コード例 #1
0
ファイル: HelpController.cs プロジェクト: andreyu/Reports
 protected void CorrectDropdowns(EditPersonnelBillingRequestViewModel model)
 {
     if (!model.IsEditable)
     {
         model.TitleId = model.TitleIdHidden;
         //model.RecipientId = model.RecipientIdHidden;
         model.UrgencyId = model.UrgencyIdHidden;
     }
 }
コード例 #2
0
ファイル: HelpController.cs プロジェクト: andreyu/Reports
 protected bool ValidateModel(EditPersonnelBillingRequestViewModel model)
 {
     if (model.Operation == 1 && string.IsNullOrEmpty(model.DateSended) && ((model.RecipientList == null || model.RecipientList.Count == 0) || model.RecipientList.Where(x => x.IsRecipient == true).Count() == 0))
         ModelState.AddModelError("RecipientList", "Выберите исполнителя!");
     return ModelState.IsValid;
 }
コード例 #3
0
ファイル: HelpController.cs プロジェクト: andreyu/Reports
 public ActionResult EditPersonnelBillingRequest(EditPersonnelBillingRequestViewModel model)
 {
     CorrectCheckboxes(model);
     CorrectDropdowns(model);
     if (!ValidateModel(model))
     {
         HelpBl.ReloadDictionariesToModel(model);
         return View(model);
     }
     string error;
     if (!HelpBl.SavePersonnelBillingRequestModel(model, out error))
     {
         if (model.ReloadPage)
         {
             ModelState.Clear();
             if (!string.IsNullOrEmpty(error))
                 ModelState.AddModelError("", error);
             return View(HelpBl.GetPersonnelBillingRequestEditModel(model.Id));
         }
         if (!string.IsNullOrEmpty(error))
             ModelState.AddModelError("", error);
     }
     return View(model);
 }
コード例 #4
0
ファイル: HelpController.cs プロジェクト: andreyu/Reports
 protected void CorrectCheckboxes(EditPersonnelBillingRequestViewModel model)
 {
     if (!model.IsWorkBeginAvailable)
     {
         if (ModelState.ContainsKey("IsWorkBegin"))
             ModelState.Remove("IsWorkBegin");
         model.IsWorkBegin = model.IsWorkBeginHidden;
     }
 }
コード例 #5
0
ファイル: HelpBl.cs プロジェクト: andreyu/Reports
 protected void SetHiddenFields(EditPersonnelBillingRequestViewModel model)
 {
     model.TitleIdHidden = model.TitleId;
     model.UrgencyIdHidden = model.UrgencyId;
     model.IsWorkBeginHidden = model.IsWorkBegin;
 }
コード例 #6
0
ファイル: HelpBl.cs プロジェクト: andreyu/Reports
 public EditPersonnelBillingRequestViewModel GetPersonnelBillingRequestEditModel(int id)
 {
     IUser current = AuthenticationService.CurrentUser;
     int userId = 0;
     HelpPersonnelBillingRequest entity = null;
     if (id == 0)
     {
         if (CurrentUser.UserRole != UserRole.OutsourcingManager || CurrentUser.UserRole == UserRole.Estimator || ((CurrentUser.UserRole & UserRole.PersonnelManager) > 0 && CurrentUser.Id == 10))
             userId = current.Id;
         else
             throw new ValidationException(StrCannotCreatePersonnelBilling);
     }
     else
         entity = HelpPersonnelBillingRequestDao.Load(id);
     EditPersonnelBillingRequestViewModel model = new EditPersonnelBillingRequestViewModel
     {
         Id = id,
         UserId = id == 0 ? userId : entity.Creator.Id,
     };
     //User user = UserDao.Load(model.UserId);
     User currUser = UserDao.Load(current.Id);
     if (id == 0)
     {
         entity = new HelpPersonnelBillingRequest
         {
             Creator = currUser,
             CreateDate = DateTime.Now,
             EditDate = DateTime.Now,
             CreatorRoleId = (int)current.UserRole
         };
     }
     else
     {
         model.Answer = entity.Answer;
         model.DepartmentId = entity.Department == null ? 0 : entity.Department.Id;
         model.DepartmentName = entity.Department == null ? string.Empty : entity.Department.Name;
         model.Question = entity.Question;
         model.TitleId = entity.Title.Id;
         model.UrgencyId = entity.Urgency.Id;
         model.UserName = entity.UserName;
         model.Version = entity.Version;
         model.UserId = entity.Creator.Id;
         model.Version = entity.Version;
     }
     SetBillingRequestInfoModel(entity, model);
     model.AttachmentsModel = GetHelpPersonnelBillingAttachmentsModel(entity, RequestAttachmentTypeEnum.HelpPersonnelBillingRequest);
     LoadDictionaries(model);
     SetFlagsState(id, currUser, entity, model);
     SetHiddenFields(model);
     return model;
 }
