Exemple #1
0
 protected void CorrectDropdowns(HelpServiceRequestEditModel model)
 {
     if (!model.IsEditable)
     {
         model.TypeId = model.TypeIdHidden;
         model.ProductionTimeTypeId = model.ProductionTimeTypeIdHidden;
         model.PeriodId = model.PeriodIdHidden;
         model.TransferMethodTypeId = model.TransferMethodTypeIdHidden;
     }
     model.NoteList = HelpBl.GetAllNodeTypesDto();
 }
Exemple #2
0
        protected bool ValidateServiceRequestEditModel(HelpServiceRequestEditModel model, UploadFileDto fileDto)
        {
            /*if (model.Id > 0 && fileDto == null && model.AttachmentId == 0)
            {
                if (model.Operation == 1)
                    ModelState.AddModelError(string.Empty,StrCannotSendRequestWithoutTemplate);
            }*/

            //if (model.TypeId == 15)
            //{
            //    ModelState.AddModelError("TypeId", "Данный вид услуги не доступен для создания заявки!");
            //}

            if(model.IsForFiredUser)
            {
                if (String.IsNullOrWhiteSpace(model.UserBirthDate)) ModelState.AddModelError("UserBirthDate", "Не заполнена дата рождения");
                if (String.IsNullOrWhiteSpace(model.FiredUserName)) ModelState.AddModelError("FiredUserName", "Не заполнено имя");
                if (String.IsNullOrWhiteSpace(model.FiredUserSurname)) ModelState.AddModelError("FiredUserSurname", "Не заполнено фамилия");
                if (String.IsNullOrWhiteSpace(model.FiredUserPatronymic)) ModelState.AddModelError("FiredUserPatronymic", "Не заполнено отчество");
            }
            return ModelState.IsValid;
        }
Exemple #3
0
 public void ReloadDictionariesToModel(HelpServiceRequestEditModel model)
 {
     LoadDictionaries(model);
 }
Exemple #4
0
 public ActionResult ServiceRequestEdit(HelpServiceRequestEditModel model)
 {
     //CorrectCheckboxes(model);
     CorrectDropdowns(model);
     UploadFileDto fileDto = GetFileContext();
     //bool needToReload;
     //string error;
     if (!ValidateServiceRequestEditModel(model, fileDto))
     {
         model.Operation = 0;
         HelpBl.ReloadDictionariesToModel(model);
         return View(model);
     }
     string error;
     if (!HelpBl.SaveServiceRequestEditModel(model, fileDto, out error))
     {
         //HttpContext.AddError(new Exception(error));
         if (model.ReloadPage)
         {
             ModelState.Clear();
             if (!string.IsNullOrEmpty(error))
                 ModelState.AddModelError("", error);
             return View(HelpBl.GetServiceRequestEditModel(model.Id, model.UserId));
         }
         if (!string.IsNullOrEmpty(error))
             ModelState.AddModelError("", error);
     }
     return View(model);
 }
Exemple #5
0
 protected void SetHiddenFields(HelpServiceRequestEditModel model)
 {
     model.TransferMethodTypeIdHidden = model.TransferMethodTypeId;
     model.ProductionTimeTypeIdHidden = model.ProductionTimeTypeIdHidden;
     model.TypeIdHidden = model.TypeId;
     model.PeriodIdHidden = model.PeriodId;
 }
