Currently i have a customer class that the user can partially create, and finish the detailed information down the line. For example it looks like this
New Customer
[Required(ErrorMessage = "Business name is required.")]
[Display(Name = "Business Name:")]
public string BusinessName { get; set; }
[Display(Name = "Address:")]
public string Address { get; set; }
[Display(Name = "City:")]
public string City { get; set; }
[Display(Name = "State:")]
public string State { get; set; }
[Display(Name = "Zip:")]
public string Zip { get; set; }
Customer Checkout
[Required(ErrorMessage = "Business name is required.")]
[Display(Name = "Business Name:")]
public string BusinessName { get; set; }
[Required(ErrorMessage = "Address is required.")]
[Display(Name = "Address:")]
public string Address { get; set; }
[Required(ErrorMessage = "City is required.")]
[Display(Name = "City:")]
public string City { get; set; }
[Required(ErrorMessage = "State is required.")]
[Display(Name = "State:")]
public string State { get; set; }
[Required(ErrorMessage = "Zip is required.")]
[Display(Name = "Zip:")]
public string Zip { get; set; }
when the user goes to checkout i need to make sure that they do finish filling out the information if some is missing.
My thought process was to create a Customer Checkout class populated with the information from when they created a new customer and check to see if its valid before passing them along to checkout. My issue is the only way i know to do that is to check each field against string.isNullOrEmpty() but i know there has to be a better way. I will have to check 25 fields like this. I know that you can check if a Model is valid, but i need to do this at a class level in my Data Access Layer checking to make sure all[required] fields have data. Hopefully i am just overlooking something
almost like I need some way to do something like
bool hasErrors = false
foreach attribute in my class
if it is marked as [required]
check to make sure not null or empty
if it is set hasErrors = true
thanks!
If performance is not a consideration you can use reflection to automatically validate your object.