protected bool ValidateMissionEditModel(MissionEditModel model) { if (model.BeginDate.HasValue && model.EndDate.HasValue && model.BeginDate > model.EndDate) ModelState.AddModelError("BeginDate", "Дата начала не может превышать дату окончания."); UserRole role = AuthenticationService.CurrentUser.UserRole; if(role == UserRole.PersonnelManager && string.IsNullOrEmpty(model.Reason)) ModelState.AddModelError("Reason", "Основание командировки - обязательное поле."); CheckBeginDate(model); return ModelState.IsValid; }
public ActionResult MissionEdit(MissionEditModel model) { CorrectCheckboxes(model); CorrectDropdowns(model); UploadFileDto orderScanFileDto = GetFileContext("orderScanFile"); if (!ValidateMissionEditModel(model)) { model.IsApproved = false; model.IsApprovedForAll = false; RequestBl.ReloadDictionariesToModel(model); return View(model); } string error; if (!RequestBl.SaveMissionEditModel(model, orderScanFileDto, out error)) { //HttpContext.AddError(new Exception(error)); if (model.ReloadPage) { ModelState.Clear(); if (!string.IsNullOrEmpty(error)) ModelState.AddModelError("", error); return View(RequestBl.GetMissionEditModel(model.Id, model.UserId)); } if (!string.IsNullOrEmpty(error)) ModelState.AddModelError("", error); } return View(model); }
protected void CorrectDropdowns(MissionEditModel model) { if (!model.IsTypeEditable) model.TypeId = model.TypeIdHidden; if (!model.IsTimesheetStatusEditable) model.TimesheetStatusId = model.TimesheetStatusIdHidden; model.DaysCount = model.DaysCountHidden; }