private void setDateEnd(CaseDeadline deadline, DeadlineType deadlineType, bool isSpecial = false) { int?months = isSpecial ? deadlineType.DeadlineSpecialMonths : deadlineType.DeadlineMonths; if (months != null) { int month = months ?? 0; deadline.EndDate = deadline.StartDate.AddMonths(month).Date; while (!workingDaysService.IsWorkingDay(userContext.CourtId, deadline.EndDate)) { deadline.EndDate = deadline.EndDate.AddDays(1).Date; } } int?workingDays = isSpecial ? deadlineType.DeadlineSpecialWorkingDays : deadlineType.DeadlineWorkingDays; if (workingDays != null) { deadline.EndDate = deadline.StartDate.Date; int wDays = (workingDays ?? 0) - 1; while (wDays > 0) { deadline.EndDate = deadline.EndDate.AddDays(1); if (workingDaysService.IsWorkingDay(userContext.CourtId, deadline.EndDate)) { wDays--; } } } int?normalDays = isSpecial ? deadlineType.DeadlineSpecialDays : deadlineType.DeadlineDays; if (normalDays != null) { int days = normalDays ?? 0; deadline.EndDate = deadline.StartDate.AddDays(days - 1).Date; while (!workingDaysService.IsWorkingDay(userContext.CourtId, deadline.EndDate)) { deadline.EndDate = deadline.EndDate.AddDays(1).Date; } } }
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), $"Няма посещение в почивен ден"); } } }
public JsonResult CheckDeliveryDate(DeliveryItemOperVM model) { ValidateModel(model); var result = "OK"; if (ModelState.IsValid) { 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) { result = $"Няма 7 дни от предното посещение {prevOper.DateOper.ToString(FormattingConstant.NormalDateFormat)}. "; } } if (opers.Count >= 2 && model.DeliveryOperId != NomenclatureConstants.NotificationState.Delivered) { 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) { result += $"Няма посещение в почивен ден"; } } } else { result = "NOT_VALID"; } return(Json(result)); }