Exemple #6
0
        public HelpServiceRequestEditModel GetServiceRequestEditModel(int id, int? userId)
        {
            IUser current = AuthenticationService.CurrentUser;
            if (id == 0 && !userId.HasValue)
            {
                if ((current.UserRole & UserRole.Employee) == UserRole.Employee || (current.UserRole & UserRole.DismissedEmployee) == UserRole.DismissedEmployee)
                    userId = current.Id;
                else
                    throw new ValidationException(StrNoUser);
            }
            HelpServiceRequest entity = null;
            if (id != 0)
                entity = HelpServiceRequestDao.Load(id);
            HelpServiceRequestEditModel model = new HelpServiceRequestEditModel
            {
                Id = id,
                UserId = id == 0 ? userId.Value : entity.User.Id,
                IsUserEmployee=CurrentUser.UserRole==UserRole.Employee
            };
            User user = UserDao.Load(model.UserId);
            User currUser = UserDao.Load(current.Id);
            if(id == 0)
            {
                entity = new HelpServiceRequest
                             {
                                 User = user,
                                 Creator = currUser,
                                 CreateDate = DateTime.Now,
                                 EditDate = DateTime.Now,
                                 UserBirthDate= DateTime.Now
                             };
            }
            else
            {
                model.TypeId = entity.Type.Id;
                model.IsForGEMoney = entity.IsForGEMoney;
                model.ProductionTimeTypeId = entity.ProductionTime.Id;
                model.TransferMethodTypeId = entity.TransferMethod.Id;
                model.PeriodId = entity.Period == null? new int?() : entity.Period.Id;
                model.FiredUserName = entity.FiredUserName;
                model.FiredUserPatronymic = entity.FiredUserPatronymic;
                model.FiredUserSurname = entity.FiredUserSurname;
                model.UserBirthDate = entity.UserBirthDate==null?String.Empty : entity.UserBirthDate.Value.ToString("dd.MM.yyyy");
                model.IsForFiredUser = (entity.UserBirthDate != null);//Если дата рождения заполнена - значит форма для уволенного сотрудника
                model.Note = entity.Note==null?0 : entity.Note.Id;
                model.Requirements = entity.Requirements;
                model.Version = entity.Version;
                model.DocumentNumber = entity.Number.ToString();
                model.DateCreated = FormatDate(entity.CreateDate);
                model.Creator = entity.Creator.FullName;
                model.Address = entity.Address;
                RequestAttachment attachment = RequestAttachmentDao.FindByRequestIdAndTypeId(entity.Id,
                    RequestAttachmentTypeEnum.HelpServiceRequestTemplate);
                if(attachment != null)
                {
                    model.AttachmentId = attachment.Id;
                    model.Attachment = attachment.FileName;
                }
                RequestAttachment serviceAttach = RequestAttachmentDao.FindByRequestIdAndTypeId(entity.Id,
                    RequestAttachmentTypeEnum.HelpServiceRequest);
                if (serviceAttach != null)
                {
                    model.ServiceAttachmentId = serviceAttach.Id;
                    model.ServiceAttachment = serviceAttach.FileName;
                    model.DocumentsCount = serviceAttach.DocumentsCount;
                }

                RequestPrintForm form = RequestPrintFormDao.FindByRequestAndTypeId(id, RequestPrintFormTypeEnum.ServiceRequest);
                model.IsPrintFormAvailable = form != null;

                if (entity.Consultant != null)
                    model.Worker = entity.Consultant.FullName;
                if (entity.EndWorkDate.HasValue)
                    model.WorkerEndDate = entity.EndWorkDate.Value.ToShortDateString();
                if (entity.ConfirmWorkDate.HasValue)
                    model.ConfirmDate = entity.ConfirmWorkDate.Value.ToShortDateString();
            }
            model.NoteList = noteTypeDao.GetAllNoteTypeDto();
            SetUserInfoModel(user, model);
            LoadDictionaries(model);
            SetFlagsState(id, currUser, entity, model);
            //SetStaticFields(model, entity);

            SetHiddenFields(model);
            return model;
        }
Exemple #7
0
 protected void SetFlagsState(HelpServiceRequestEditModel model, bool state)
 {
     model.IsBeginWorkAvailable = state;
     model.IsEditable = state;
     model.IsEndAvailable = state;
     model.IsEndWorkAvailable = state;
     model.IsNotEndWorkAvailable = state;
     model.IsSaveAvailable = state;
     model.IsSendAvailable = state;
     model.IsConsultantOutsourcingEditable = state;
     //model.IsServiceAttachmentVisible = state;
 }
