示例#1
0
        protected bool ValidateDismissalEditModel(DismissalEditModel model, UploadFileDto fileDto)
        {
            //if (model.BeginDate.HasValue && model.EndDate.HasValue &&
             //    model.BeginDate > model.EndDate)
             //    ModelState.AddModelError("BeginDate", "Дата начала не может превышать дату окончания.");
             UserRole role = AuthenticationService.CurrentUser.UserRole;
             if (model.Id > 0 && fileDto == null)
             {
                 int attachmentCount = RequestBl.GetAttachmentsCount(model.Id, RequestAttachmentTypeEnum.Dismissal);
                 if (attachmentCount <= 0)
                 {
                     if ((role == UserRole.Employee && model.IsApprovedByUser) ||
                         (role == UserRole.Manager && model.IsApprovedByManager) ||
                         (role == UserRole.PersonnelManager && model.IsApprovedByPersonnelManager))
                     {

                         ModelState.AddModelError(string.Empty,
                                                  "Заявка не может быть согласована без прикрепленого заявления.");
                         if (role == UserRole.Employee && model.IsApprovedByUser)
                         {
                             ModelState.Remove("IsApprovedByUser");
                             model.IsApprovedByUser = false;
                         }
                         if (role == UserRole.Manager && model.IsApprovedByManager)
                         {
                             ModelState.Remove("IsApprovedByManager");
                             model.IsApprovedByManager = false;
                         }
                         if (role == UserRole.PersonnelManager && model.IsApprovedByPersonnelManager)
                         {
                             ModelState.Remove("IsApprovedByPersonnelManager");
                             model.IsApprovedByPersonnelManager = false;
                         }
                         //error = "Заявка не может быть согласована без прикрепленого скана больничного.";
                         //needToReload = true;
                         //return false;

                     }
                 }
             }
             if (role == UserRole.PersonnelManager && string.IsNullOrEmpty(model.Reason))
                 ModelState.AddModelError("Reason", "Основание документ - обязательное поле.");
             if(!string.IsNullOrEmpty(model.Compensation))
             {
                 decimal compensation;
                 if(!Decimal.TryParse(model.Compensation,out compensation) ||
                     compensation < 0)
                     ModelState.AddModelError("Compensation", "Кол-во дней компенсации должно быть неотрицательным десятичным числом.");
             }
             if (!string.IsNullOrEmpty(model.Reduction))
             {
                 decimal reduction;
                 if (!Decimal.TryParse(model.Reduction, out reduction) ||
                     reduction < 0)
                     ModelState.AddModelError("Reduction", "Кол-во дней удержания должно быть неотрицательным десятичным числом.");
             }
             if (role == UserRole.PersonnelManager && string.IsNullOrEmpty(model.Compensation) && string.IsNullOrEmpty(model.Reduction))
                 ModelState.AddModelError("Compensation", "Укажите \"Кол-во дней компенсации\" и/или \"Кол-во дней удержания\"");

             CheckEndDate(model);
             return ModelState.IsValid;
        }
示例#2
0
 public ActionResult DismissalEdit(DismissalEditModel model)
 {
     CorrectCheckboxes(model);
      CorrectDropdowns(model);
      UploadFileDto fileDto = GetFileContext();
      UploadFileDto orderScanFileDto = GetFileContext("orderScanFile");
      UploadFileDto unsignedOrderScanFileDto = GetFileContext("unsignedOrderScanFile");
      UploadFileDto t2ScanFileDto = GetFileContext("t2ScanFile");
      UploadFileDto dismissalAgreementScanFileDto = GetFileContext("dismissalAgreementScanFile");
      UploadFileDto f182NScanFileDto = GetFileContext("f182NScanFile");
      UploadFileDto f2NDFLScanFileDto = GetFileContext("f2NDFLScanFile");
      UploadFileDto unsignedT2ScanFileDto = GetFileContext("unsignedT2ScanFile");
      UploadFileDto unsignedDismissalAgreementScanFileDto = GetFileContext("unsignedDismissalAgreementScanFile");
      UploadFileDto workbookRequestScanFileDto = GetFileContext("workbookRequestScanFile");
      UploadFileDto cancelNoteFileDto = GetFileContext("CancelNoteScanFile");
      if (!ValidateDismissalEditModel(model,fileDto))
      {
          model.IsApproved = false;
          model.IsApprovedForAll = false;
          RequestBl.ReloadDictionariesToModel(model);
          return View(model);
      }
      string error;
      if (!RequestBl.SaveDismissalEditModel(model, new Dictionary<RequestAttachmentTypeEnum, UploadFileDto> {
             { RequestAttachmentTypeEnum.Dismissal, fileDto},
             { RequestAttachmentTypeEnum.UnsignedDismissalOrderScan, unsignedOrderScanFileDto},
             { RequestAttachmentTypeEnum.DismissalOrderScan, orderScanFileDto},
             { RequestAttachmentTypeEnum.T2Scan, t2ScanFileDto },
             { RequestAttachmentTypeEnum.DismissalAgreementScan, dismissalAgreementScanFileDto },
             { RequestAttachmentTypeEnum.F182NScan, f182NScanFileDto },
             { RequestAttachmentTypeEnum.F2NDFLScan, f2NDFLScanFileDto },
             { RequestAttachmentTypeEnum.UnsignedT2Scan, unsignedT2ScanFileDto },
             { RequestAttachmentTypeEnum.UnsignedDismissalAgreementScan, unsignedDismissalAgreementScanFileDto },
             { RequestAttachmentTypeEnum.WorkbookRequestScan, workbookRequestScanFileDto},
             { RequestAttachmentTypeEnum.CancelNote, cancelNoteFileDto}
         }, out error))
      {
          //HttpContext.AddError(new Exception(error));
          if (model.ReloadPage)
          {
              ModelState.Clear();
              if (!string.IsNullOrEmpty(error))
                  ModelState.AddModelError("", error);
              return View(RequestBl.GetDismissalEditModel(model.Id, model.UserId));
          }
          if (!string.IsNullOrEmpty(error))
              ModelState.AddModelError("", error);
      }
      return View(model);
 }
示例#3
0
 protected void CorrectDropdowns(DismissalEditModel model)
 {
     if (!model.IsPersonnelFieldsEditable)
          model.TypeId = model.TypeIdHidden;
      /*if (!model.IsPersonnelFieldsEditable)
          model.StatusId = model.StatusIdHidden;*/
      //model.DaysCount = model.DaysCountHidden;
 }