I have a timesheet system written in ASP.NET MVC in C# with Entity Framework 6 and I want to prevent users from submitting overlapping / clashing timesheets for the same job.
The SQL Server timesheet
table has a number of columns, these are the most relevant:
╔═══════════════╦══════════╗
║ Column Name ║ DataType ║
╠═══════════════╬══════════╣
║ UserId ║ int ║
║ JobId ║ int ║
║ StartDateTime ║ datetime ║
║ EndDateTime ║ datetime ║
╚═══════════════╩══════════╝
and here's a sample of data:
╔══════╦════════╦═══════╦══════════════════╦══════════════════╗
║ Id ║ UserId ║ JobId ║ StartDateTime ║ EndDateTime ║
╠══════╬════════╬═══════╬══════════════════╬══════════════════╣
║ 4893 ║ 245 ║ 119 ║ 26/08/2014 17:00 ║ 27/08/2014 08:00 ║
╚══════╩════════╩═══════╩══════════════════╩══════════════════╝
What would be the most efficient way to prevent a clash of date/time if someone tries to submit an overlapping timesheet for the same JobId
?
Thanks for any pointers on this, as I want to keep the system pretty fast - which it currently is but the timesheet table will eventually have many rows to traverse through.