Exemple #8
0
        protected void SetFlagsState(int id, User current, HelpServiceRequest entity, HelpServiceRequestEditModel 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 && (currentRole & UserRole.PersonnelManager) != UserRole.PersonnelManager)
                    throw new ArgumentException(string.Format(StrUserNotManager, current.Id));
                model.IsEditable = true;
                model.IsSaveAvailable = true;
                return;
            }
            if (entity!=null && entity.FiredUserDepartment != null)
            {
                model.DepartmentId = entity.FiredUserDepartment.Id;
                model.DepartmentName = entity.FiredUserDepartment.Name;
            }
            switch (currentRole)
            {
                case UserRole.ConsultantPersonnel:
                    case UserRole.Employee:
                    if (entity.Creator.Id == current.Id)
                    {
                        if(!entity.SendDate.HasValue)
                        {
                            model.IsEditable = true;
                            model.IsSaveAvailable = true;
                            //if (model.AttachmentId > 0 || !model.IsAttachmentVisible)
                            model.IsSendAvailable = 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)
                        {
                            model.IsEditable = true;
                            model.IsSaveAvailable = true;
                            //if (model.AttachmentId > 0 || !model.IsAttachmentVisible)
                            model.IsSendAvailable = 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)
                        {
                            model.IsEditable = true;
                            model.IsSaveAvailable = true;
                            //if (model.AttachmentId > 0 || !model.IsAttachmentVisible)
                            model.IsSendAvailable = true;
                        }
                        if (entity.EndWorkDate.HasValue && !entity.ConfirmWorkDate.HasValue)
                            model.IsEndAvailable = true;
                    }
                    break;
                case UserRole.ConsultantOutsourcing:
                    if (entity.Consultant == null || (entity.Consultant.Id == current.Id))
                    {
                        if (entity.Consultant != null && entity.Consultant.Id == current.Id
                            && entity.BeginWorkDate.HasValue && !entity.EndWorkDate.HasValue)
                        {
                            model.IsEndWorkAvailable = true;
                            model.IsNotEndWorkAvailable = true;
                            model.IsConsultantOutsourcingEditable = true;
                            model.IsSaveAvailable = true;
                        }
                        if (entity.SendDate.HasValue && !entity.BeginWorkDate.HasValue)
                            model.IsBeginWorkAvailable = true;
                    }
                    //кнопка принятия в работу доступна пока не сформируется услуга не зависимо от того, кто ее принял в работу
                    if (entity.SendDate.HasValue && entity.BeginWorkDate.HasValue && !entity.EndWorkDate.HasValue)
                        model.IsBeginWorkAvailable = true;
                    break;
                /*case UserRole.PersonnelManager:
                    if (entity.Consultant == null || (entity.Consultant.Id == current.Id))
                    {
                        if (entity.Consultant != null && entity.Consultant.Id == current.Id
                            && entity.BeginWorkDate.HasValue && !entity.EndWorkDate.HasValue)
                        {
                            if (current.Id == 10)
                            {
                                model.IsNotEndWorkAvailable = true;
                            }
                            model.IsEndWorkAvailable = true;
                            model.IsConsultantOutsourcingEditable = true;
                            model.IsSaveAvailable = true;
                        }
                        if (entity.SendDate.HasValue && !entity.BeginWorkDate.HasValue)
                            model.IsBeginWorkAvailable = true;
                    }
                    //кнопка принятия в работу доступна пока не сформируется услуга не зависимо от того, кто ее принял в работу
                    if (entity.SendDate.HasValue && entity.BeginWorkDate.HasValue && !entity.EndWorkDate.HasValue)
                        model.IsBeginWorkAvailable = true;
                    break;*/ //DEPRECATED MAY BE PROBLEM
                case UserRole.Estimator:
                case UserRole.PersonnelManager:
                    if (entity.Consultant == null || (entity.Consultant.Id == current.Id))
                    {
                        if (entity.Consultant != null && entity.Consultant.Id == current.Id
                            && entity.BeginWorkDate.HasValue && !entity.EndWorkDate.HasValue)
                        {
                            model.IsEndWorkAvailable = true;
                            model.IsNotEndWorkAvailable = true;
                            model.IsConsultantOutsourcingEditable = true;
                            model.IsSaveAvailable = true;
                        }
                        if (entity.SendDate.HasValue && !entity.BeginWorkDate.HasValue)
                        {
                            model.IsBeginWorkAvailable = true;
                        }
                    }
                    //кнопка принятия в работу доступна пока не сформируется услуга не зависимо от того, кто ее принял в работу
                    if (entity.SendDate.HasValue && entity.BeginWorkDate.HasValue && !entity.EndWorkDate.HasValue)
                        model.IsBeginWorkAvailable = true;

                    //чтобы видно было кадровикам, но в работу не принималось и скан не выкачивался
                    List<int> EstimatorList = new List<int> { 2, 4, 5, 7, 8, 10, 11, 12, 16, 17, 20, 21, 26, 27 };
                    List<int> PersonnelList = new List<int> { 1, 3, 6, 8, 9, 12, 13, 14, 15, 16, 18, 19, 20, 22, 23, 24, 25, 28, 4, 2, 5, 7, 10, 11, 21, 26, 27 };
                    if (AuthenticationService.CurrentUser.Id != 10 && (CurrentUser.UserRole & UserRole.Estimator) == 0)
                    {
                        if (entity.Type.Id == 4 || entity.Type.Id == 2 || entity.Type.Id == 5 || entity.Type.Id == 10 || entity.Type.Id == 11 || entity.Type.Id == 21 || entity.Type.Id == 7 || entity.Type.Id == 26 || entity.Type.Id == 27)
                        {
                            model.IsNotScanView = entity.Type.Id == 26 || entity.Type.Id == 27 ? false : true;
                            model.IsBeginWorkAvailable = false;
                        }
                        else
                            model.IsNotScanView = false;
                    }
                    else
                    {
                        if (!EstimatorList.Contains(entity.Type.Id))
                        {
                            model.IsBeginWorkAvailable = false;
                            model.IsNotScanView = false;
                        }
                    }
                    //консультант составляет за сотрудника
                    if (entity.Creator.Id == current.Id)
                    {
                        if (!entity.SendDate.HasValue)
                        {
                            model.IsEditable = true;
                            model.IsSaveAvailable = true;
                            //if (model.AttachmentId > 0 || !model.IsAttachmentVisible)
                            model.IsSendAvailable = true;
                        }
                        if (entity.EndWorkDate.HasValue && !entity.ConfirmWorkDate.HasValue)
                            model.IsEndAvailable = true;
                    }
                    break;
            }
        }