コード例 #7
0
ファイル: HelpBl.cs プロジェクト: andreyu/Reports
        protected void SetFlagsState(int id, User current, HelpPersonnelBillingRequest entity, EditPersonnelBillingRequestViewModel model)
        {
            UserRole currentRole = AuthenticationService.CurrentUser.UserRole;
            SetFlagsState(model, false);
            if (model.Id == 0)
            {
                model.IsEditable = true;
                model.IsSaveAvailable = true;
                model.IsSendAvailable = true;
                return;
            }

            if (AuthenticationService.CurrentUser.Id == 10 || AuthenticationService.CurrentUser.UserRole == UserRole.ConsultantOutsourcing ||
                AuthenticationService.CurrentUser.UserRole == UserRole.PersonnelManager || AuthenticationService.CurrentUser.UserRole == UserRole.Estimator||
                AuthenticationService.CurrentUser.UserRole == UserRole.ConsultantPersonnel ||
                AuthenticationService.CurrentUser.UserRole == UserRole.Accountant ||
                AuthenticationService.CurrentUser.UserRole == UserRole.TaxCollector ||
                AuthenticationService.CurrentUser.UserRole == UserRole.Estimator
                )
            {
                if (entity.Creator.Id == current.Id)
                {
                    if (!entity.EndWorkDate.HasValue)
                    {
                        model.IsEditable = true;
                        model.IsSaveAvailable = entity.SendDate.HasValue ? false : true;
                        model.IsSendAvailable = true;
                    }
                }
                else
                {
                    //кому доступно сообщение в реестре могут отвечать
                    //консультант может закрыть тему созданную другими
                    if (entity.SendDate.HasValue && !entity.BeginWorkDate.HasValue)
                    {
                        model.IsWorkBeginAvailable = true;
                        //model.IsSaveAvailable = true;
                        model.IsAnswerEditable = true;
                    }

                    if (entity.BeginWorkDate.HasValue && !entity.EndWorkDate.HasValue)
                    {
                        model.IsSendAvailable = AuthenticationService.CurrentUser.UserRole == UserRole.ConsultantOutsourcing ? true : false; //консультант может закрыть тему созданную другими
                        model.IsAnswerEditable = true;
                    }
                }
            }

            //SetRecepientsDictionary(entity,model);
        }
コード例 #8
0
ファイル: HelpBl.cs プロジェクト: andreyu/Reports
 protected void SetFlagsState(EditPersonnelBillingRequestViewModel model, bool state)
 {
     model.IsAnswerEditable = state;
     model.IsEditable = state;
     model.IsSaveAvailable = state;
     model.IsSendAvailable = state;
     model.IsWorkBeginAvailable = state;
 }
