protected bool ValidateAppointmentReportEditModel(AppointmentReportEditModel model,UploadFileDto fileDto) { if (model.IsDelete) return true; if (!string.IsNullOrEmpty(model.ColloquyDate)) { DateTime colloquyDate; if (!DateTime.TryParse(model.ColloquyDate, out colloquyDate)) ModelState.AddModelError("ColloquyDate", StrInvalidColloquyDate); } if (!string.IsNullOrEmpty(model.DateAccept)) { DateTime dateAccept; if (!DateTime.TryParse(model.DateAccept, out dateAccept)) ModelState.AddModelError("DateAccept", StrInvalidDateAccept); } return ModelState.IsValid; }
protected void CorrectCheckboxes(AppointmentReportEditModel model) { if (!model.IsStaffApproveAvailable) { if (ModelState.ContainsKey("IsStaffApproved")) ModelState.Remove("IsStaffApproved"); model.IsStaffApproved = model.IsStaffApprovedHidden; } if (!model.IsManagerApproveAvailable) { if (ModelState.ContainsKey("IsManagerApproved")) ModelState.Remove("IsManagerApproved"); model.IsManagerApproved = model.IsManagerApprovedHidden; } }
protected void CorrectDropdowns(AppointmentReportEditModel model) { if (!model.IsEditable) { model.TypeId = model.TypeIdHidden; } if (!model.IsManagerEditable) { if(!model.IsStaffSetDateAcceptAvailable && !model.IsTrainerCanSave) model.IsEducationExists = model.IsEducationExistsHidden; model.IsColloquyPassed = model.IsColloquyPassedHidden; } }
public bool SaveAppointmentReportEditModel(AppointmentReportEditModel model, UploadFileDto fileDto,out string error) { error = string.Empty; User creator = null; AppointmentReport entity = null; try { IUser current = AuthenticationService.CurrentUser; entity = AppointmentReportDao.Get(model.Id); if (entity == null) throw new ValidationException(string.Format(StrAppointmentReportNotFound, model.Id)); creator = UserDao.Load(entity.Appointment.Creator.Id); if (entity.Version != model.Version) { error = StrMultipleAccessError; model.ReloadPage = true; return false; } if (entity.DeleteDate.HasValue) { error = StrReportWasRejected; model.ReloadPage = true; return false; } if (entity.Appointment.DeleteDate.HasValue) { error = StrAppointmentWasRejected; model.ReloadPage = true; return false; } string fileName; int? attachmentId = SaveAttachment(entity.Id, model.AttachmentId, fileDto, RequestAttachmentTypeEnum.AppointmentReport, out fileName); if (attachmentId.HasValue) { model.AttachmentId = attachmentId.Value; model.Attachment = fileName; } if (model.IsDelete) { switch (current.UserRole) { case UserRole.StaffManager: if (!entity.DeleteDate.HasValue && !entity.ManagerDateAccept.HasValue && entity.Appointment.AcceptStaff.Id == current.Id) { entity.DeleteDate = DateTime.Now; entity.DeleteUser = entity.Appointment.AcceptStaff; } break; case UserRole.Manager: if (!entity.DeleteDate.HasValue && entity.StaffDateAccept.HasValue && entity.Appointment.Creator.Id == current.Id && !entity.DateAccept.HasValue) { entity.DeleteDate = DateTime.Now; entity.DeleteUser = entity.Appointment.Creator; entity.RejectReason = model.RejectReason; } break; case UserRole.Trainer: break; default: throw new ArgumentException(string.Format("Недопустимая роль {0}", current.UserRole)); } } else { ChangeEntityProperties(current, entity, model, creator, out error); AppointmentReportDao.SaveAndFlush(entity); if (entity.Version != model.Version) { entity.EditDate = DateTime.Now; AppointmentReportDao.SaveAndFlush(entity); } } if (entity.DeleteDate.HasValue) model.IsDeleted = true; model.DocumentNumber = entity.Number.ToString(); model.Version = entity.Version; model.DateCreated = entity.CreateDate.ToShortDateString(); model.IsEducationExists = entity.IsEducationExists.HasValue ? (entity.IsEducationExists.Value ? 1 : 0) : -1; model.IsColloquyPassed = entity.IsColloquyPassed.HasValue?(entity.IsColloquyPassed.Value?1:0):-1; SetFlagsState(entity.Id, UserDao.Load(current.Id), current.UserRole, entity, model); //Задолбала Улькина model.ReloadPage = true; return true; } catch (Exception ex) { AppointmentDao.RollbackTran(); Log.Error("Error on SaveAppointmentReportEditModel:", ex); error = StrException + ex.GetBaseException().Message; return false; } finally { SetManagerInfoModel(creator, model,null,entity); LoadDictionaries(model); SetHiddenFields(model,entity); } }
public ActionResult AppointmentReportEdit(AppointmentReportEditModel model) { CorrectCheckboxes(model); CorrectDropdowns(model); UploadFileDto fileDto = GetFileContext(Request,ModelState); if (!ValidateAppointmentReportEditModel(model, fileDto)) { model.IsDelete = false; AppointmentBl.ReloadDictionariesToModel(model); return View(model); } string error; if (!AppointmentBl.SaveAppointmentReportEditModel(model, fileDto, out error)) { if (model.ReloadPage) { ModelState.Clear(); if (!string.IsNullOrEmpty(error)) ModelState.AddModelError("", error); return View(AppointmentBl.GetAppointmentReportEditModel(model.Id)); } if (!string.IsNullOrEmpty(error)) ModelState.AddModelError("", error); } else { model = AppointmentBl.GetAppointmentReportEditModel(model.Id); } return View(model); }
public AppointmentReportEditModel GetAppointmentReportEditModel(int id) { AppointmentReportEditModel model = new AppointmentReportEditModel { Id = id }; //User creator; model.Personnels = EmploymentCandidateDao.GetPersonnels(); IUser current = AuthenticationService.CurrentUser; User currUser = UserDao.Load(current.Id); if(id == 0) throw new ValidationException(StrAppointmentReportIncorrectId); AppointmentReport entity = AppointmentReportDao.Get(id); if (entity == null) throw new ValidationException(string.Format(StrAppointmentReportNotFound, id)); if (entity.Candidates != null && entity.Candidates.Any()) { model.Candidates = entity.Candidates.Select(x => new Reports.Core.Dto.Employment2.CandidateDto { Id = x.Id, Name = x.User.Name, EmploymentDate = (x.PersonnelManagers!=null)?x.PersonnelManagers.CompleteDate:null, Status=x.SendTo1C.HasValue?"Выгружено в 1С":"Не выгружено в 1С" }).ToList(); var candidates = entity.Appointment.Candidates.Where(x => x.Status != Reports.Core.Enum.EmploymentStatus.REJECTED); if (candidates.Count() >= entity.Appointment.BankAccountantAcceptCount) model.IsClosed = true; } if (entity.Appointment.Recruter == 2) { model.ShowStaff = false; model.IsColloquyPassed = 1; } else model.ShowStaff = true; model.TestingResult = entity.TestingResult; model.AppId = entity.Appointment.Id; model.Version = entity.Version; model.DateCreated = FormatDate(entity.CreateDate); model.TypeId = entity.Type.Id; model.IsEducationExists = !entity.IsEducationExists.HasValue ? -1 : (entity.IsEducationExists.Value ? 1 : 0); model.IsColloquyPassed = !entity.IsColloquyPassed.HasValue ? -1 : (entity.IsColloquyPassed.Value ? 1 : 0); model.UserId = entity.Appointment.Creator.Id; model.Name = entity.Name; model.DocumentNumber = entity.Appointment.Number+"/"+entity.SecondNumber; model.Phone = entity.Phone; model.Email = entity.Email; model.ColloquyDate = FormatDate(entity.ColloquyDate); model.EducationTime = entity.EducationTime; model.RejectReason = entity.RejectReason; model.DateAccept = FormatDate(entity.DateAccept); model.ResumeComment = entity.ResumeComment; model.ResumeCommentByOPINP = entity.ResumeCommentByOPINP; model.LessonDate = entity.LessonDate.HasValue ? entity.LessonDate.Value.ToShortDateString() : ""; SetManagerInfoModel(entity.Appointment.Creator, model,null,entity); SetAttachmentToModel(model, id, RequestAttachmentTypeEnum.AppointmentReport); LoadDictionaries(model); SetFlagsState(id, currUser, current.UserRole, entity, model); SetHiddenFields(model,entity); return model; }
public void ReloadDictionariesToModel(AppointmentReportEditModel model) { User user = UserDao.Load(model.UserId); LoadDictionaries(model); AppointmentReport entity = AppointmentReportDao.Load(model.Id); SetManagerInfoModel(user, model,null,entity); model.DocumentNumber = entity.Number.ToString(); model.DateCreated = entity.CreateDate.ToShortDateString(); if (entity.DeleteDate.HasValue) model.IsDeleted = true; }
protected void SetHiddenFields(AppointmentReportEditModel model, AppointmentReport entity) { if (entity != null) { model.DepartmentName = entity.Appointment.Department.Name; model.DepartmentId = entity.Appointment.Department.Id; model.ManagerId = entity.Appointment.Creator.Id; model.City = entity.Appointment.City; model.CandidatePosition = entity.Appointment.PositionName; model.VacationCount = entity.Appointment.BankAccountantAcceptCount.ToString(); model.Reason = entity.Appointment.Reason.Name; model.AppointmentNumber = entity.Appointment.Number.ToString(); } model.TypeIdHidden = model.TypeId; model.IsEducationExistsHidden = model.IsEducationExists; model.IsColloquyPassedHidden = model.IsColloquyPassed; model.IsManagerApprovedHidden = model.IsManagerApproved; model.IsStaffApprovedHidden = model.IsStaffApproved; //model.DateCreatedHidden = model.DateCreated; }
protected void SetFlagsState(int id, User current, UserRole currRole, AppointmentReport entity, AppointmentReportEditModel model) { SetFlagsState(model, false); model.AppId = entity.Appointment.Id; if (entity.CandidateRejectDate.HasValue) { model.CandidateRejectDate = entity.CandidateRejectDate; model.CandidateRejectedBy = entity.CandidateRejectedBy != null ? entity.CandidateRejectedBy.Name : ""; } model.IsManagerApproved = entity.ManagerDateAccept.HasValue; model.IsBankAccountantAccept = entity.Appointment.BankAccountantAccept.HasValue && entity.Appointment.BankAccountantAccept.HasValue && entity.Appointment.BankAccountantAcceptCount > 0; model.IsStaffApproved = entity.StaffDateAccept.HasValue; model.IsDeleted = entity.DeleteDate.HasValue; if (entity.AcceptManager != null && entity.ManagerDateAccept.HasValue) model.ManagerFio = entity.AcceptManager.FullName; if (entity.AcceptStaff != null && entity.StaffDateAccept.HasValue) model.StaffFio = entity.AcceptStaff.FullName; if (entity.DeleteDate.HasValue) model.DeleteUser = entity.DeleteUser.FullName; model.ShowStaff = entity.Appointment.Recruter == 1; switch (currRole) { case UserRole.Manager: if (current.Id == entity.Appointment.Creator.Id && !entity.DeleteDate.HasValue) { if (!entity.StaffDateAccept.HasValue) { model.IsStaffApproveAvailable = true; } model.IsEditable = true; if (entity.AcceptManager != null && !string.IsNullOrEmpty(entity.TempLogin)) model.IsPrintLoginAvailable = true; if (!entity.DateAccept.HasValue) { if (entity.StaffDateAccept.HasValue) { model.IsManagerRejectAvailable = true; if (!entity.ManagerDateAccept.HasValue) { model.IsManagerApproveAvailable = true; model.IsColloquyDateEditable = true; } else { model.IsManagerEditable = true; if (!string.IsNullOrEmpty(entity.TempLogin)) model.IsPrintLoginAvailable = true; } } } } break; case UserRole.StaffManager: if (!entity.DeleteDate.HasValue /*&& (current.Id == entity.Appointment.AcceptStaff.Id || (entity.Appointment.Recruters!=null?entity.Appointment.Recruters.Any(x=>x.Id==current.Id):false))*/) { if (entity.AcceptManager != null && entity.AcceptManager.Id == current.Id && !string.IsNullOrEmpty(entity.TempLogin)) model.IsPrintLoginAvailable = true; if (!entity.DateAccept.HasValue) { if (!entity.StaffDateAccept.HasValue) { model.IsStaffApproveAvailable = true; model.IsEditable = true; if (model.AttachmentId > 0) { model.IsDeleteScanAvailable = true; model.IsManagerApproveAvailable = true; model.IsColloquyDateEditable = true; model.IsManagerEditable = false; } } else if (!entity.ManagerDateAccept.HasValue) { model.IsManagerRejectAvailable = true; model.IsManagerApproveAvailable = true; model.IsColloquyDateEditable = true; model.IsManagerEditable = false; } else if (entity.AcceptManager.Id == current.Id) { model.IsManagerRejectAvailable = true; model.IsManagerEditable = false; } /*if (!entity.StaffDateAccept.HasValue) { model.IsEditable = true; if (model.AttachmentId > 0) { model.IsStaffApproveAvailable = true; model.IsDeleteScanAvailable = true; model.IsManagerApproveAvailable = true; model.IsColloquyDateEditable = true; } } else { model.IsManagerRejectAvailable = true; if (!entity.ManagerDateAccept.HasValue) { model.IsManagerApproveAvailable = true; model.IsColloquyDateEditable = true; } else { model.IsManagerEditable = true; if (!string.IsNullOrEmpty(entity.TempLogin)) model.IsPrintLoginAvailable = true; } }*/ if (entity.ManagerDateAccept.HasValue && model.IsColloquyPassed == 1) model.IsStaffSetDateAcceptAvailable = true; model.IsAddAvailable = true; /*if (model.AttachmentId > 0) model.ApproveForAllAvailable = true;*/ } } break; case UserRole.Trainer: model.IsTrainerCanSave = model.IsColloquyPassed == 1; break; case UserRole.ConsultantPersonnel: case UserRole.PersonnelManager: case UserRole.Estimator: case UserRole.OutsourcingManager: case UserRole.Security: break; default: throw new ArgumentException(string.Format("Недопустимая роль {0}", currRole)); } model.IsSaveAvailable = model.IsEditable || model.IsManagerEditable || model.IsManagerApproveAvailable || model.IsStaffApproveAvailable || model.IsStaffSetDateAcceptAvailable | model.IsTrainerCanSave; }
protected void SetFlagsState(AppointmentReportEditModel model, bool state) { model.IsEditable = state; model.IsSaveAvailable = state; model.IsManagerApproveAvailable = state; model.IsManagerRejectAvailable = state; model.IsStaffApproveAvailable = state; model.IsDeleteScanAvailable = state; model.IsManagerEditable = state; model.IsAddAvailable = state; model.IsPrintLoginAvailable = state; model.IsColloquyDateEditable = state; model.IsStaffSetDateAcceptAvailable = state; //model.ApproveForAllAvailable = state; }
protected void LoadDictionaries(AppointmentReportEditModel model) { model.Personnels = EmploymentCandidateDao.GetPersonnels(); model.CommentsModel = GetCommentsModel(model.Id, RequestTypeEnum.AppointmentReport); model.IsEducationExistsValues = new List<IdNameDto> { new IdNameDto {Id = -1,Name = string.Empty}, new IdNameDto {Id = 0,Name = "Нет"}, new IdNameDto {Id = 1,Name = "Да"}, }.OrderBy(x => x.Name).ToList(); model.TestingResults = new List<IdNameDto> { new IdNameDto {Id=0, Name="-"}, new IdNameDto {Id=1, Name="Тест не пройден(отклонение)"}, new IdNameDto {Id=2, Name="худший(отклонение)"}, new IdNameDto {Id=3, Name="ниже среднего"}, new IdNameDto {Id=4, Name="средний"}, new IdNameDto {Id=5, Name="выше среднего"}, new IdNameDto {Id=6, Name="лучший"} }; model.IsColloquyPassedValues = new List<IdNameDto> { new IdNameDto {Id = -1,Name = string.Empty}, new IdNameDto {Id = 0,Name = "Нет"}, new IdNameDto {Id = 1,Name = "Да"}, }.OrderBy(x => x.Name).ToList(); model.Types = AppointmentEducationTypeDao.LoadAll().ToList(). ConvertAll(x => new IdNameDto { Id = x.Id, Name = x.Name }); }
protected void ChangeEntityProperties(IUser current, AppointmentReport entity, AppointmentReportEditModel model, User user, out string error) { error = string.Empty; User currUser = UserDao.Get(current.Id); bool dateAcceptSet = false; if (model.CandidateRejectDate.HasValue) { entity.CandidateRejectDate = DateTime.Now; entity.CandidateRejectedBy = UserDao.Load(CurrentUser.Id); } if (!model.IsDelete) { if (model.IsEditable) { //model.IsEducationExists = !entity.IsEducationExists.HasValue ? 0 : (entity.IsEducationExists.Value ? 1 : 0); //model.UserId = entity.Creator.Id; //entity.Type = AppointmentEducationTypeDao.Get(model.TypeId); entity.Name = model.Name; entity.Phone = model.Phone; entity.Email = model.Email; //entity.ColloquyDate = DateTime.Parse(model.ColloquyDate); entity.EducationTime = model.EducationTime ; //entity.RejectReason = model.RejectReason; } if (!String.IsNullOrWhiteSpace(model.LessonDate)) { DateTime res; if (DateTime.TryParse(model.LessonDate, out res)) { entity.LessonDate = res; }; } if(model.IsColloquyDateEditable) { entity.ColloquyDate = string.IsNullOrEmpty(model.ColloquyDate) ? new DateTime?() : DateTime.Parse(model.ColloquyDate); } if (model.IsManagerEditable) { entity.ResumeComment = model.ResumeComment; if (model.IsColloquyPassed >= 0) entity.IsColloquyPassed = model.IsColloquyPassed == 1 ? true : false; else entity.IsColloquyPassed = new bool?(); if (!string.IsNullOrEmpty(model.DateAccept)) { entity.DateAccept = DateTime.Parse(model.DateAccept); dateAcceptSet = true; } } if (model.IsStaffSetDateAcceptAvailable) { /*if (model.IsEducationExists >= 0) entity.IsEducationExists = model.IsEducationExists == 1 ? true : false; else entity.IsEducationExists = new bool?();*/ if (!string.IsNullOrEmpty(model.DateAccept) && entity.IsEducationExists.HasValue) { entity.DateAccept = DateTime.Parse(model.DateAccept); dateAcceptSet = true; } } } switch (current.UserRole) { case UserRole.StaffManager: { if (!entity.DeleteDate.HasValue /*&& (entity.Appointment.AcceptStaff.Id == current.Id || entity.Appointment.Recruters.Any(x=>x.Id==current.Id))*/) { entity.TestingResult = model.TestingResult; entity.ResumeCommentByOPINP = model.ResumeCommentByOPINP; if (!entity.StaffDateAccept.HasValue && model.IsStaffApproved && model.AttachmentId > 0) { entity.StaffDateAccept = DateTime.Now; entity.AcceptStaff = currUser; } if (entity.StaffDateAccept.HasValue && !entity.ManagerDateAccept.HasValue && model.IsManagerApproved) { entity.ManagerDateAccept = DateTime.Now; entity.AcceptManager = currUser; entity.TempLogin = entity.Id.ToString(); entity.TempPassword = CreatePassword(PasswordLength); } /*if (entity.Appointment.Creator.Id == current.Id && dateAcceptSet) { RejectReportsExceptId(entity.Appointment.Id, entity.Id, entity.Appointment.Creator, string.Format("Другой кандидат принят на работу (отчет № {0})", entity.Number)); }*/ if (entity.AcceptStaff != null && dateAcceptSet) { RejectReportsExceptId(entity.Appointment.Id, entity.Id, entity.Creator, string.Format("Другой кандидат принят на работу (отчет № {0})", entity.Number)); } //} } } break; case UserRole.Manager: { if (!entity.StaffDateAccept.HasValue && model.IsStaffApproved && model.AttachmentId > 0) { entity.StaffDateAccept = DateTime.Now; entity.AcceptStaff = currUser; } if(!entity.DeleteDate.HasValue && entity.StaffDateAccept.HasValue && !entity.ManagerDateAccept.HasValue && entity.Appointment.Creator.Id == current.Id && model.IsManagerApproved) { entity.ManagerDateAccept = DateTime.Now; entity.AcceptManager = currUser; entity.TempLogin = entity.Id.ToString(); entity.TempPassword = CreatePassword(PasswordLength); entity.ResumeComment = model.ResumeComment; CreateCandidate(entity); } if (!entity.DeleteDate.HasValue && entity.Appointment.Creator.Id == current.Id && dateAcceptSet) { RejectReportsExceptId(entity.Appointment.Id, entity.Id, entity.Appointment.Creator, string.Format("Другой кандидат принят на работу (отчет № {0})", entity.Number)); } } break; case UserRole.Trainer: if (model.IsEducationExists >= 0) entity.IsEducationExists = model.IsEducationExists == 1 ? true : false; else entity.IsEducationExists = new bool?(); break; case UserRole.Estimator: case UserRole.OutsourcingManager: break; default: throw new ArgumentException(string.Format("Недопустимая роль {0}", current.UserRole)); } }