Esempio n. 1
0
        public ActionResult DeductionEdit(DeductionEditModel model)
        {
            CorrectCheckboxes(model);
            CorrectDropdowns(model);
            //UploadFileDto fileDto = GetFileContext();
            if (!ValidateDeductionEditModel(model))
            {
                //model.IsApproved = false;
                //model.IsApprovedForAll = false;
                RequestBl.ReloadDictionariesToModel(model);
                return View(model);
            }

            string error;
            //чтобы письма рассылались только когда идет работа с рабочей базой
            bool EnableSendEmail = Request.Url.Port == 8002 || Request.Url.Port == 500 ? true : false;
            if (!RequestBl.SaveDeductionEditModel(model, EnableSendEmail, out error))
            {

                if (model.ReloadPage)
                {
                    ModelState.Clear();
                    if (!string.IsNullOrEmpty(error))
                        ModelState.AddModelError("", error);
                    return View(RequestBl.GetDeductionEditModel(model.Id));
                }
                if (!string.IsNullOrEmpty(error))
                    ModelState.AddModelError("", error);
            }
            return View(model);
        }
Esempio n. 2
0
 protected void CorrectDropdowns(DeductionEditModel model)
 {
     if (!model.IsEditable)
     {
         //model.TypeId = model.TypeIdHidden;
         //model.KindId = model.KindIdHidden;
         //model.MonthId = model.MonthIdHidden;
         model.UserId = model.UserIdHidden;
     }
 }
Esempio n. 3
0
        protected bool ValidateDeductionEditModel(DeductionEditModel model)
        {
            if (model.Id == 0)
            {
                if (model.UserId != 0)
                {
                    User DeductionUser = RequestBl.GetUser(model.UserId);
                    if ((DeductionUser.UserRole & UserRole.DismissedEmployee) > 0 && DeductionUser.DateRelease <= DateTime.Today.AddMonths(-3))
                    {
                        ModelState.AddModelError("Surname", "Нельзя создать заявку на удержание, так как выбранный сотрудник уволен более 3 месяцев назад!");
                    }
                }
                else
                {
                    ModelState.AddModelError("Surname", "Укажите сотрудника!");
                }
            }
            if(string.IsNullOrEmpty(model.Sum))
                ModelState.AddModelError("Sum", "'Сумма' - обязательное поле.");
            else
            {
                decimal sum;
                if(!Decimal.TryParse(model.Sum,out sum))
                    ModelState.AddModelError("Sum", "Поле 'Сумма' должно быть числом.");
                else if (sum <= 0)
                    ModelState.AddModelError("Sum", "Поле 'Сумма' должно быть положительным числом.");
            }
            if (Convert.ToDateTime(model.DateEdited).Month == DateTime.Today.Month && Convert.ToDateTime(model.DateEdited).Year == DateTime.Today.Year)
            {
                if (model.TypeId != (int)DeductionTypeEnum.Deduction)
                {
                    if (!model.DismissalDate.HasValue)
                        ModelState.AddModelError("DismissalDate", "'Дата увольнения' - обязательное поле.");
                }
            }
            else
            {
                ModelState.AddModelError("DismissalDate", "Отклонение заявки в прошлом периоде запрещено!");
            }

            return ModelState.IsValid;
        }
Esempio n. 4
0
 protected void CorrectCheckboxes(DeductionEditModel model)
 {
     if (!model.IsEditable && model.IsFastDismissalHidden)
     {
         if (ModelState.ContainsKey("IsFastDismissal"))
             ModelState.Remove("IsFastDismissal");
         model.IsFastDismissal = model.IsFastDismissalHidden;
     }
 }