Пример #1
0
 protected bool ValidateHelpQuestionEditModel(HelpQuestionEditModel model)
 {
     return ModelState.IsValid;
 }
Пример #2
0
 protected void CorrectDropdowns(HelpQuestionEditModel model)
 {
     if (!model.IsTypeEditable)
     {
         model.TypeId = model.TypeIdHidden;
         model.SubtypeId = model.SubtypeIdHidden;
     }
 }
Пример #3
0
 protected void CorrectModel(HelpQuestionEditModel model)
 {
     if (model.Operation == 6 && !string.IsNullOrEmpty(model.Answer))
     {
         if (ModelState.ContainsKey("Answer"))
             ModelState.Remove("Answer");
     }
     if (model.Operation == 5)
     {
         if (ModelState.ContainsKey("Question"))
             ModelState.Remove("Question");
         if (ModelState.ContainsKey("Answer"))
             ModelState.Remove("Answer");
     }
 }
Пример #4
0
 public void ReloadDictionariesToModel(HelpQuestionEditModel model)
 {
     HelpQuestionRequest entity = HelpQuestionRequestDao.Load(model.Id);
     LoadDictionaries(model,entity);
 }
Пример #5
0
 public ActionResult HelpQuestionEdit(HelpQuestionEditModel model)
 {
     CorrectModel(model);
     CorrectDropdowns(model);
     //UploadFileDto fileDto = GetFileContext();
     //bool needToReload;
     //string error;
     if (!ValidateHelpQuestionEditModel(model))
     {
         model.Operation = 0;
         HelpBl.ReloadDictionariesToModel(model);
         return View(model);
     }
     string error;
     if (!HelpBl.SaveHelpQuestionEditModel(model, out error))
     {
         //HttpContext.AddError(new Exception(error));
         if (model.ReloadPage)
         {
             ModelState.Clear();
             if (!string.IsNullOrEmpty(error))
                 ModelState.AddModelError("", error);
             return View(HelpBl.GetHelpQuestionEditModel(model.Id, model.UserId));
         }
         if (!string.IsNullOrEmpty(error))
             ModelState.AddModelError("", error);
     }
     return View(model);
 }
Пример #6
0
        protected void SetStaticFields(HelpQuestionEditModel model, HelpQuestionRequest entity)
        {
            model.Version = entity.Version;
            model.DocumentNumber = entity.Number.ToString();
            model.DateCreated = FormatDate(entity.CreateDate);
            model.Creator = entity.Creator.FullName;

            if (entity.ConsultantOutsourcing != null)
                model.Worker = entity.ConsultantOutsourcing.FullName;

            if (entity.ConsultantPersonnel != null)
                model.Worker = entity.ConsultantPersonnel.FullName;

            if (entity.ConsultantAccountant != null)
                model.Worker = entity.ConsultantAccountant.FullName;

            if (entity.ConsultantOutsorsingManager != null)
                model.Worker = entity.ConsultantOutsorsingManager.FullName;

            if (entity.SendDate.HasValue)
                model.QuestionSendDate = entity.SendDate.Value.ToShortDateString();
            if (entity.EndWorkDate.HasValue)
                model.WorkerEndDate = entity.EndWorkDate.Value.ToShortDateString();
            if (entity.ConfirmWorkDate.HasValue)
                model.ConfirmDate = entity.ConfirmWorkDate.Value.ToShortDateString();
        }
Пример #7
0
        public HelpQuestionEditModel GetHelpQuestionEditModel(int id, int? userId)
        {
            IUser current = AuthenticationService.CurrentUser;
            if (id == 0 && !userId.HasValue)
            {
                if ((current.UserRole & UserRole.Employee) == UserRole.Employee || (current.UserRole & UserRole.Manager) == UserRole.Manager || (current.UserRole & UserRole.DismissedEmployee) == UserRole.DismissedEmployee)
                    userId = current.Id;
                else
                    throw new ValidationException(StrQuestionNoUser);
            }
            HelpQuestionRequest entity = null;
            if (id != 0)
                entity = HelpQuestionRequestDao.Load(id);
            HelpQuestionEditModel model = new HelpQuestionEditModel
            {
                Id = id,
                UserId = id == 0 ? userId.Value : entity.User.Id
            };
            User user = UserDao.Load(model.UserId);
            User currUser = UserDao.Load(current.Id);
            if (id == 0)
            {
                entity = new HelpQuestionRequest
                {
                    User = user,
                    Creator = currUser,
                    CreateDate = DateTime.Now,
                    EditDate = DateTime.Now
                };
            }
            else
            {
                model.TypeId = entity.Type.Id;
                model.SubtypeId = entity.Subtype.Id;
                model.Question = entity.Question;
                model.Answer = entity.Answer;

                SetStaticFields(model, entity);
            }
            if (!CheckUserRights(currUser, current.UserRole, entity))
            {
                Log.ErrorFormat("GetHelpQuestionEditModel:CheckUserRights return false for user {0}, request {1}", current.Id, entity.Id);
                throw new ArgumentException("Доступ запрещен.");
            }
            model.IsForQuestion = true;
            SetUserInfoModel(user, model);
            LoadDictionaries(model,entity);
            SetFlagsState(id, currUser, entity, model);

            SetHiddenFields(model);
            return model;
        }
