Sunday, September 5, 2010

Formal Dress Shops Co.armagh

Validating domain objects and not only ...

Hi little now I do not regularly written due to lack of time but has already commenced in September so time to work. Today I would like discuss the problem of validation domain objects but not only. This interface can be used in any object. I would like to achieve the objectives of which are two: First of all, the validation must be reusable and easily accessible. The second objective is the ability to validate the entire object at once and return to the controller information about all the wrong boxes.


interface IValidatable

Let's start from the beginning because the validation must be easily accessible and reusable, any object that will have validation must implement the above interface. Nothing special: Public interface
IValidatable


ValidationResult
This class consists of a dictionary that stores information about the error and check that the information relates. However, because the data field can have a lot of mistakes because stores a list of strings. In addition, one has two functions for counting errors and another error to add to the dictionary. Class itself looks like this: public class
 ValidationResult 

{private IDictionary \u0026lt;string, IList \u0026lt;string>> _validationErrors;

public ValidationResult()
{
_validationErrors = new Dictionary<string, IList<string>>(); }
public IDictionary<string, IList<string>> Errors
{
         get { return _validationErrors; } 
private set { _validationErrors = value; }
}

public int CountErrors()
{
int errorCount = 0;

foreach (var errorMessages in _validationErrors.Values)
{
errorCount += errorMessages.Count;
}

return errorCount;
}

public void AddError(KeyValuePair<string, string> error)
{
if (error.Key != null)
{
if (_validationErrors.ContainsKey(error.Key))
{
_validationErrors[error.Key].Add(error.Value);
}
else
{
IList<string> newErrorList = new List<string>();
newErrorList.Add(error.Value);

_validationErrors.Add(new KeyValuePair<string, IList \u0026lt;string>> (error.Key, newErrorList));}


}}}




ValidationHelper

To facilitate the addition of a little bug I decided to create a secondary class that will be somewhat automate adding errors. This will be an object which has two methods that give an error if the condition is not fulfilled. They differ only in one parameter associated with a key error. This is usually called just as the field concerned. And in the end, a version of the method of expression lambda. The other takes a string parameter. So it is more generalized. Class looks like this: public class

ValidationHelper \u0026lt;T>
{public
ValidationHelper ()

{} public KeyValuePair
\u0026lt;string, string> CreateErrorIf (bool condition, String errorKey, String errorMessageKey)
{if (condition) return new KeyValuePair
\u0026lt;string, string> (errorKey, ResourceHelper.GetErrorMessage (errorMessageKey));
 
else return new KeyValuePair \u0026lt;string, string> ( );
}

public KeyValuePair \u0026lt;string, string> CreateErrorIf \u0026lt;TResult> (bool condition, Expression \u0026lt;Func \u0026lt;T, TResult>> errorKey, string errorMessageKey)
{var
expressionMember = errorKey.Body as MemberExpression;

CreateErrorIf return (condition, expressionMember.Member.Name, errorMessageKey);

}}

method that uses lambda expressions simply take from him the name of the field. And now an example using these classes: public class

User: BaseEntity, IEntity, IValidatable
{
...

public virtual ValidationResult Validate()
{
ValidationResult validationResult = new ValidationResult();
ValidationHelper<User> validationHelper = new ValidationHelper<User>();
validationResult.AddError(validationHelper.CreateErrorIf(!String.IsNullOrEmpty(Username), f => f.Username, ResourceKey.Common.RequiredField));
validationResult.AddError(validationHelper.CreateErrorIf(Username.Length >= 256, f => f.Username, ResourceKey.Common.FieldLength));
  
...

validationResult return;}

}


addition to writing this mechanism, slowly add missing tests in the project already associated with a ready functionality. That's all for today:)


Tuesday, August 31, 2010

All Male Spa Nj Star Spa

As the storm.

As the storm going. Last dose of news at the end of vacation. Now I probably will not be enough time .. : /
The first one announced with our small child in LO. :)
Ideally, of course, gave the studs with scrap.com.pl ;)






