I have been using the following pattern for my controller actions:
public ActionResult Create(CreateViewModel model) { if( !ModelState.IsValid ) { return View(model); } var project = new Project { Name = model.Name, // ... }; projectRepository.Add(project); return RedirectToAction("Index"); } This works for simple scenarios, but I have had a few situations where a repository is not enough. I created a service layer / class that will handle saving the project and any extra business logic (not normal validations with fluent validation or data annotations).
public class ProjectService : IProjectService { void AddProject(Project project) { // do business logic // ... repository.Add(project); } } How can my service layer easily communicate with my controller?
These are the types of things I would like to communicate to the controller:
- Business Logic / Validation errors
- Database Failures (failed to save etc.)
How can I do this without just returning true/false or status codes from the service layer?