Beispiel #1
0
 protected override bool ValidatePost(System.Web.Http.ModelBinding.ModelStateDictionary validationDictionary, Client currentClient, Period entity, object param, params object[] additionalObjects)
 {
     if (param != null && entity != null && entity.End != null && entity.Begin != null && entity.Days > 0)
     {
         List <Period> periodList = PeriodRepository.GetPeriodByDates(entity.Begin, entity.End, currentClient.Id).ToList();
         if (PeriodUtils.IsDaysCross(periodList, entity))
         {
             validationDictionary.AddModelError(TypeOfName.GetNameFromType <Period>(), GenericError.ALREADY_EXISTS);
         }
     }
     return(CommonValidation(validationDictionary, currentClient, entity, param, additionalObjects));
 }
Beispiel #2
0
        public void IsDayCrossTestReturnTrue()
        {
            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,
                    IsClosed = false
                },
                new Period()
                {
                    Begin    = new DateTime(2015, 3, 10, 0, 0, 0),
                    End      = new DateTime(2015, 3, 13, 23, 59, 59),
                    Days     = 2 | 64 | 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 | 32,
                    IsClosed = false
                },
                new Period()
                {
                    Begin    = new DateTime(2015, 3, 16, 0, 0, 0),
                    End      = new DateTime(2015, 3, 29, 23, 59, 59),
                    Days     = 8,
                    IsClosed = false
                },
            };

            Assert.IsTrue(PeriodUtils.IsDaysCross(periods, new Period()
            {
                Begin    = new DateTime(2015, 3, 5, 0, 0, 0),
                End      = new DateTime(2015, 3, 29, 23, 59, 59),
                Days     = 16,
                IsClosed = false
            }));
        }