コード例 #9
0
ファイル: HelpBl.cs プロジェクト: andreyu/Reports
 /// <summary>
 /// Сохраняем список ответственных за задачу.
 /// </summary>
 /// <param name="entity">Заявка</param>
 /// <param name="model">Модель заявки.</param>
 /// <param name="currUser">Текущий пользователь.</param>
 /// <returns></returns>
 protected void SaveExecutorTaskList(HelpPersonnelBillingRequest entity, EditPersonnelBillingRequestViewModel model)
 {
     foreach (var item in model.RecipientList)
     {
         if (entity.Executors == null || (item.IsRecipient && entity.Executors.Where(x => x.Worker.Id == item.UserId).Count() == 0))//вновь добавляемый
         {
             entity.Executors.Add(new HelpBillingExecutorTasks
             {
                 Worker = UserDao.Load(item.UserId),
                 CreatedDate = DateTime.Now
             });
         }
         else//существующий
         {
             //если птица снята, то удаляем
             if (!item.IsRecipient && entity.Executors.Where(x => x.Worker.Id == item.UserId).Count() != 0)
             {
                 foreach (var w in entity.Executors)
                 {
                     if (w.Worker.Id == item.UserId)
                     {
                         entity.Executors.Remove(w);
                         break;
                     }
                 }
             }
         }
     }
 }
コード例 #10
0
ファイル: HelpBl.cs プロジェクト: andreyu/Reports
 protected void LoadDictionaries(EditPersonnelBillingRequestViewModel model)
 {
     model.Urgencies = GetPersonnelBillingUrgencies(false);
     model.Titles = GetPersonnelBillingTitles(false);
     model.Comments = HelpPersonnelBillingCommentDao.GetComments(model.Id);
     model.RecipientList = HelpBillingExecutorTaskDao.GetHelpBillingRecipients(model.Id, string.IsNullOrEmpty(model.DateSended));
     model.RecipientGroups = HelpBillingExecutorTaskDao.GetHelpBillingRecipientGroups(model.Id);
 }
コード例 #11
0
ファイル: HelpBl.cs プロジェクト: andreyu/Reports
        protected void ChangeEntityProperties(HelpPersonnelBillingRequest entity, EditPersonnelBillingRequestViewModel model, User currUser, out string error)
        {
            error = string.Empty;
            UserRole currRole = AuthenticationService.CurrentUser.UserRole;
            if (model.IsEditable)
            {
                entity.Department = model.DepartmentId != 0 ? DepartmentDao.Load(model.DepartmentId) : null;
                entity.Question = model.Question;
                entity.Title = HelpBillingTitleDao.Load(model.TitleId);
                entity.Urgency = HelpBillingUrgencyDao.Load(model.UrgencyId);
                entity.UserName = model.UserName;

                //сохраняем список ответственных за выполнение поставленной партией задачи
                if (!entity.SendDate.HasValue && model.RecipientList != null)
                {
                    SaveExecutorTaskList(entity, model);
                }
            }

            if (model.IsAnswerEditable)
                entity.Answer = model.Answer;

            if (AuthenticationService.CurrentUser.Id == 10 || AuthenticationService.CurrentUser.UserRole == UserRole.ConsultantOutsourcing ||
                AuthenticationService.CurrentUser.UserRole == UserRole.PersonnelManager || AuthenticationService.CurrentUser.UserRole == UserRole.Estimator||
                AuthenticationService.CurrentUser.UserRole == UserRole.ConsultantPersonnel ||
                AuthenticationService.CurrentUser.UserRole == UserRole.Accountant ||
                AuthenticationService.CurrentUser.UserRole == UserRole.TaxCollector
                )
            {
                if (entity.Creator.Id == currUser.Id)
                {
                    if (!entity.SendDate.HasValue && model.Operation == 1) // send
                    {
                        entity.SendDate = DateTime.Now;
                    }

                    if (model.Operation == 3)
                    {
                        entity.EndWorkDate = DateTime.Now;
                        entity.BeginWorkDate = entity.BeginWorkDate.HasValue ? entity.BeginWorkDate.Value : DateTime.Now;
                    }
                }
                else
                {
                    //кому направлена тема
                    if (AuthenticationService.CurrentUser.UserRole != UserRole.OutsourcingManager && AuthenticationService.CurrentUser.UserRole != UserRole.Estimator)
                    {
                        if (entity.SendDate.HasValue && !entity.BeginWorkDate.HasValue && entity.Creator.Id != AuthenticationService.CurrentUser.Id)
                        {
                            entity.BeginWorkDate = DateTime.Now;
                        }

                        //консультант может закрыть тему созданную другими
                        if (AuthenticationService.CurrentUser.UserRole == UserRole.ConsultantOutsourcing)
                        {
                            if (model.Operation == 3)
                            {
                                entity.EndWorkDate = DateTime.Now;
                                entity.BeginWorkDate = entity.BeginWorkDate.HasValue ? entity.BeginWorkDate.Value : DateTime.Now;
                            }
                        }
                    }

                }
            }
        }
