Is it a good practice to add methods to the POCOs or to create separate class to update the values of the POCOs in case we need that?
For example,
public class ForUser
{
[Required]
public int Depratment { get; set; }
public List<SelectListItem> DepartmentsList { get; set; }
[Required]
public int Role { get; set; }
[Required]
[StringLength(200, MinimumLength = 3, ErrorMessage = "Length Of The First Name Should Be More Than Three Letters")]
public string FirstName { get; set; }
[StringLength(200, MinimumLength = 3, ErrorMessage = "Length Of The Mid Name Should Be More Than Three Letters")]
public string MidName { get; set; }
[Required]
[StringLength(200, MinimumLength = 3, ErrorMessage = "Length Of The Last Name Should Be More Than Three Letters")]
public string LastName { get; set; }
[Required]
[EmailAddress(ErrorMessage = "Invalid Email Address")]
public string Email { get; set; }
[StringLength(14, MinimumLength = 10 , ErrorMessage = "Length Of The Mid Name Should Be More Than Nine Letters and Less than fourteen Letters")]
[RegularExpression(@"^[+]?[0-9]*", ErrorMessage="Phone Number is not correct")]
public string PhoneNumber { get; set; }
[Required]
public string Password { get; set; }
public int UserId { get; set; }
public int Company { get; set; }
public int Country { get; set; }
public List<SelectListItem> Roles { get; set; }
}
I use it just to hold the data to update the model entity
or to return data to the view. Sometimes I need to update some properties before I send the object
to the view, like the list called Roles
in the above example, so I am wondering about if I should add the methods to the POCO
class or is it better to create a class to update the properties?