Пример #8
0
        protected void SetFlagsState(HelpQuestionEditModel model, bool state)
        {
            model.IsTypeEditable = state;
            model.IsQuestionEditable = state;
            model.IsAnswerEditable = state;

            model.IsBeginWorkAvailable = state;
            model.IsEndAvailable = state;
            model.IsEndWorkAvailable = state;
            model.IsSaveAvailable = state;
            model.IsSendAvailable = state;
            model.IsRedirectAvailable = state;
        }
Пример #9
0
 protected void SetHiddenFields(HelpQuestionEditModel model)
 {
     model.TypeIdHidden = model.TypeId;
     model.SubtypeIdHidden = model.SubtypeId;
 }
Пример #10
0
        protected void SetFlagsState(int id, User current, HelpQuestionRequest entity, HelpQuestionEditModel model)
        {
            UserRole currentRole = AuthenticationService.CurrentUser.UserRole;
            SetFlagsState(model, false);
            if (model.Id == 0)
            {
                if ((currentRole & UserRole.ConsultantPersonnel) != UserRole.ConsultantPersonnel && (currentRole & UserRole.Manager) != UserRole.Manager && (currentRole & UserRole.Employee) != UserRole.Employee && (currentRole & UserRole.DismissedEmployee) != UserRole.DismissedEmployee)
                    throw new ArgumentException(string.Format(StrUserNotManager, current.Id));
                model.IsTypeEditable = true;
                model.IsQuestionEditable = true;
                model.IsSaveAvailable = true;
                model.IsSendAvailable = true;
                return;
            }
            switch (currentRole)
            {
                case UserRole.Employee:
                    if (entity.Creator.Id == current.Id)
                    {
                        if (!entity.SendDate.HasValue)
                        {
                            if (entity.HistoryEntities == null || entity.HistoryEntities.Count == 0)
                                model.IsTypeEditable = true;
                            model.IsQuestionEditable = true;
                            model.IsSendAvailable = true;
                            model.IsSaveAvailable = true;
                        }
                        if (entity.EndWorkDate.HasValue && !entity.ConfirmWorkDate.HasValue)
                            model.IsEndAvailable = true;
                    }
                    break;
                case UserRole.DismissedEmployee:
                    if (entity.Creator.Id == current.Id)
                    {
                        if (!entity.SendDate.HasValue)
                        {
                            if (entity.HistoryEntities == null || entity.HistoryEntities.Count == 0)
                                model.IsTypeEditable = true;
                            model.IsQuestionEditable = true;
                            model.IsSendAvailable = true;
                            model.IsSaveAvailable = true;
                        }
                        if (entity.EndWorkDate.HasValue && !entity.ConfirmWorkDate.HasValue)
                            model.IsEndAvailable = true;
                    }
                    break;
                case UserRole.Manager:
                    if (entity.Creator.Id == current.Id)
                    {
                        if (!entity.SendDate.HasValue)
                        {
                            if (entity.HistoryEntities == null || entity.HistoryEntities.Count == 0)
                                model.IsTypeEditable = true;
                            model.IsQuestionEditable = true;
                            model.IsSendAvailable = true;
                            model.IsSaveAvailable = true;
                        }
                        if (entity.EndWorkDate.HasValue && !entity.ConfirmWorkDate.HasValue)
                            model.IsEndAvailable = true;
                    }
                    break;
                case UserRole.ConsultantOutsourcing:
                    //if ((entity.ConsultantOutsourcing == null || (entity.ConsultantOutsourcing.Id == current.Id))
                    //    && (!entity.ConsultantRoleId.HasValue ||
                    //         entity.ConsultantRoleId.Value == (int) UserRole.ConsultantOutsourcing))
                    //{
                    //}
                    //могут отвечать на любые открытые вопросы, не важно кому направленные
                    //вытащил кусок из закомментаренного условия

                    if (entity.ConsultantOutsourcing != null && entity.ConsultantOutsourcing.Id == current.Id
                            && entity.BeginWorkDate.HasValue && !entity.EndWorkDate.HasValue)
                        {
                            model.IsEndWorkAvailable = true;
                            model.IsRedirectAvailable = true;
                            model.IsSaveAvailable = true;
                            model.IsAnswerEditable = true;
                        }
                        if (entity.SendDate.HasValue &&  !entity.EndWorkDate.HasValue/*!entity.BeginWorkDate.HasValue*/)
                        {
                            model.IsRedirectAvailable = true;
                            model.IsBeginWorkAvailable = true;
                        }
                        if (entity.EndWorkDate.HasValue && !entity.ConfirmWorkDate.HasValue)
                                model.IsEndAvailable = true;//могут закрывать тему
                        if (!entity.EndWorkDate.HasValue) model.IsBaseAvailable = true;
                        else  model.IsBaseAvailable = entity.Base;
                    break;
                case UserRole.ConsultantPersonnel:
                    if (entity.Creator.Id == current.Id)
                    {
                        if (!entity.SendDate.HasValue)
                        {
                            if (entity.HistoryEntities == null || entity.HistoryEntities.Count == 0)
                                model.IsTypeEditable = true;
                            model.IsQuestionEditable = true;
                            model.IsSendAvailable = true;
                            model.IsSaveAvailable = true;
                        }
                        if (entity.EndWorkDate.HasValue && !entity.ConfirmWorkDate.HasValue)
                            model.IsEndAvailable = true;
                    }
                    if ((entity.ConsultantPersonnel == null || (entity.ConsultantPersonnel.Id == current.Id))
                        && (!entity.ConsultantRoleId.HasValue ||
                             entity.ConsultantRoleId.Value == (int)UserRole.ConsultantPersonnel))
                    {
                        if (entity.ConsultantPersonnel != null && entity.ConsultantPersonnel.Id == current.Id
                            && entity.BeginWorkDate.HasValue && !entity.EndWorkDate.HasValue)
                        {
                            model.IsEndWorkAvailable = true;
                            model.IsRedirectAvailable = true;
                            model.IsSaveAvailable = true;
                            model.IsAnswerEditable = true;
                        }
                        if (entity.SendDate.HasValue && !entity.BeginWorkDate.HasValue)
                        {
                            model.IsRedirectAvailable = true;
                            model.IsBeginWorkAvailable = true;
                        }
                    }
                    break;
                case UserRole.PersonnelManager:
                    if ((entity.ConsultantOutsorsingManager == null || (entity.ConsultantOutsorsingManager.Id == current.Id))
                        && (!entity.ConsultantRoleId.HasValue ||
                             entity.ConsultantRoleId.Value == (int)UserRole.PersonnelManager))
                    {
                        if (//entity.ConsultantOutsorsingManager != null && entity.ConsultantOutsorsingManager.Id == current.Id
                            //&&
                            entity.BeginWorkDate.HasValue && !entity.EndWorkDate.HasValue)
                        {
                            model.IsEndWorkAvailable = true;
                            model.IsRedirectAvailable = true;//разрешил перенаправлять
                            model.IsSaveAvailable = false;
                            model.IsAnswerEditable = true;
                        }
                        if (entity.SendDate.HasValue && !entity.BeginWorkDate.HasValue)
                        {
                            model.IsRedirectAvailable = false;
                            model.IsBeginWorkAvailable = true;
                        }
                    }
                    break;
                //case UserRole.PersonnelManager:
                //    if ((entity.PersonnelManager == null || (entity.PersonnelManager.Id == current.Id))
                //        && (!entity.ConsultantRoleId.HasValue ||
                //             entity.ConsultantRoleId.Value == (int)UserRole.PersonnelManager))
                //    {
                //        if (entity.PersonnelManager != null && entity.PersonnelManager.Id == current.Id
                //            && entity.BeginWorkDate.HasValue && !entity.EndWorkDate.HasValue)
                //        {
                //            model.IsEndWorkAvailable = true;
                //            model.IsRedirectAvailable = true;
                //            model.IsSaveAvailable = true;
                //            model.IsAnswerEditable = true;
                //        }
                //        if (entity.SendDate.HasValue && !entity.BeginWorkDate.HasValue)
                //        {
                //            model.IsRedirectAvailable = true;
                //            model.IsBeginWorkAvailable = true;
                //        }
                //    }
                //    break;
                case UserRole.Accountant:
                    if ((entity.ConsultantAccountant == null || (entity.ConsultantAccountant.Id == current.Id))
                        && (!entity.ConsultantRoleId.HasValue ||
                             entity.ConsultantRoleId.Value == (int)UserRole.Accountant))
                    {
                        if (entity.ConsultantAccountant != null && entity.ConsultantAccountant.Id == current.Id
                            && entity.BeginWorkDate.HasValue && !entity.EndWorkDate.HasValue)
                        {
                            model.IsEndWorkAvailable = true;
                            model.IsRedirectAvailable = true;
                            model.IsSaveAvailable = true;
                            model.IsAnswerEditable = true;
                        }
                        if (entity.SendDate.HasValue && !entity.BeginWorkDate.HasValue)
                        {
                            model.IsRedirectAvailable = true;
                            model.IsBeginWorkAvailable = true;
                        }
                    }
                    break;
            }
        }
