private void ValidateModel(DeliveryItemOperVM model) { var regDate = service.GetRegDate(model.DeliveryItemId); if (model.DateOper < regDate?.Date) { ModelState.AddModelError(nameof(model.DateOper), $"{MessageConstant.ValidationErrors.DeliveryDateBeforeRegDate} {regDate?.ToString(FormattingConstant.NormalDateFormat)}"); } if (model.DateOper > DateTime.Now.AddMinutes(10)) { ModelState.AddModelError(nameof(model.DateOper), MessageConstant.ValidationErrors.DeliveryDateBeforeRegDate); } var opers = service.DeliveryItemOperSelect(model.DeliveryItemId, true) .Where(x => x.DeliveryOperId < model.DeliveryOperId) .OrderBy(x => x.DeliveryOperId) .ToList(); var prevOper = opers.LastOrDefault(); if (prevOper != null && model.DateOper != null) { if (model.DateOper?.Date < prevOper.DateOper.Date) { ModelState.AddModelError(nameof(model.DateOper), $"Не може да въвеждате посещение преди предното посещение {prevOper.DateOper.ToString(FormattingConstant.NormalDateFormat)}"); } } }
private void ValidateModel(DeliveryItemOperVM model) { var regDate = service.GetRegDate(model.DeliveryItemId); if (model.DateOper < regDate) { ModelState.AddModelError(nameof(model.DateOper), $"Посещение преди дата на изготвяне {regDate?.ToString(FormattingConstant.NormalDateFormat)}"); } if (model.DateOper > DateTime.Now) { ModelState.AddModelError(nameof(model.DateOper), $"Не може да въвеждате посещение с бъдеща дата"); } var opers = service.DeliveryItemOperSelect(model.DeliveryItemId, true) .Where(x => x.DeliveryOperId < model.DeliveryOperId) .OrderBy(x => x.DeliveryOperId) .ToList(); var prevOper = opers.LastOrDefault(); if (prevOper != null) { var dR = model.DateOper - prevOper.DateOper; if (dR.Value.TotalDays < 7) { ModelState.AddModelError(nameof(model.DateOper), $"Няма 7 дни от преднато посещение {prevOper.DateOper.ToString(FormattingConstant.NormalDateFormat)}"); } } if (opers.Count >= 2) { bool haveHoliday = !workingDaysService.IsWorkingDay(userContext.CourtId, model.DateOper?.Date ?? DateTime.Now); haveHoliday = haveHoliday || opers.Max(x => !workingDaysService.IsWorkingDay(userContext.CourtId, (DateTime)(x.DateOper).Date)); if (!haveHoliday) { ModelState.AddModelError(nameof(model.DateOper), $"Няма посещение в почивен ден"); } } }