protected override bool CommonValidation(System.Web.Http.ModelBinding.ModelStateDictionary validationDictionary, Client currentClient, Booking entity, object param, params object[] additionalObjects) { double elapsed; // If DateDeparture - DateArrive < 1 or if the booking time is more than 365 days if (entity.DateArrival != null && entity.DateDeparture != null && ((elapsed = DateUtils.GetElapsedDaysFromDateTimes(entity.DateArrival, entity.DateDeparture)) < 1 || elapsed > MAX_NIGHTS)) { validationDictionary.AddModelError("Dates", GenericError.WRONG_DATA); } if (entity.DateArrival != null && entity.DateDeparture != null && !PeriodUtils.AllCovered(PeriodRepository.GetPeriodByDates((DateTime)entity.DateArrival, (DateTime)entity.DateDeparture, currentClient.Id).ToList(), (DateTime)entity.DateArrival, (DateTime)entity.DateDeparture)) { validationDictionary.AddModelError("Period", GenericError.DOES_NOT_MEET_REQUIREMENTS); } return(validationDictionary.IsValid); }
public void AllCoveredShouldReturnTrue() { List <Period> periods = new List <Period>() { new Period() { Begin = new DateTime(2015, 3, 5, 0, 0, 0), End = new DateTime(2015, 3, 9, 23, 59, 59), Days = 1 | 8 | 16 | 32 | 64, IsClosed = false }, new Period() { Begin = new DateTime(2015, 3, 10, 0, 0, 0), End = new DateTime(2015, 3, 13, 23, 59, 59), Days = 2 | 8 | 16, IsClosed = false }, new Period() { Begin = new DateTime(2015, 3, 10, 0, 0, 0), End = new DateTime(2015, 3, 13, 23, 59, 59), Days = 4, IsClosed = false }, new Period() { Begin = new DateTime(2015, 3, 14, 0, 0, 0), End = new DateTime(2015, 3, 15, 23, 59, 59), Days = 32 | 64, IsClosed = false }, new Period() { Begin = new DateTime(2015, 3, 16, 0, 0, 0), End = new DateTime(2015, 3, 29, 23, 59, 59), Days = 1 | 2 | 4 | 8 | 16 | 32 | 64, IsClosed = false }, }; Assert.IsTrue(PeriodUtils.AllCovered(periods, new DateTime(2015, 3, 9, 14, 0, 0), new DateTime(2015, 3, 29, 10, 0, 0))); }