Roses made based on the rate of scrappassion Sassili.


And this is my favorite;)

Today I finished the piece dress.






Again, rubella:)


Haha, yesterday out of boredom oskrapowaƂam even my cork board: DD


And tomorrow ..


pile of books and notebooks and now is, krowiasty pencil case too: D
A Polish my book subtitled 'scrapmania' oO

I hit my:



And so I conclude. But I hope that soon I will write here.
: *


Sunday, August 29, 2010

Wording For Retirement Cakes

QueenEfekt went

Although the remaining two hours yet to officially launch ... but I can confidently say that the community information service for fans of the band Queen is already running.

Almost all of the information in one place, news and articles on an ongoing basis and the community, friends ...

From the biography, by concerts, to the gadgets. Accurate descriptions, photos, videos, texts, translations, albums, songs, awards, tour, discography and even a dictionary. Support for search and calendar.

All you can comment, rate and edit.

The mini-blog community, friends, news, galleries and information.

whole summarizes innovative online radio - Radio Gaga - Queen where the game without interruption.

Anything else?
much, much more ... lots of information, contact with fans and friends, great fun.

Join http://QueenEfekt.pl

Tuesday, August 24, 2010

Spanish Wording For Receptions

Nhibernate - the relationship one to many and a few cosmetic changes

Hi after quite a long break due to the holidays:) Today I decided a little bit to describe a very simplified model of the logic associated closely with the forum or entities, such as Category Forum, Forum, Topic, Post. In addition, describe a few cosmetic.


logic associated with the forum

Forum will consist of categories. They divide the whole forum partly related to each other thematically. Each categories can have multiple forums. The forums have included topics and have many posts. Currently, models are very simple. With the development of the project and increasing functionality will grow
Forum Categories Class: public class
ForumCategory: BaseEntity
public virtual IEnumerable {get \u0026lt;Forum> Forums ; set;}}
Class Forum:

public class Forum: BaseEntity
 {public virtual string Name {get; set;  } 

public virtual string Description { get; set; }

public virtual ForumCategory Category { get; set; }

public virtual IEnumerable<Topic> Topics { get; set; }
}
 Klasa Temat: 

public class Topic : BaseEntity
{
public virtual string Name { get; set; }

public virtual Forum Forum { get; set; }

public virtual IEnumerable<Post> Posts { get; set; }
}
Klasa Post:
 public class Post : BaseEntity 
{
public virtual string Name { get; set; }
Public virtual
Topic Topic {get; set;}}



Nhibernate - one to many relationships

As seen above in our simple model of entity pair relations: one to many. The Fluent Nhibernate maps these relationships by the method of References and hasMany. Re is the same as the method that the entity that is Hason has an object in a relationship. However hasMany means that the entity has a number of objects from a given relation. The combination of these two methods gives rise to many a relationship. Now a simple example, mapping one to many relationship: ForumCategory -> Forum
 
public class ForumCategoryMap: ClassMap \u0026lt;ForumCategory>
{
Public ForumCategoryMap () {

Id (p => p.Id). GeneratedBy.Guid ();
Map (p => p.Name). Not.Nullable (.) Length (256 ); hasMany (p => p.Forums);

}}
 
And here we have the other end of our relationship that is a class forum: public class

ForumMap: ClassMap \u0026lt;Forum>
{
public ForumMap () {

Id (p => p.Id). GeneratedBy.Guid ();

Map (p => p.Name). Not.Nullable (). Length ( 256);
Map (p => p.Description). Not.Nullable (.) Length (256);
References (p => p.Category);
hasMany (p => p.Topics);
}} 


As can be seen in a very simple manner by means of Fluent Nhibernate we can create one to many relationships.

In addition to these changes I introduced the basic layout of the forum. Removed commandy. Their roles now Przejma DataTransferObjecty. PodmieniƂem client-side validation of the standard Microsoft on jQuery. This required a download MVC Futures and substitution in views instead MicrosoftMvcValidation.js MicrosoftMvcJQueryValidation.js file.