Пример #11
0
 protected void LoadHistory(HelpQuestionEditModel model, HelpQuestionRequest entity)
 {
     if (entity.HistoryEntities == null || entity.HistoryEntities.Count == 0)
         return;
     model.HistoryEntities = entity.HistoryEntities
         .OrderByDescending(x => x.CreateDate).ToList()
         .ConvertAll(x => new HistoryEntityModel
                              {
                                  Answer = x.Answer,
                                  CreateDate = x.CreateDate.ToString(),
                                  CreatorName = x.Creator.FullName,
                                  Question = x.Question,
                                  Message = GetMessage(x)
                              });
 }
Пример #12
0
 protected void LoadDictionaries(HelpQuestionEditModel model,HelpQuestionRequest entity)
 {
     LoadHistory(model, entity);
     List<HelpQuestionType> types = HelpQuestionTypeDao.LoadAllSortedByOrder();
     model.Types = types.ConvertAll(x => new IdNameDto { Id = x.Id, Name = x.Name });
     if (model.TypeId == 0)
         model.TypeId = types.First().Id;
     model.Subtypes = HelpQuestionSubtypeDao.LoadForTypeIdSortedByOrder(model.TypeId)
         .ConvertAll(x => new IdNameDto { Id = x.Id, Name = x.Name });
 }