Exemple #9
0
        protected void LoadDictionaries(HelpServiceRequestEditModel model)
        {
            model.CommentsModel = GetCommentsModel(model.Id, RequestTypeEnum.HelpServiceRequest);
            List<HelpServiceType> types = HelpServiceTypeDao.LoadAllSortedByOrder();
            //types = FilteServiceRequestTypes(types);
            model.Types = types.ConvertAll(x => new IdNameDto { Id = x.Id,Name = x.Name});
            model.ProductionTimeTypes = HelpServiceProductionTimeDao.LoadAllSortedByOrder().
                ConvertAll(x => new IdNameDto { Id = x.Id, Name = x.Name }).
                Where(x => x.Id != 1).ToList<IdNameDto>();//исключил одну строку
            if (model.Id == 0)
                model.ProductionTimeTypeId = 2;
            model.TransferMethodTypes = HelpServiceTransferMethodDao.LoadAllSortedByOrder().
               ConvertAll(x => new IdNameDto { Id = x.Id, Name = x.Name }).
               Where(x => x.Id != 3 && x.Id != 2).ToList<IdNameDto>(); //удалил из списка почту России и курьер-сервис

            if(model.TypeId == 0)
                model.TypeId = types.First().Id;
            HelpServiceType type = types.Where(x => x.Id == model.TypeId).First();
            SetDistionariesFlag(model,type);
        }
