public ActionResult Index(MissionOrderListModel model) { ModelState.Clear(); bool hasError = !ValidateModel(model); if(!hasError) SetMissionOrderFilterToSession(model); RequestBl.SetMissionOrderListModel(model, hasError); if(model.HasErrors) ModelState.AddModelError(string.Empty, "При согласовании приказов произошла(и) ошибка(и).Не все приказы были согласованы."); return View(model); }
protected void SetMissionOrderListModelFromSession(MissionOrderListModel model) { MissionOrderFilterModel filterModel = (MissionOrderFilterModel)System.Web.HttpContext.Current.Session[SessionMissionOrderFilterName]; if(filterModel != null) { model.StatusId = filterModel.StatusId; model.BeginDate = filterModel.BeginDate; model.EndDate = filterModel.EndDate; model.UserName = filterModel.UserName; model.Number = filterModel.Number; if(AuthenticationService.CurrentUser.UserRole != UserRole.Employee && filterModel.DepartmentId != 0) { Department dep = DepartmentDao.Load(filterModel.DepartmentId); if (dep != null) { model.DepartmentId = filterModel.DepartmentId; model.DepartmentName = dep.Name; } } } }
protected bool ValidateModel(MissionOrderListModel model) { if (model.BeginDate.HasValue && model.EndDate.HasValue && model.BeginDate.Value > model.EndDate.Value) ModelState.AddModelError("BeginDate", "Дата в поле <Период с> не может быть больше даты в поле <по>."); if (model.IsApproveClick && (model.Documents == null || model.Documents.Count == 0 || model.Documents.Where(x => x.IsChecked).Count() == 0 )) ModelState.AddModelError(string.Empty, "Не выбрано ни одного приказа для согласования."); return ModelState.IsValid; }
protected void SetMissionOrderFilterToSession(MissionOrderListModel model) { MissionOrderFilterModel filterModel = new MissionOrderFilterModel { BeginDate = model.BeginDate, DepartmentId = model.DepartmentId, EndDate = model.EndDate, StatusId = model.StatusId, UserName = model.UserName, Number = model.Number, }; System.Web.HttpContext.Current.Session[SessionMissionOrderFilterName] = filterModel; }