I have setup EF4.2 (Database First) with my MVC3 site. I have to entities fixture and fixture period. Fixture periods have start and end dates.
I need to allow customer to add/edit fixture periods in a single view in my MVC3 site.
I have this working. I also managed to validate that fixture period start/end dates are in the right order. I did that in a partial class of the fixture period implemetimng IValidateObject. However now I need to validate that the fixture periods themselves don’t overlap with each other.
How should I ensure periods don’t overlap? Where should I check for this? I was going to do it at the ViewModel level (which seemed easy) however it seems a domain level concern. Should it be in the entity, repository, a service layer?
Any advice?
Thanks
Answer was to create an after trigger in the database for insert and update. If the rows overlapped then I raised an error and rolled back insert. I then caught the SQL Exception on SaveChanges on Object Context and handled by adding an error to ModelState.