Exemple #10
0
        protected void ChangeEntityProperties(HelpServiceRequest entity,HelpServiceRequestEditModel model,
            UploadFileDto fileDto, User currUser,out string error)
        {
            error = string.Empty;
            UserRole currRole = AuthenticationService.CurrentUser.UserRole;
            if (model.IsEditable)
            {
                HelpServiceType type = HelpServiceTypeDao.Load(model.TypeId);
                if (model.Id != 0)
                {
                    if (fileDto != null && entity.Type.IsAttachmentAvailable && model.AttachmentId != 0)
                        RequestAttachmentDao.DeleteAndFlush(model.AttachmentId);
                }
                entity.Type = type;
                entity.IsForGEMoney = model.IsForGEMoney;
                entity.Note = noteTypeDao.Load(model.Note);
                entity.FiredUserName = model.FiredUserName;
                entity.FiredUserSurname = model.FiredUserSurname;
                entity.FiredUserPatronymic = model.FiredUserPatronymic;
                if (model.DepartmentId > 0)
                {
                    var dep = DepartmentDao.Load(model.DepartmentId);
                    entity.FiredUserDepartment = dep;
                }
                if(model.UserBirthDate!=null) entity.UserBirthDate = DateTime.Parse(model.UserBirthDate);
                entity.ProductionTime = HelpServiceProductionTimeDao.Load(model.ProductionTimeTypeId);
                entity.TransferMethod = helpServiceTransferMethodDao.Load(model.TransferMethodTypeId);
                entity.Requirements = type.IsRequirementsAvailable ? model.Requirements : null;
                entity.Period = type.IsPeriodAvailable
                                    ? model.PeriodId.HasValue ? helpServicePeriodDao.Load(model.PeriodId.Value) : null
                                    : null;
                entity.Address = model.Address;
                if(fileDto != null && entity.Type.IsAttachmentAvailable && entity.Id != 0)
                {
                    RequestAttachment attachment = new RequestAttachment
                                                       {
                                                           UncompressContext = fileDto.Context,
                                                           ContextType = fileDto.ContextType,
                                                           CreatorRole = RoleDao.Load((int)currRole),
                                                           DateCreated = DateTime.Now,
                                                           FileName = fileDto.FileName,
                                                           RequestId = entity.Id,
                                                           RequestType = (int)RequestAttachmentTypeEnum.HelpServiceRequestTemplate,
                                                       };
                    RequestAttachmentDao.SaveAndFlush(attachment);
                    model.AttachmentId = attachment.Id;
                    model.Attachment = attachment.FileName;
                }
                if (!entity.Type.IsAttachmentAvailable && model.AttachmentId != 0)
                    RequestAttachmentDao.DeleteAndFlush(model.AttachmentId);
            }
            if (model.IsConsultantOutsourcingEditable)
            {
                if (fileDto != null && model.ServiceAttachmentId != 0)
                    RequestAttachmentDao.DeleteAndFlush(model.ServiceAttachmentId);
                if (fileDto != null)
                {
                    RequestAttachment attachment = new RequestAttachment
                    {
                        UncompressContext = fileDto.Context,
                        ContextType = fileDto.ContextType,
                        CreatorRole = RoleDao.Load((int)currRole),
                        DateCreated = DateTime.Now,
                        FileName = fileDto.FileName,
                        RequestId = entity.Id,
                        RequestType = (int)RequestAttachmentTypeEnum.HelpServiceRequest,
                        DocumentsCount =  model.DocumentsCount>0?model.DocumentsCount:1
                    };
                    RequestAttachmentDao.SaveAndFlush(attachment);
                    model.ServiceAttachmentId = attachment.Id;
                    model.ServiceAttachment = attachment.FileName;
                }
            }
            switch (currRole)
            {
                case UserRole.ConsultantPersonnel:
                case UserRole.Employee:
                    if (entity.Creator.Id == currUser.Id)
                    {
                        if (model.Operation == 1 && !entity.SendDate.HasValue)
                            entity.SendDate = DateTime.Now;
                        if(entity.EndWorkDate.HasValue)
                        {
                            if(model.Operation == 4)
                                entity.ConfirmWorkDate = DateTime.Now;
                            else if(model.Operation == 5)
                            {
                                entity.SendDate = null;
                                entity.BeginWorkDate = null;
                                entity.EndWorkDate = null;
                            }
                        }
                    }
                    break;
                case UserRole.DismissedEmployee:
                    if (entity.Creator.Id == currUser.Id)
                    {
                        if (model.Operation == 1 && !entity.SendDate.HasValue)
                            entity.SendDate = DateTime.Now;
                        if (entity.EndWorkDate.HasValue)
                        {
                            if (model.Operation == 4)
                                entity.ConfirmWorkDate = DateTime.Now;
                            else if (model.Operation == 5)
                            {
                                entity.SendDate = null;
                                entity.BeginWorkDate = null;
                                entity.EndWorkDate = null;
                            }
                        }
                    }
                    break;
                case UserRole.Manager:
                    if (entity.Creator.Id == currUser.Id)
                    {
                        if (model.Operation == 1 && !entity.SendDate.HasValue)
                            entity.SendDate = DateTime.Now;
                        if (entity.EndWorkDate.HasValue)
                        {
                            if (model.Operation == 4)
                                entity.ConfirmWorkDate = DateTime.Now;
                            else if (model.Operation == 5)
                            {
                                entity.SendDate = null;
                                entity.BeginWorkDate = null;
                                entity.EndWorkDate = null;
                            }
                        }
                    }
                    break;
                case UserRole.ConsultantOutsourcing:
                    if (entity.Consultant == null || (entity.Consultant.Id == currUser.Id))
                    {
                        if (model.Operation == 2 && entity.SendDate.HasValue)
                        {
                            entity.BeginWorkDate = DateTime.Now;
                            entity.Consultant = currUser;
                        }
                        if (entity.Consultant != null && entity.Consultant.Id == currUser.Id
                            && model.Operation == 3 && entity.BeginWorkDate.HasValue)
                        {
                            entity.EndWorkDate = DateTime.Now;
                            entity.ConfirmWorkDate = DateTime.Now;
                        }
                        if (entity.Consultant != null && entity.Consultant.Id == currUser.Id
                            && model.Operation == 6 && entity.BeginWorkDate.HasValue)
                        {
                            entity.EndWorkDate = DateTime.Now;
                            entity.NotEndWorkDate = DateTime.Now;
                        }
                    }
                    //кнопка принятия в работу доступна пока не сформируется услуга не зависимо от того, кто ее принял в работу
                    if (model.Operation == 2 && entity.SendDate.HasValue && !entity.NotEndWorkDate.HasValue)
                    {
                        entity.BeginWorkDate = DateTime.Now;
                        entity.Consultant = currUser;
                    }
                    break;
                case UserRole.PersonnelManager:
                    if (entity.Consultant == null || (entity.Consultant.Id == currUser.Id))
                    {
                        if (model.Operation == 2 && entity.SendDate.HasValue)
                        {
                            entity.BeginWorkDate = DateTime.Now;
                            entity.Consultant = currUser;
                        }
                        if (entity.Consultant != null && entity.Consultant.Id == currUser.Id
                            && model.Operation == 3 && entity.BeginWorkDate.HasValue)
                        {
                            entity.EndWorkDate = DateTime.Now;
                            entity.ConfirmWorkDate = DateTime.Now;
                        }
                        if (entity.Consultant != null && entity.Consultant.Id == currUser.Id
                            && model.Operation == 6 && entity.BeginWorkDate.HasValue)
                        {
                            entity.EndWorkDate = DateTime.Now;
                            entity.NotEndWorkDate = DateTime.Now;
                        }
                    }
                    //кнопка принятия в работу доступна пока не сформируется услуга не зависимо от того, кто ее принял в работу
                    if (model.Operation == 2 && entity.SendDate.HasValue && !entity.NotEndWorkDate.HasValue)
                    {
                        entity.BeginWorkDate = DateTime.Now;
                        entity.Consultant = currUser;
                    }

                    //если консультант создает заявку за сотрудника
                    if (entity.Creator.Id == currUser.Id && model.Operation == 1 && !entity.SendDate.HasValue)
                        entity.SendDate = DateTime.Now;
                    break;
                /*case UserRole.PersonnelManager: //DEPRECATED MAY BE PROBLEM
                    if (entity.Consultant == null || (entity.Consultant.Id == currUser.Id))
                    {
                        if (model.Operation == 2 && entity.SendDate.HasValue)
                        {
                            entity.BeginWorkDate = DateTime.Now;
                            entity.Consultant = currUser;
                        }
                        if (entity.Consultant != null && entity.Consultant.Id == currUser.Id
                            && model.Operation == 3 && entity.BeginWorkDate.HasValue)
                        {
                            entity.EndWorkDate = DateTime.Now;
                            entity.ConfirmWorkDate = DateTime.Now;
                        }
                        if (entity.Consultant != null && entity.Consultant.Id == currUser.Id
                            && model.Operation == 6 && entity.BeginWorkDate.HasValue && currUser.Id == 10)
                        {
                            entity.EndWorkDate = DateTime.Now;
                            entity.NotEndWorkDate = DateTime.Now;
                        }
                    }
                    //кнопка принятия в работу доступна пока не сформируется услуга не зависимо от того, кто ее принял в работу
                    if (model.Operation == 2 && entity.SendDate.HasValue && !entity.NotEndWorkDate.HasValue)
                    {
                        entity.BeginWorkDate = DateTime.Now;
                        entity.Consultant = currUser;
                    }
                    break;*/
            }
        }
