Exemplo n.º 1
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;
        }
Exemplo n.º 2
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;
            }
        }
Exemplo n.º 3
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();
        }
Exemplo n.º 4
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)
                              });
 }
Exemplo n.º 5
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 });
 }
Exemplo n.º 6
0
        public bool CheckUserRights(User current,UserRole currRole, HelpQuestionRequest entity)
        {
            if ((current.Id == entity.User.Id && ((currRole & UserRole.Manager) == UserRole.Manager || (currRole & UserRole.Employee) == UserRole.Employee)) ||
                (current.Id == entity.Creator.Id && (currRole & UserRole.Manager) == UserRole.Manager))
                return true;
            switch (currRole)
            {
                case UserRole.Employee:
                    return entity.User.Id == current.Id;
                case UserRole.DismissedEmployee:
                    return entity.User.Id == current.Id;
                case UserRole.Manager:
                    if (entity.User.Department == null)
                       throw new ArgumentException(string.Format(StrInvalidUserDepartment, entity.User.Id));
                    if (current.Department == null)
                       throw new ArgumentException(string.Format(StrInvalidUserDepartment, current.Id));
                    switch (current.Level)
                    {
                        case 2:
                        case 3:
                            IList<Department> deps = ManualRoleRecordDao.LoadDepartmentsForUserId(current.Id);
                            if ((entity.User.RoleId & (int)UserRole.Employee) > 0)
                                return deps.Any(x => entity.User.Department.Path.Contains(x.Path));
                            if ((entity.User.RoleId & (int)UserRole.Manager) > 0)
                            {
                                User owner = entity.User;
                                if (owner.Level < current.Level || (owner.Level == current.Level &&
                                    ((owner.IsMainManager && !current.IsMainManager) ||
                                    (!owner.IsMainManager && !current.IsMainManager) ||
                                    (owner.IsMainManager && current.IsMainManager))))
                                    return false;
                                return deps.Any(x => entity.User.Department.Path.Contains(x.Path));
                            }
                            throw new ArgumentException(string.Format(StrInvalidHelpRequestOwner, entity.User.Id,
                                   entity.User.RoleId));
                        case 4:
                        case 5:
                        case 6:
                            if ((entity.User.RoleId & (int)UserRole.Employee) > 0)
                                return entity.User.Department.Path.Contains(current.Department.Path);
                            if ((entity.User.RoleId & (int)UserRole.Manager) > 0)
                            {
                                User owner = entity.User;
                                if (owner.Level < current.Level || (owner.Level == current.Level &&
                                    ((owner.IsMainManager && !current.IsMainManager) ||
                                    (!owner.IsMainManager && !current.IsMainManager) ||
                                    (owner.IsMainManager && current.IsMainManager))))
                                    return false;
                                return entity.User.Department.Path.Contains(current.Department.Path);
                            }
                            throw new ArgumentException(string.Format(StrInvalidHelpRequestOwner, entity.User.Id,
                                    entity.User.RoleId));
                        default:
                            throw new ArgumentException(string.Format(StrInvalidManagerLevel, current.Id,
                                current.Level));

                    }
                case UserRole.ConsultantOutsourcing:
                case UserRole.ConsultantPersonnel:
                case UserRole.Accountant:
                case UserRole.OutsourcingManager:
                case UserRole.Estimator:
                case UserRole.PersonnelManager:
                //case UserRole.ConsultantOutsorsingManager:
                case UserRole.Admin:
                    return true;
            }
            return false;
        }
Exemplo n.º 7
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;
            }
        }
Exemplo n.º 8
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);
            }
        }