I know the header is a bit hard to figure out, but I didn't exactly know how to describe the problem, but here it comes.
I have this domain entity: User and it has a list of the subclass Address, since the user can have multiple address. Home, Work etc etc...
private class User{
private string _FirstName;
private string _LastName;
private IList<Address> _addresses;
public string FirstName{...}
public string LastName{...}
public IList<Addresses> Addresses {...}
}
private class Address{
private string _streetAddress1;
private string _streetAddress2;
...
public string StreetAddress1{...};
public string StreetAddress2{...};
...
}
I have a Validation of the inputdata that looks like this.
[AcceptVerbs(HttpVerbs.Post)]
[ValidateModelAttribute(typeof(FormUser))]
public ActionResult CreateEdit([Bind(Prefix = "")] FormUser formUser)
{
//-- Check so the input
if (!ModelState.IsValid)
return View();
User modelUser = new UserMapper().MapToModel(formUser);
_UserRepository.Save(modelUser);
return RedirectToAction<SharedController>(m => m.Success());
}
The FormUser is my PresentationEntity that looks like this.
public class FormUser
{
[NonEmptyValidator("Field is required!")]
public string FirstName{get;set;}
[NonEmptyValidator("Field is required!")]
public string LastName{get;set;}
public List<Address> Addresses{get;set;}
}
For the FirstName and LastName filed this is no problem it's very simple and works greate. But now I have added the Addresses property to my User entity and want to make this input in a smart way with easy validation of the input field in the Address entity.
So say I have the FirstName and LastName textboxes in my webpage, and now I want to add an Address for this User. I can see a way to do this
It is to open an new webpage that has it's own controller that makes the same validation that I do for the User. So I have a FormAddress class and CreateEdit()- method in my AddressController. The problem I see here is how do I add this address-data to the user when I am finished validating the data?
Or is there a better way to do this. It's really easy in a stateful applicaiton, but here I can't see a good clean way to do it.