Esempio n. 1
0
 protected string GetMessage(HelpQuestionHistoryEntity entity)
 {
     switch (entity.Type)
     {
         case 1://send
             return string.Format("Вопрос задан");
         case 2://begin work
             return string.Format("Вопрос принят в работу");
         case 3://end work
             return string.Format("Ответ на вопрос дан");
         case 4://confirm
             return string.Format("Ответ на вопрос подтвержден");
         case 5://reject
             return string.Format("Ответ на вопрос не подтвержден");
         case 6://redirect
             Role targetRole = RoleDao.Load(entity.RecipientRoleId);
             return string.Format("Заявка перенаправлена роли {0}", targetRole.Name);
         default:
             throw new ArgumentException(string.Format("Неизвестный тип записи в истории {0}",entity.Type));
     }
 }
Esempio n. 2
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;
            }
        }