コード例 #12
0
ファイル: HelpBl.cs プロジェクト: andreyu/Reports
        public bool SavePersonnelBillingRequestModel(EditPersonnelBillingRequestViewModel model, out string error)
        {
            error = string.Empty;
            //User user = null;
            HelpPersonnelBillingRequest entity;

            try
            {
                IUser current = AuthenticationService.CurrentUser;
                User currUser = UserDao.Load(current.Id);
                //user = UserDao.Load(model.UserId);
                if (model.Id == 0)
                {
                    entity = new HelpPersonnelBillingRequest
                    {
                        CreateDate = DateTime.Now,
                        Creator = currUser,
                        Number = RequestNextNumberDao.GetNextNumberForType((int)RequestTypeEnum.HelpPersonnelBillingRequest),
                        EditDate = DateTime.Now,
                        CreatorRoleId = (int)current.UserRole
                    };
                    ChangeEntityProperties(entity, model, currUser, out error);
                    HelpPersonnelBillingRequestDao.SaveAndFlush(entity);
                    model.Id = entity.Id;
                }
                else
                {
                    entity = HelpPersonnelBillingRequestDao.Get(model.Id);
                    if (entity == null)
                        throw new ValidationException(string.Format(StrPersonnalBillingRequestNotFound, model.Id));
                    if (entity.Version != model.Version)
                    {
                        error = StrServiceRequestWasChanged;
                        model.ReloadPage = true;
                        return false;
                    }

                    if (entity.EndWorkDate.HasValue)
                    {
                        error = "Данная тема закрыта автором!";
                        return false;
                    }

                    ChangeEntityProperties(entity, model, currUser, out error);
                    HelpPersonnelBillingRequestDao.SaveAndFlush(entity);
                    if (entity.Version != model.Version)
                    {
                        entity.EditDate = DateTime.Now;
                        HelpPersonnelBillingRequestDao.SaveAndFlush(entity);
                    }
                }

                //переписка
                if (model.Operation != 0 && !entity.EndWorkDate.HasValue)
                {
                    SaveComments(model.Id, model.IsSendAvailable, model.IsSendAvailable ? model.Question : model.Answer, out error);
                    if (!string.IsNullOrEmpty(error))
                        throw new ValidationException(error);
                }

                model.Version = entity.Version;
                SetFlagsState(entity.Id, currUser, entity, model);
                SetBillingRequestInfoModel(entity, model);
                LoadDictionaries(model);
                model.AttachmentsModel = GetHelpPersonnelBillingAttachmentsModel(entity, RequestAttachmentTypeEnum.HelpPersonnelBillingRequest);
                return true;
            }
            catch (Exception ex)
            {
                HelpServiceRequestDao.RollbackTran();
                Log.Error("Error on SavePersonnelBillingRequestModel:", ex);
                error = StrException + ex.GetBaseException().Message;
                return false;
            }
            finally
            {
                //SetUserInfoModel(user, model);
                LoadDictionaries(model);
                SetHiddenFields(model);
            }
        }
コード例 #13
0
ファイル: HelpBl.cs プロジェクト: andreyu/Reports
 public void ReloadDictionariesToModel(EditPersonnelBillingRequestViewModel model)
 {
     HelpPersonnelBillingRequest entity = HelpPersonnelBillingRequestDao.Get(model.Id);
     model.AttachmentsModel = GetHelpPersonnelBillingAttachmentsModel(entity, RequestAttachmentTypeEnum.HelpPersonnelBillingRequest);
     LoadDictionaries(model);
 }