Exemple #11
0
        public bool SaveServiceRequestEditModel(HelpServiceRequestEditModel model, UploadFileDto fileDto, out string error)
        {
            error = string.Empty;
            User currUser = null;
            User user = null;
            HelpServiceRequest entity = null;
            try
            {

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

                if (model.Id == 0)
                {
                    entity = new HelpServiceRequest
                    {
                        CreateDate = DateTime.Now,
                        Creator = currUser,//UserDao.Load(current.Id),
                        Number = RequestNextNumberDao.GetNextNumberForType((int)RequestTypeEnum.HelpServiceRequest),
                        EditDate = DateTime.Now,
                        User = user,
                        FiredUserName=model.FiredUserName,
                        FiredUserSurname=model.FiredUserSurname,
                        FiredUserPatronymic=model.FiredUserPatronymic,
                        Note=noteTypeDao.Load(model.Note),
                        IsForGEMoney=model.IsForGEMoney
                    };
                    if (model.UserBirthDate != null) entity.UserBirthDate = DateTime.Parse(model.UserBirthDate);

                    ChangeEntityProperties(entity, model,fileDto,currUser,out error);
                    HelpServiceRequestDao.SaveAndFlush(entity);
                    model.Id = entity.Id;
                    model.DocumentNumber = entity.Number.ToString();
                    model.DateCreated = entity.CreateDate.ToShortDateString();
                    model.Creator = entity.Creator.FullName;
                    if (fileDto != null && entity.Type.IsAttachmentAvailable)
                        ChangeEntityProperties(entity, model, fileDto, currUser, out error);//если создается черновик, то цепляем файл образца
                }
                else
                {
                    entity = HelpServiceRequestDao.Get(model.Id);
                    if (entity == null)
                        throw new ValidationException(string.Format(StrServiceRequestNotFound, model.Id));
                    if (entity.Version != model.Version)
                    {
                        error = StrServiceRequestWasChanged;
                        model.ReloadPage = true;
                        return false;
                    }
                    ChangeEntityProperties(entity, model, fileDto, currUser, out error);
                    HelpServiceRequestDao.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;
                        HelpServiceRequestDao.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;

                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);
                SetHiddenFields(model);
            }
        }