Пример #13
0
        protected void ChangeEntityProperties(HelpQuestionRequest entity, HelpQuestionEditModel model,
            User currUser, out string error)
        {
            error = string.Empty;
            UserRole currRole = AuthenticationService.CurrentUser.UserRole;
            if (model.IsTypeEditable)
            {
                entity.Type = HelpQuestionTypeDao.Load(model.TypeId);
                entity.Subtype = HelpQuestionSubtypeDao.Load(model.SubtypeId);
            }
            if (model.IsQuestionEditable)
                entity.Question = model.Question;
            if(model.IsAnswerEditable)
                entity.Answer = model.Answer;
            switch (currRole)
            {
                case UserRole.Employee:
                    if (entity.Creator.Id == currUser.Id)
                    {
                        if (model.Operation == 1 && !entity.SendDate.HasValue)
                        {
                            entity.SendDate = DateTime.Now;
                            entity.ConsultantRoleId = (int)UserRole.ConsultantOutsourcing;
                            HelpQuestionHistoryEntity send = new HelpQuestionHistoryEntity
                            {
                                CreateDate = DateTime.Now,
                                Creator = currUser,
                                CreatorRoleId = (int)currRole,
                                Question = entity.Question,
                                RecipientRoleId = (int)UserRole.ConsultantOutsourcing,
                                Request = entity,
                                Type = 1,// send
                            };
                            entity.HistoryEntities.Add(send);
                        }
                        if (entity.EndWorkDate.HasValue)
                        {
                            if (model.Operation == 4)
                            {
                                entity.ConfirmWorkDate = DateTime.Now;
                                HelpQuestionHistoryEntity confirm = new HelpQuestionHistoryEntity
                                {
                                    Answer = entity.Answer,
                                    CreateDate = DateTime.Now,
                                    Creator = currUser,
                                    CreatorRoleId = (int)currRole,
                                    Question = entity.Question,
                                    RecipientRoleId = (int)currRole,
                                    Request = entity,
                                    Type = 4,// confirm
                                };
                                entity.HistoryEntities.Add(confirm);
                            }
                            else if (model.Operation == 5)
                            {
                                entity.SendDate = null;
                                entity.BeginWorkDate = null;
                                entity.EndWorkDate = null;
                                HelpQuestionHistoryEntity reject = new HelpQuestionHistoryEntity
                                {
                                    Answer = entity.Answer,
                                    CreateDate = DateTime.Now,
                                    Creator = currUser,
                                    CreatorRoleId = (int)currRole,
                                    Question = entity.Question,
                                    RecipientRoleId = (int)currRole,
                                    Request = entity,
                                    Type = 5,// reject
                                };
                                entity.HistoryEntities.Add(reject);
                                model.Answer = null;
                                model.Question = null;
                                entity.Answer = null;
                                entity.Question = null;
                                entity.ConsultantRoleId = null;
                            }
                        }
                    }
                    break;
                case UserRole.DismissedEmployee:
                    if (entity.Creator.Id == currUser.Id)
                    {
                        if (model.Operation == 1 && !entity.SendDate.HasValue)
                        {
                            entity.SendDate = DateTime.Now;
                            entity.ConsultantRoleId = (int)UserRole.ConsultantOutsourcing;
                            HelpQuestionHistoryEntity send = new HelpQuestionHistoryEntity
                            {
                                CreateDate = DateTime.Now,
                                Creator = currUser,
                                CreatorRoleId = (int)currRole,
                                Question = entity.Question,
                                RecipientRoleId = (int)UserRole.ConsultantOutsourcing,
                                Request = entity,
                                Type = 1,// send
                            };
                            entity.HistoryEntities.Add(send);
                        }
                        if (entity.EndWorkDate.HasValue)
                        {
                            if (model.Operation == 4)
                            {
                                entity.ConfirmWorkDate = DateTime.Now;
                                HelpQuestionHistoryEntity confirm = new HelpQuestionHistoryEntity
                                {
                                    Answer = entity.Answer,
                                    CreateDate = DateTime.Now,
                                    Creator = currUser,
                                    CreatorRoleId = (int)currRole,
                                    Question = entity.Question,
                                    RecipientRoleId = (int)currRole,
                                    Request = entity,
                                    Type = 4,// confirm
                                };
                                entity.HistoryEntities.Add(confirm);
                            }
                            else if (model.Operation == 5)
                            {
                                entity.SendDate = null;
                                entity.BeginWorkDate = null;
                                entity.EndWorkDate = null;
                                HelpQuestionHistoryEntity reject = new HelpQuestionHistoryEntity
                                {
                                    Answer = entity.Answer,
                                    CreateDate = DateTime.Now,
                                    Creator = currUser,
                                    CreatorRoleId = (int)currRole,
                                    Question = entity.Question,
                                    RecipientRoleId = (int)currRole,
                                    Request = entity,
                                    Type = 5,// reject
                                };
                                entity.HistoryEntities.Add(reject);
                                model.Answer = null;
                                model.Question = null;
                                entity.Answer = null;
                                entity.Question = null;
                                entity.ConsultantRoleId = null;
                            }
                        }
                    }
                    break;
                case UserRole.Manager:
                    if (entity.Creator.Id == currUser.Id)
                    {
                        if (model.Operation == 1 && !entity.SendDate.HasValue)
                        {
                            entity.SendDate = DateTime.Now;
                            entity.ConsultantRoleId = (int) UserRole.ConsultantOutsourcing;
                            HelpQuestionHistoryEntity send = new HelpQuestionHistoryEntity
                            {
                                CreateDate = DateTime.Now,
                                Creator = currUser,
                                CreatorRoleId = (int)currRole,
                                Question = entity.Question,
                                RecipientRoleId = (int)UserRole.ConsultantOutsourcing,
                                Request = entity,
                                Type = 1,// send
                            };
                            entity.HistoryEntities.Add(send);
                        }
                        if (entity.EndWorkDate.HasValue)
                        {
                            if (model.Operation == 4)
                            {
                                entity.ConfirmWorkDate = DateTime.Now;
                                HelpQuestionHistoryEntity confirm = new HelpQuestionHistoryEntity
                                {
                                    Answer = entity.Answer,
                                    CreateDate = DateTime.Now,
                                    Creator = currUser,
                                    CreatorRoleId = (int)currRole,
                                    Question = entity.Question,
                                    RecipientRoleId = (int)currRole,
                                    Request = entity,
                                    Type = 4,// confirm
                                };
                                entity.HistoryEntities.Add(confirm);
                            }
                            else if (model.Operation == 5)
                            {
                                entity.SendDate = null;
                                entity.BeginWorkDate = null;
                                entity.EndWorkDate = null;
                                HelpQuestionHistoryEntity reject = new HelpQuestionHistoryEntity
                                {
                                    Answer = entity.Answer,
                                    CreateDate = DateTime.Now,
                                    Creator = currUser,
                                    CreatorRoleId = (int)currRole,
                                    Question = entity.Question,
                                    RecipientRoleId = (int)currRole,
                                    Request = entity,
                                    Type = 5,// reject
                                };
                                entity.HistoryEntities.Add(reject);
                                model.Answer = null;
                                model.Question = null;
                                entity.Answer = null;
                                entity.Question = null;
                            }
                        }
                    }
                    break;
                case UserRole.ConsultantOutsourcing:
                    //закомментарил чтобы консультанты могли перекрывать друг друга
                    //if (entity.ConsultantOutsourcing == null || (entity.ConsultantOutsourcing.Id == currUser.Id))
                    //{
                        if (model.Operation == 2 && entity.SendDate.HasValue)
                        {
                            entity.BeginWorkDate = DateTime.Now;
                            entity.ConsultantOutsourcing = currUser;
                            entity.ConsultantRoleId = (int) UserRole.ConsultantOutsourcing;
                            HelpQuestionHistoryEntity beginWork = new HelpQuestionHistoryEntity
                            {
                                //Answer = entity.Answer,
                                Consultant = currUser,
                                CreateDate = DateTime.Now,
                                Creator = currUser,
                                CreatorRoleId = (int)currRole,
                                Question = entity.Question,
                                RecipientRoleId = (int)currRole,
                                Request = entity,
                                Type = 2,// beginWork
                            };
                            entity.HistoryEntities.Add(beginWork);

                        }
                        if (/*entity.ConsultantOutsourcing != null && entity.ConsultantOutsourcing.Id == currUser.Id
                            &&*/ model.Operation == 3 && entity.BeginWorkDate.HasValue)
                        {
                            entity.EndWorkDate = DateTime.Now;
                            HelpQuestionHistoryEntity endWork = new HelpQuestionHistoryEntity
                            {
                                Answer = entity.Answer,
                                Consultant = currUser,
                                CreateDate = DateTime.Now,
                                Creator = currUser,
                                CreatorRoleId = (int)currRole,
                                Question = entity.Question,
                                RecipientRoleId = (int)currRole,
                                Request = entity,
                                Type = 3,// endWork
                            };
                            entity.HistoryEntities.Add(endWork);
                        }

                        if (entity.EndWorkDate.HasValue)//можно закрыть тему
                        {
                            if (model.Operation == 4)
                            {
                                entity.ConfirmWorkDate = DateTime.Now;
                                HelpQuestionHistoryEntity confirm = new HelpQuestionHistoryEntity
                                {
                                    Answer = entity.Answer,
                                    CreateDate = DateTime.Now,
                                    Creator = currUser,
                                    CreatorRoleId = (int)currRole,
                                    Question = entity.Question,
                                    RecipientRoleId = (int)currRole,
                                    Request = entity,
                                    Type = 4,// confirm
                                };
                                entity.HistoryEntities.Add(confirm);
                            }
                        }

                        if (model.Operation == 6 && entity.SendDate.HasValue && !entity.EndWorkDate.HasValue) //redirect
                        {
                            entity.ConsultantRoleId = model.RedirectRoleId;
                            entity.BeginWorkDate = null;
                            HelpQuestionHistoryEntity redirect = new HelpQuestionHistoryEntity
                                                                     {
                                                                         Answer = entity.Answer,
                                                                         Consultant = currUser,
                                                                         CreateDate = DateTime.Now,
                                                                         Creator = currUser,
                                                                         CreatorRoleId = (int)currRole,
                                                                         Question = entity.Question,
                                                                         RecipientRoleId = model.RedirectRoleId,
                                                                         Request = entity,
                                                                         Type = 6,// redirect
                                                                     };
                            entity.HistoryEntities.Add(redirect);
                            entity.Answer = null;
                            model.Answer = null;
                        }
                        if (model.Operation == 7)
                        {
                            entity.Base = true;
                        }
                    //}
                    break;
                case UserRole.ConsultantPersonnel:
                    if (entity.ConsultantPersonnel == null || (entity.ConsultantPersonnel.Id == currUser.Id))
                    {
                        if (model.Operation == 1 && !entity.SendDate.HasValue)
                        {
                            entity.SendDate = DateTime.Now;
                            entity.ConsultantRoleId = (int)UserRole.ConsultantOutsourcing;
                            HelpQuestionHistoryEntity send = new HelpQuestionHistoryEntity
                            {
                                CreateDate = DateTime.Now,
                                Creator = currUser,
                                CreatorRoleId = (int)currRole,
                                Question = entity.Question,
                                RecipientRoleId = (int)UserRole.ConsultantOutsourcing,
                                Request = entity,
                                Type = 1,// send
                            };
                            entity.HistoryEntities.Add(send);
                        }
                        if (model.Operation == 2 && entity.SendDate.HasValue)
                        {
                            entity.BeginWorkDate = DateTime.Now;
                            entity.ConsultantPersonnel = currUser;
                            entity.ConsultantRoleId = (int)UserRole.ConsultantPersonnel;
                            HelpQuestionHistoryEntity beginWork = new HelpQuestionHistoryEntity
                            {
                                //Answer = entity.Answer,
                                Consultant = currUser,
                                CreateDate = DateTime.Now,
                                Creator = currUser,
                                CreatorRoleId = (int)currRole,
                                Question = entity.Question,
                                RecipientRoleId = (int)currRole,
                                Request = entity,
                                Type = 2,// beginWork
                            };
                            entity.HistoryEntities.Add(beginWork);
                        }
                        if (entity.ConsultantPersonnel != null && entity.ConsultantPersonnel.Id == currUser.Id
                            && model.Operation == 3 && entity.BeginWorkDate.HasValue)
                        {
                            entity.EndWorkDate = DateTime.Now;
                            HelpQuestionHistoryEntity endWork = new HelpQuestionHistoryEntity
                            {
                                Answer = entity.Answer,
                                Consultant = currUser,
                                CreateDate = DateTime.Now,
                                Creator = currUser,
                                CreatorRoleId = (int)currRole,
                                Question = entity.Question,
                                RecipientRoleId = (int)currRole,
                                Request = entity,
                                Type = 3,// endWork
                            };
                            entity.HistoryEntities.Add(endWork);
                        }
                        if (model.Operation == 6 && entity.SendDate.HasValue && !entity.EndWorkDate.HasValue) //redirect
                        {
                            entity.ConsultantRoleId = model.RedirectRoleId;
                            entity.BeginWorkDate = null;
                            HelpQuestionHistoryEntity redirect = new HelpQuestionHistoryEntity
                            {
                                Answer = entity.Answer,
                                Consultant = currUser,
                                CreateDate = DateTime.Now,
                                Creator = currUser,
                                CreatorRoleId = (int)currRole,
                                Question = entity.Question,
                                RecipientRoleId = model.RedirectRoleId,
                                Request = entity,
                                Type = 6,// redirect
                            };
                            entity.HistoryEntities.Add(redirect);
                            entity.Answer = null;
                            model.Answer = null;
                        }
                    }
                    break;
                case UserRole.Accountant:
                    if (entity.ConsultantAccountant == null || (entity.ConsultantAccountant.Id == currUser.Id))
                    {
                        if (model.Operation == 2 && entity.SendDate.HasValue)
                        {
                            entity.BeginWorkDate = DateTime.Now;
                            entity.ConsultantAccountant = currUser;
                            entity.ConsultantRoleId = (int)UserRole.Accountant;
                            HelpQuestionHistoryEntity beginWork = new HelpQuestionHistoryEntity
                            {
                                //Answer = entity.Answer,
                                Consultant = currUser,
                                CreateDate = DateTime.Now,
                                Creator = currUser,
                                CreatorRoleId = (int)currRole,
                                Question = entity.Question,
                                RecipientRoleId = (int)currRole,
                                Request = entity,
                                Type = 2,// beginWork
                            };
                            entity.HistoryEntities.Add(beginWork);
                        }
                        if (entity.ConsultantAccountant != null && entity.ConsultantAccountant.Id == currUser.Id
                            && model.Operation == 3 && entity.BeginWorkDate.HasValue)
                        {
                            entity.EndWorkDate = DateTime.Now;
                            HelpQuestionHistoryEntity endWork = new HelpQuestionHistoryEntity
                            {
                                Answer = entity.Answer,
                                Consultant = currUser,
                                CreateDate = DateTime.Now,
                                Creator = currUser,
                                CreatorRoleId = (int)currRole,
                                Question = entity.Question,
                                RecipientRoleId = (int)currRole,
                                Request = entity,
                                Type = 3,// endWork
                            };
                            entity.HistoryEntities.Add(endWork);
                        }
                        if (model.Operation == 6 && entity.SendDate.HasValue && !entity.EndWorkDate.HasValue) //redirect
                        {
                            entity.ConsultantRoleId = model.RedirectRoleId;
                            entity.BeginWorkDate = null;
                            HelpQuestionHistoryEntity redirect = new HelpQuestionHistoryEntity
                            {
                                Answer = entity.Answer,
                                Consultant = currUser,
                                CreateDate = DateTime.Now,
                                Creator = currUser,
                                CreatorRoleId = (int)currRole,
                                Question = entity.Question,
                                RecipientRoleId = model.RedirectRoleId,
                                Request = entity,
                                Type = 6,// redirect
                            };
                            entity.HistoryEntities.Add(redirect);
                            entity.Answer = null;
                            model.Answer = null;
                        }
                    }
                    break;
                //case UserRole.PersonnelManager:
                //    if (entity.PersonnelManager == null || (entity.PersonnelManager.Id == currUser.Id))
                //    {
                //        if (model.Operation == 2 && entity.SendDate.HasValue)
                //        {
                //            entity.BeginWorkDate = DateTime.Now;
                //            entity.PersonnelManager = currUser;
                //            entity.ConsultantRoleId = (int)UserRole.PersonnelManager;
                //            HelpQuestionHistoryEntity beginWork = new HelpQuestionHistoryEntity
                //            {
                //                //Answer = entity.Answer,
                //                Consultant = currUser,
                //                CreateDate = DateTime.Now,
                //                Creator = currUser,
                //                CreatorRoleId = (int)currRole,
                //                Question = entity.Question,
                //                RecipientRoleId = (int)currRole,
                //                Request = entity,
                //                Type = 2,// beginWork
                //            };
                //            entity.HistoryEntities.Add(beginWork);
                //        }
                //        if (entity.PersonnelManager != null && entity.PersonnelManager.Id == currUser.Id
                //            && model.Operation == 3 && entity.BeginWorkDate.HasValue)
                //        {
                //            entity.EndWorkDate = DateTime.Now;
                //            HelpQuestionHistoryEntity endWork = new HelpQuestionHistoryEntity
                //            {
                //                Answer = entity.Answer,
                //                Consultant = currUser,
                //                CreateDate = DateTime.Now,
                //                Creator = currUser,
                //                CreatorRoleId = (int)currRole,
                //                Question = entity.Question,
                //                RecipientRoleId = (int)currRole,
                //                Request = entity,
                //                Type = 3,// endWork
                //            };
                //            entity.HistoryEntities.Add(endWork);
                //        }
                //        if (model.Operation == 6 && entity.SendDate.HasValue && !entity.EndWorkDate.HasValue) //redirect
                //        {
                //            entity.ConsultantRoleId = model.RedirectRoleId;
                //            entity.BeginWorkDate = null;
                //            HelpQuestionHistoryEntity redirect = new HelpQuestionHistoryEntity
                //            {
                //                Answer = entity.Answer,
                //                Consultant = currUser,
                //                CreateDate = DateTime.Now,
                //                Creator = currUser,
                //                CreatorRoleId = (int)currRole,
                //                Question = entity.Question,
                //                RecipientRoleId = model.RedirectRoleId,
                //                Request = entity,
                //                Type = 6,// redirect
                //            };
                //            entity.HistoryEntities.Add(redirect);
                //            entity.Answer = null;
                //            model.Answer = null;
                //        }
                //    }
                //    break;
                case UserRole.PersonnelManager:
                    if (entity.ConsultantOutsorsingManager == null || (entity.ConsultantOutsorsingManager.Id == currUser.Id))
                    {
                        if (model.Operation == 2 && entity.SendDate.HasValue)
                        {
                            entity.BeginWorkDate = DateTime.Now;
                            entity.ConsultantOutsorsingManager = currUser;
                            entity.ConsultantRoleId = (int)UserRole.PersonnelManager;
                            HelpQuestionHistoryEntity beginWork = new HelpQuestionHistoryEntity
                            {
                                //Answer = entity.Answer,
                                Consultant = currUser,
                                CreateDate = DateTime.Now,
                                Creator = currUser,
                                CreatorRoleId = (int)currRole,
                                Question = entity.Question,
                                RecipientRoleId = (int)currRole,
                                Request = entity,
                                Type = 2,// beginWork
                            };
                            entity.HistoryEntities.Add(beginWork);
                        }
                        if (//entity.ConsultantOutsorsingManager != null && entity.ConsultantOutsorsingManager.Id == currUser.Id
                            //&&
                            model.Operation == 3 && entity.BeginWorkDate.HasValue)
                        {
                            entity.EndWorkDate = DateTime.Now;
                            HelpQuestionHistoryEntity endWork = new HelpQuestionHistoryEntity
                            {
                                Answer = entity.Answer,
                                Consultant = currUser,
                                CreateDate = DateTime.Now,
                                Creator = currUser,
                                CreatorRoleId = (int)currRole,
                                Question = entity.Question,
                                RecipientRoleId = (int)currRole,
                                Request = entity,
                                Type = 3,// endWork
                            };
                            entity.HistoryEntities.Add(endWork);
                        }
                        if (model.Operation == 6 && entity.SendDate.HasValue && !entity.EndWorkDate.HasValue) //redirect
                        {
                            entity.ConsultantRoleId = model.RedirectRoleId;
                            entity.BeginWorkDate = null;
                            HelpQuestionHistoryEntity redirect = new HelpQuestionHistoryEntity
                            {
                                Answer = entity.Answer,
                                Consultant = currUser,
                                CreateDate = DateTime.Now,
                                Creator = currUser,
                                CreatorRoleId = (int)currRole,
                                Question = entity.Question,
                                RecipientRoleId = model.RedirectRoleId,
                                Request = entity,
                                Type = 6,// redirect
                            };
                            entity.HistoryEntities.Add(redirect);
                            entity.Answer = null;
                            model.Answer = null;
                        }
                    }
                    break;
            }
        }
