public RequestAttachmentsModel GetHelpPersonnelBillingAttachmentsModel(HelpPersonnelBillingRequest entity, RequestAttachmentTypeEnum typeId) { if(entity.Id == 0) { return new RequestAttachmentsModel { AttachmentRequestId = 0, AttachmentRequestTypeId = (int) typeId, Attachments = new List<RequestAttachmentModel>(), IsAddAvailable = false }; } //открыто для создающего и отвечающих, кроме просмотровой роли bool isAddAvailable = (!entity.SendDate.HasValue && (entity.Creator.Id == CurrentUser.Id)) || ((entity.BeginWorkDate.HasValue && !entity.EndWorkDate.HasValue && (AuthenticationService.CurrentUser.UserRole != UserRole.OutsourcingManager) && (AuthenticationService.CurrentUser.UserRole != UserRole.Estimator))); List<RequestAttachment> list = RequestAttachmentDao.FindManyByRequestIdAndTypeId(entity.Id, typeId).ToList(); RequestAttachmentsModel model = new RequestAttachmentsModel { AttachmentRequestId = entity.Id, AttachmentRequestTypeId = (int)typeId, IsAddAvailable = isAddAvailable, Attachments = new List<RequestAttachmentModel>() }; model.Attachments = list.ConvertAll(x => new RequestAttachmentModel { Attachment = x.FileName, AttachmentId = x.Id, Description = x.Description, IsDeleteAvailable = ((x.CreatorUserRole & CurrentUser.UserRole) > 0 || AuthenticationService.CurrentUser.UserRole == UserRole.ConsultantOutsourcing) && isAddAvailable, }); return model; }
public EditPersonnelBillingRequestViewModel GetPersonnelBillingRequestEditModel(int id) { IUser current = AuthenticationService.CurrentUser; int userId = 0; HelpPersonnelBillingRequest entity = null; if (id == 0) { if (CurrentUser.UserRole != UserRole.OutsourcingManager || CurrentUser.UserRole == UserRole.Estimator || ((CurrentUser.UserRole & UserRole.PersonnelManager) > 0 && CurrentUser.Id == 10)) userId = current.Id; else throw new ValidationException(StrCannotCreatePersonnelBilling); } else entity = HelpPersonnelBillingRequestDao.Load(id); EditPersonnelBillingRequestViewModel model = new EditPersonnelBillingRequestViewModel { Id = id, UserId = id == 0 ? userId : entity.Creator.Id, }; //User user = UserDao.Load(model.UserId); User currUser = UserDao.Load(current.Id); if (id == 0) { entity = new HelpPersonnelBillingRequest { Creator = currUser, CreateDate = DateTime.Now, EditDate = DateTime.Now, CreatorRoleId = (int)current.UserRole }; } else { model.Answer = entity.Answer; model.DepartmentId = entity.Department == null ? 0 : entity.Department.Id; model.DepartmentName = entity.Department == null ? string.Empty : entity.Department.Name; model.Question = entity.Question; model.TitleId = entity.Title.Id; model.UrgencyId = entity.Urgency.Id; model.UserName = entity.UserName; model.Version = entity.Version; model.UserId = entity.Creator.Id; model.Version = entity.Version; } SetBillingRequestInfoModel(entity, model); model.AttachmentsModel = GetHelpPersonnelBillingAttachmentsModel(entity, RequestAttachmentTypeEnum.HelpPersonnelBillingRequest); LoadDictionaries(model); SetFlagsState(id, currUser, entity, model); SetHiddenFields(model); return model; }
protected void SetFlagsState(int id, User current, HelpPersonnelBillingRequest entity, EditPersonnelBillingRequestViewModel model) { UserRole currentRole = AuthenticationService.CurrentUser.UserRole; SetFlagsState(model, false); if (model.Id == 0) { model.IsEditable = true; model.IsSaveAvailable = true; model.IsSendAvailable = true; return; } if (AuthenticationService.CurrentUser.Id == 10 || AuthenticationService.CurrentUser.UserRole == UserRole.ConsultantOutsourcing || AuthenticationService.CurrentUser.UserRole == UserRole.PersonnelManager || AuthenticationService.CurrentUser.UserRole == UserRole.Estimator|| AuthenticationService.CurrentUser.UserRole == UserRole.ConsultantPersonnel || AuthenticationService.CurrentUser.UserRole == UserRole.Accountant || AuthenticationService.CurrentUser.UserRole == UserRole.TaxCollector || AuthenticationService.CurrentUser.UserRole == UserRole.Estimator ) { if (entity.Creator.Id == current.Id) { if (!entity.EndWorkDate.HasValue) { model.IsEditable = true; model.IsSaveAvailable = entity.SendDate.HasValue ? false : true; model.IsSendAvailable = true; } } else { //кому доступно сообщение в реестре могут отвечать //консультант может закрыть тему созданную другими if (entity.SendDate.HasValue && !entity.BeginWorkDate.HasValue) { model.IsWorkBeginAvailable = true; //model.IsSaveAvailable = true; model.IsAnswerEditable = true; } if (entity.BeginWorkDate.HasValue && !entity.EndWorkDate.HasValue) { model.IsSendAvailable = AuthenticationService.CurrentUser.UserRole == UserRole.ConsultantOutsourcing ? true : false; //консультант может закрыть тему созданную другими model.IsAnswerEditable = true; } } } //SetRecepientsDictionary(entity,model); }
protected void SetBillingRequestInfoModel(HelpPersonnelBillingRequest entity, BillingRequestInfoViewModel model) { model.CreatorName = entity.Creator.FullName; model.DateBeginWork = FormatDate(entity.BeginWorkDate); model.DateCreated = FormatDate(entity.CreateDate); model.DateEndWork = FormatDate(entity.EndWorkDate); model.DateSended = FormatDate(entity.SendDate); model.Department3Name = string.Empty; if(entity.Department != null) { Department dep3 = DepartmentDao.GetParentDepartmentWithLevel(entity.Department, 3); if (dep3 != null) model.Department3Name = dep3.Name; } model.DocumentNumber = entity.Id == 0 ? string.Empty : entity.Number.ToString(); }
/// <summary> /// Сохраняем список ответственных за задачу. /// </summary> /// <param name="entity">Заявка</param> /// <param name="model">Модель заявки.</param> /// <param name="currUser">Текущий пользователь.</param> /// <returns></returns> protected void SaveExecutorTaskList(HelpPersonnelBillingRequest entity, EditPersonnelBillingRequestViewModel model) { foreach (var item in model.RecipientList) { if (entity.Executors == null || (item.IsRecipient && entity.Executors.Where(x => x.Worker.Id == item.UserId).Count() == 0))//вновь добавляемый { entity.Executors.Add(new HelpBillingExecutorTasks { Worker = UserDao.Load(item.UserId), CreatedDate = DateTime.Now }); } else//существующий { //если птица снята, то удаляем if (!item.IsRecipient && entity.Executors.Where(x => x.Worker.Id == item.UserId).Count() != 0) { foreach (var w in entity.Executors) { if (w.Worker.Id == item.UserId) { entity.Executors.Remove(w); break; } } } } } }
protected void ChangeEntityProperties(HelpPersonnelBillingRequest entity, EditPersonnelBillingRequestViewModel model, User currUser, out string error) { error = string.Empty; UserRole currRole = AuthenticationService.CurrentUser.UserRole; if (model.IsEditable) { entity.Department = model.DepartmentId != 0 ? DepartmentDao.Load(model.DepartmentId) : null; entity.Question = model.Question; entity.Title = HelpBillingTitleDao.Load(model.TitleId); entity.Urgency = HelpBillingUrgencyDao.Load(model.UrgencyId); entity.UserName = model.UserName; //сохраняем список ответственных за выполнение поставленной партией задачи if (!entity.SendDate.HasValue && model.RecipientList != null) { SaveExecutorTaskList(entity, model); } } if (model.IsAnswerEditable) entity.Answer = model.Answer; if (AuthenticationService.CurrentUser.Id == 10 || AuthenticationService.CurrentUser.UserRole == UserRole.ConsultantOutsourcing || AuthenticationService.CurrentUser.UserRole == UserRole.PersonnelManager || AuthenticationService.CurrentUser.UserRole == UserRole.Estimator|| AuthenticationService.CurrentUser.UserRole == UserRole.ConsultantPersonnel || AuthenticationService.CurrentUser.UserRole == UserRole.Accountant || AuthenticationService.CurrentUser.UserRole == UserRole.TaxCollector ) { if (entity.Creator.Id == currUser.Id) { if (!entity.SendDate.HasValue && model.Operation == 1) // send { entity.SendDate = DateTime.Now; } if (model.Operation == 3) { entity.EndWorkDate = DateTime.Now; entity.BeginWorkDate = entity.BeginWorkDate.HasValue ? entity.BeginWorkDate.Value : DateTime.Now; } } else { //кому направлена тема if (AuthenticationService.CurrentUser.UserRole != UserRole.OutsourcingManager && AuthenticationService.CurrentUser.UserRole != UserRole.Estimator) { if (entity.SendDate.HasValue && !entity.BeginWorkDate.HasValue && entity.Creator.Id != AuthenticationService.CurrentUser.Id) { entity.BeginWorkDate = DateTime.Now; } //консультант может закрыть тему созданную другими if (AuthenticationService.CurrentUser.UserRole == UserRole.ConsultantOutsourcing) { if (model.Operation == 3) { entity.EndWorkDate = DateTime.Now; entity.BeginWorkDate = entity.BeginWorkDate.HasValue ? entity.BeginWorkDate.Value : DateTime.Now; } } } } } }
public bool SavePersonnelBillingRequestModel(EditPersonnelBillingRequestViewModel model, out string error) { error = string.Empty; //User user = null; HelpPersonnelBillingRequest entity; try { IUser current = AuthenticationService.CurrentUser; User currUser = UserDao.Load(current.Id); //user = UserDao.Load(model.UserId); if (model.Id == 0) { entity = new HelpPersonnelBillingRequest { CreateDate = DateTime.Now, Creator = currUser, Number = RequestNextNumberDao.GetNextNumberForType((int)RequestTypeEnum.HelpPersonnelBillingRequest), EditDate = DateTime.Now, CreatorRoleId = (int)current.UserRole }; ChangeEntityProperties(entity, model, currUser, out error); HelpPersonnelBillingRequestDao.SaveAndFlush(entity); model.Id = entity.Id; } else { entity = HelpPersonnelBillingRequestDao.Get(model.Id); if (entity == null) throw new ValidationException(string.Format(StrPersonnalBillingRequestNotFound, model.Id)); if (entity.Version != model.Version) { error = StrServiceRequestWasChanged; model.ReloadPage = true; return false; } if (entity.EndWorkDate.HasValue) { error = "Данная тема закрыта автором!"; return false; } ChangeEntityProperties(entity, model, currUser, out error); HelpPersonnelBillingRequestDao.SaveAndFlush(entity); if (entity.Version != model.Version) { entity.EditDate = DateTime.Now; HelpPersonnelBillingRequestDao.SaveAndFlush(entity); } } //переписка if (model.Operation != 0 && !entity.EndWorkDate.HasValue) { SaveComments(model.Id, model.IsSendAvailable, model.IsSendAvailable ? model.Question : model.Answer, out error); if (!string.IsNullOrEmpty(error)) throw new ValidationException(error); } model.Version = entity.Version; SetFlagsState(entity.Id, currUser, entity, model); SetBillingRequestInfoModel(entity, model); LoadDictionaries(model); model.AttachmentsModel = GetHelpPersonnelBillingAttachmentsModel(entity, RequestAttachmentTypeEnum.HelpPersonnelBillingRequest); return true; } catch (Exception ex) { HelpServiceRequestDao.RollbackTran(); Log.Error("Error on SavePersonnelBillingRequestModel:", ex); error = StrException + ex.GetBaseException().Message; return false; } finally { //SetUserInfoModel(user, model); LoadDictionaries(model); SetHiddenFields(model); } }