I am at the center of refactoring the project I am working on. In my existing controllers, I use the repository template, but I still ran too many scaffolding than I was comfortable with. This and some of my controllers could have 10+ repositories transferred (via Ninject). So, I decided to introduce a service level, where my intention is to have one service per controller, and each service will instead have several repositories entered into it and do the work I need. This has worked fine so far, but I'm confused: how do I transfer model validation from the controller to the service level?
For example, look at this method Editon mine OfficesController:
[HttpPost]
public async Task<RedirectToRouteResult> Edit(
short id,
FormCollection form,
[Bind(Prefix = "Office.Coordinates", Include = "Latitude,Longitude")] Coordinate[] coordinates) {
if (id > 0) {
Office office = await this.OfficesService.GetOfficeAsync(id);
if ((office != null)
&& base.TryUpdateModel(office, "Office", new string[2] {
"Name",
"RegionId"
}, form)
&& base.ModelState.IsValid) {
this.OfficesService.UpdateOfficeAsync(office, coordinates);
}
return base.RedirectToAction("Edit", new {
id = id
});
}
return base.RedirectToAction("Default");
}
, - Office , , . , . , , . Edit, , , , .
, , , , ? !
, , :
- . .
- Data.Google.Maps: , Kml
- Data.Models: DbContext, , .
- Data.Repositories. , DbContext. EF , "" . :
FindTechnicians() FindActive() .. - Data.Services. , . , , , , .
- . Identity ASP.NET.
- Web.Private: MVC.