Пример #14
0
        public bool SaveHelpQuestionEditModel(HelpQuestionEditModel model, out string error)
        {
            error = string.Empty;
            User currUser = null;
            User user = null;
            HelpQuestionRequest entity = null;
            try
            {

                IUser current = AuthenticationService.CurrentUser;
                currUser = UserDao.Load(current.Id);
                user = UserDao.Load(model.UserId);

                /*if (model.Id != 0)
                    entity = AppointmentDao.Get(model.Id);*/
                /*if (!CheckUserMoRights(user, current, model.Id, entity, true))
                {
                    error = "Редактирование заявки запрещено";
                    return false;
                }*/

                if (model.Id == 0)
                {
                    entity = new HelpQuestionRequest
                    {
                        CreateDate = DateTime.Now,
                        Creator = currUser,//UserDao.Load(current.Id),
                        Number = RequestNextNumberDao.GetNextNumberForType((int)RequestTypeEnum.HelpQuestionRequest),
                        EditDate = DateTime.Now,
                        User = user,
                        CreatorRoleId = (int)(current.Id == user.Id?current.UserRole:UserRole.Employee),
                        HistoryEntities = new List<HelpQuestionHistoryEntity>()
                    };
                    ChangeEntityProperties(entity, model, currUser, out error);
                    HelpQuestionRequestDao.SaveAndFlush(entity);
                    model.Id = entity.Id;
                    model.DocumentNumber = entity.Number.ToString();
                    model.DateCreated = entity.CreateDate.ToShortDateString();
                    model.Creator = entity.Creator.FullName;
                }
                else
                {
                    entity = HelpQuestionRequestDao.Get(model.Id);
                    if (entity == null)
                        throw new ValidationException(string.Format(StrQuestionRequestNotFound, model.Id));
                    if (entity.Version != model.Version)
                    {
                        error = StrServiceRequestWasChanged;
                        model.ReloadPage = true;
                        return false;
                    }
                    ChangeEntityProperties(entity, model, currUser, out error);
                    HelpQuestionRequestDao.SaveAndFlush(entity);
                    if (entity.Version != model.Version)
                    {
                        if((entity.Creator!=null && entity.Creator.Id==CurrentUser.Id) || (entity.User!=null && entity.User.Id==CurrentUser.Id))
                            entity.EditDate = DateTime.Now;
                        HelpQuestionRequestDao.SaveAndFlush(entity);
                    }
                }
                //if (entity.DeleteDate.HasValue)
                //    model.IsDeleted = true;
                //}
                //model.Version = entity.Version;
                /*model.Worker = entity.Consultant != null ? entity.Consultant.FullName : string.Empty;
                model.WorkerEndDate = entity.EndWorkDate.HasValue ?
                                      entity.EndWorkDate.Value.ToShortDateString() : string.Empty;
                model.ConfirmDate = entity.ConfirmWorkDate.HasValue ?
                                     entity.ConfirmWorkDate.Value.ToShortDateString() : string.Empty;*/
                SetStaticFields(model, entity);
                SetFlagsState(entity.Id, currUser, entity, model);
                return true;
            }
            catch (Exception ex)
            {
                HelpServiceRequestDao.RollbackTran();
                Log.Error("Error on SaveServiceRequestEditModel:", ex);
                error = StrException + ex.GetBaseException().Message;
                return false;
            }
            finally
            {
                //SetUserInfoModel(user, model);
                LoadDictionaries(model,entity);
                SetHiddenFields(model);
            }
        }