public ActionResult AppointmentEdit(AppointmentEditModel model) { CorrectCheckboxes(model); CorrectDropdowns(model); if (!ValidateAppointmentEditModel(model)) { model.IsDelete = false; model.ApproveForAll = false; AppointmentBl.ReloadDictionaries(model); return View(model); } string error; if (!AppointmentBl.SaveAppointmentEditModel(model, out error)) { model.IsDelete = false; model.ApproveForAll = false; if (model.ReloadPage) { ModelState.Clear(); if (!string.IsNullOrEmpty(error)) ModelState.AddModelError("", error); var mdl = AppointmentBl.GetAppointmentEditModel(model.Id, model.StaffCreatorId == 0 ? new int?() : model.UserId); return View(mdl); } if (!string.IsNullOrEmpty(error)) ModelState.AddModelError("", error); } else { if (!string.IsNullOrEmpty(error)) ModelState.AddModelError("", error); } model.IsDelete = false; model.ApproveForAll = false; if (string.IsNullOrEmpty(error)) ViewBag.Message = "Данные успешно сохранены"; return View(model); /*if (!string.IsNullOrEmpty(error)) return View(model); return RedirectToAction("Index");*/ }
protected void CorrectDropdowns(AppointmentEditModel model) { if (!model.IsEditable) { //model.PositionId = model.PositionIdHidden; model.ReasonId = model.ReasonIdHidden; model.TypeId = model.TypeIdHidden; model.IsVacationExists = model.IsVacationExistsHidden; } }
protected bool ValidateAppointmentEditModel(AppointmentEditModel model) { //return false; //if (RequestBl.CheckOtherOrdersExists(model)) // ModelState.AddModelError("BeginMissionDate", StrOtherOrdersExists); if (model.IsDelete || model.NonActual) return true; if (model.Recruter == 2 && String.IsNullOrWhiteSpace(model.FIO)) { ModelState.AddModelError("FIO", "ФИО Кандидата должно быть заполнено!"); } if(model.ReasonId != 3 && !string.IsNullOrEmpty(model.ReasonBeginDate)) { DateTime beginDate; if (!DateTime.TryParse(model.ReasonBeginDate, out beginDate)) { ModelState.AddModelError("ReasonBeginDate", StrInvalidReasonFromDate); /*switch (model.ReasonId) { case 1: case 2: ModelState.AddModelError("ReasonBeginDate", StrInvalidReasonFromDate); break; case 4: ModelState.AddModelError("ReasonBeginDate", StrInvalidReasonFromDate); break; case 5: ModelState.AddModelError("ReasonBeginDate", StrInvalidReasonFromDate); break; }*/ } } if (!string.IsNullOrEmpty(model.ReasonBeginDate) && model.ShowStaff) { DateTime beginDate; if (!DateTime.TryParse(model.DesirableBeginDate, out beginDate)) ModelState.AddModelError("DesirableBeginDate", StrInvalidDesirableBeginDate); else { DateTime createDate = DateTime.Today; if (!string.IsNullOrEmpty(model.DateCreated)) createDate = DateTime.Parse(model.DateCreated); if (beginDate.Subtract(createDate).Days < 14) ModelState.AddModelError("DesirableBeginDate", StrDesirableBeginDateIsSmall); } } //todo need to check department int depLevel; if (!AppointmentBl.CheckDepartment(model, out depLevel)) { if (depLevel != AppointmentBl.GetRequeredDepartmentLevel()) ModelState.AddModelError("SelectDepartmentBtn", string.Format(StrInvalidDepartmentLevel, AppointmentBl.GetRequeredDepartmentLevel())); else { ModelState.AddModelError("SelectDepartmentBtn", StrInvalidDepartment); } } return ModelState.IsValid; }
public bool SaveAppointmentEditModel(AppointmentEditModel model, out string error) { error = string.Empty; User creator = null; Appointment entity = null; try { creator = UserDao.Load(model.UserId); IUser current = AuthenticationService.CurrentUser; if (model.Id == 0) { entity = new Appointment { Recruter = model.Recruter, CreateDate = DateTime.Now, Creator = creator,//UserDao.Load(current.Id), Number = RequestNextNumberDao.GetNextNumberForType((int)RequestTypeEnum.Appointment), EditDate = DateTime.Now, AppointmentEducationTypeId=model.AppointmentEducationType }; if ((CurrentUser.UserRole & UserRole.StaffManager) > 0) entity.StaffCreator = UserDao.Load(CurrentUser.Id); ChangeEntityProperties(current, entity, model, creator,out error); AppointmentDao.SaveAndFlush(entity); model.Id = entity.Id; } else { entity = AppointmentDao.Get(model.Id); if (entity == null) throw new ValidationException(string.Format(StrAppointmentNotFound, model.Id)); if (entity.Version != model.Version) { error = "Заявка была изменена другим пользователем."; model.ReloadPage = true; return false; } ChangeEntityProperties(current, entity, model, creator, out error); AppointmentDao.SaveAndFlush(entity); if (entity.Version != model.Version) { entity.EditDate = DateTime.Now; AppointmentDao.SaveAndFlush(entity); } } if (entity.DeleteDate.HasValue) model.IsDeleted = true; if (entity.Reports != null && entity.Reports.Any()) { model.Reports = entity.Reports.Select(x => new IdNameDto { Id = x.Id, Name = x.SecondNumber.ToString() }).ToList(); } model.DocumentNumber = entity.Number.ToString(); model.Version = entity.Version; model.DateCreated = entity.CreateDate.ToShortDateString(); SetFlagsState(entity.Id, UserDao.Load(current.Id),current.UserRole, entity, model); return true; } catch (Exception ex) { AppointmentDao.RollbackTran(); Log.Error("Error on SaveAppointmentEditModel:", ex); error = StrException + ex.GetBaseException().Message; return false; } finally { SetManagerInfoModel(creator, model,entity,null); LoadDictionaries(model); SetHiddenFields(model); } }
protected void CorrectCheckboxes(AppointmentEditModel model) { if (!model.IsManagerApproveAvailable) { if (ModelState.ContainsKey("IsManagerApproved")) ModelState.Remove("IsManagerApproved"); model.IsManagerApproved = model.IsManagerApprovedHidden; } if (!model.IsChiefApproveAvailable) { if (ModelState.ContainsKey("IsChiefApproved")) ModelState.Remove("IsChiefApproved"); model.IsChiefApproved = model.IsChiefApprovedHidden; } /*if (!model.IsPersonnelApproveAvailable) { if (ModelState.ContainsKey("IsPersonnelApproved")) ModelState.Remove("IsPersonnelApproved"); model.IsPersonnelApproved = model.IsPersonnelApprovedHidden; }*/ if (!model.IsStaffApproveAvailable) { if (ModelState.ContainsKey("IsStaffApproved")) ModelState.Remove("IsStaffApproved"); model.IsStaffApproved = model.IsStaffApprovedHidden; } if(model.IsDelete) { if (ModelState.ContainsKey("IsStaffReceiveRejectMail")) ModelState.Remove("IsStaffReceiveRejectMail"); } if (model.ApproveForAll) { if (ModelState.ContainsKey("IsManagerApproved")) ModelState.Remove("IsManagerApproved"); } /*if (model.IsManagerApproveAvailable && model.IsManagerApproved.HasValue && !model.IsManagerApproved.Value) { if (ModelState.ContainsKey("IsManagerApproved")) ModelState.Remove("IsManagerApproved"); } if (model.IsChiefApproveAvailable && model.IsChiefApproved.HasValue && !model.IsChiefApproved.Value) { if (ModelState.ContainsKey("IsChiefApproved")) ModelState.Remove("IsChiefApproved"); if (ModelState.ContainsKey("IsManagerApproved")) ModelState.Remove("IsManagerApproved"); }*/ }
public AppointmentEditModel GetAppointmentEditModel(int id,int? managerId) { AppointmentEditModel model = new AppointmentEditModel { Id = id }; Appointment entity = null; User creator; IUser current = AuthenticationService.CurrentUser; User currUser = UserDao.Load(current.Id); if (id != 0) { entity = AppointmentDao.Load(id); if (entity == null) throw new ValidationException(string.Format(StrAppointmentNotFound, id)); creator = entity.Creator; model.StaffCreatorId = entity.StaffCreator == null ? 0 : entity.StaffCreator.Id; model.StaffCreatorName = entity.StaffCreator == null ? "" : entity.StaffCreator.Name; model.isNeedToNotify = entity.isNotifyNeeded; model.FIO = entity.FIO; model.Priority = entity.Priority; model.PyrusNumber = entity.PyrusNumber; model.AppointmentEducationType = entity.AppointmentEducationTypeId; if(entity.Recruters!=null && entity.Recruters.Any()) { model.Recruter1id = entity.Recruters[0].Id; if (entity.Recruters.Count > 1) model.Recruter2id = entity.Recruters[1].Id; if (entity.Recruters.Count > 2) model.Recruter3id = entity.Recruters[2].Id; } model.Recruter = entity.Recruter; 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(); } if (entity.Reports != null && entity.Reports.Any()) { model.Reports = entity.Reports.Select(x => new IdNameDto { Id = x.Id, Name = x.SecondNumber.ToString() }).ToList(); } //model.AdditionalRequirements = entity.AdditionalRequirements; model.ShowStaff = entity.Recruter == 1; if(entity.BankAccountant!=null) model.BankAccountantName = entity.BankAccountant.Name; model.Bonus = FormatSum(entity.Bonus); model.City = entity.City; model.Compensation = entity.Compensation; model.DateCreated = FormatDate(entity.CreateDate); model.DepartmentId = entity.Department.Id; model.DepartmentName = entity.Department.Name; model.DesirableBeginDate = FormatDate(entity.DesirableBeginDate); model.EducationRequirements = entity.EducationRequirements; model.ExperienceRequirements = entity.ExperienceRequirements; model.IsVacationExists = entity.IsVacationExists ? 1 : 0; model.DocumentNumber = entity.Number.ToString(); model.OtherRequirements = entity.OtherRequirements; model.BankAccountantAccept = entity.BankAccountantAccept.HasValue?entity.BankAccountantAccept.Value:false; model.BankAccountantAcceptCount = entity.BankAccountantAcceptCount; //model.Period = entity.Period; model.PositionName = entity.PositionName; model.ReasonId = entity.Reason.Id; // hardcode using database Ids from [dbo].[AppointmentReason] switch (entity.Reason.Id) { case 1: case 2: //case 3: model.ReasonPosition = null; model.ReasonBeginDate = FormatDate(entity.ReasonBeginDate); break; case 4: case 5: model.ReasonPosition = entity.ReasonPosition; if(entity.ReasonPositionUser!=null) model.ReasonPositionId = entity.ReasonPositionUser.Id; model.ReasonBeginDate = FormatDate(entity.ReasonBeginDate); break; case 7: case 6: case 3: model.ReasonPosition = entity.ReasonPosition; if (entity.ReasonPositionUser != null) model.ReasonPositionId = entity.ReasonPositionUser.Id; model.ReasonBeginDate = string.Empty; break; /*case 4: case 5: model.ReasonPosition = entity.ReasonUser; model.ReasonBeginDate = FormatDate(entity.ReasonBeginDate); break;*/ default: throw new ArgumentException(string.Format(StrIncorrectReasonId,entity.Reason.Id)); } model.Responsibility = entity.Responsibility; model.Salary = FormatSum(entity.Salary); model.Schedule = entity.Schedule; model.TypeId = entity.Type?1:0; model.UserId = entity.Creator.Id; model.VacationCount = entity.VacationCount.ToString(); model.Version = entity.Version; } else { creator = managerId.HasValue? UserDao.Load(managerId.Value) : currUser; model.ShowStaff = true; model.Recruter = 1; model.AppointmentEducationType = 1; model.IsVacationExists = 1; SetCreatorDepartment(creator, model); model.UserId = creator.Id;//currUser.Id; if(managerId.HasValue) model.StaffCreatorId = currUser.Id; } //if (!CheckUserRights(current, id, entity, false)) todo ??? // throw new ArgumentException(StrAccessIsDenied); SetManagerInfoModel(creator, model,entity,null); LoadDictionaries(model); SetFlagsState(id, currUser,current.UserRole, entity, model); SetHiddenFields(model); if ((current.UserRole & UserRole.Manager) != UserRole.Manager && model.StaffCreatorId != current.Id && current.UserRole != UserRole.ConsultantPersonnel &¤t.UserRole != UserRole.StaffManager ) { model.IsEditable = false; model.IsSaveAvailable = false; } return model; }
public void ReloadDictionaries(AppointmentEditModel model) { User user = UserDao.Load(model.UserId); Appointment entity = null; LoadDictionaries(model); if (model.Id == 0) { model.DateCreated = DateTime.Today.ToShortDateString(); } else { entity = AppointmentDao.Load(model.Id); model.DocumentNumber = entity.Number.ToString(); model.DateCreated = entity.CreateDate.ToShortDateString(); if (entity.DeleteDate.HasValue) model.IsDeleted = true; // no need to load ManagerFio and other because no error in model after manager approve } SetManagerInfoModel(user, model,entity,null); }
protected void SetFlagsState(AppointmentEditModel model, bool state) { model.IsEditable = state; model.IsSaveAvailable = state; model.IsChiefApproveAvailable = state; model.IsManagerApproveAvailable = state; model.IsManagerRejectAvailable = state; //model.IsPersonnelApproveAvailable = state; model.IsStaffApproveAvailable = state; model.ApproveForAllAvailable = state; }
protected void SetHiddenFields(AppointmentEditModel model) { model.IsVacationExistsHidden = model.IsVacationExists; //model.PositionIdHidden = model.PositionId; model.ReasonIdHidden = model.ReasonId; model.TypeIdHidden = model.TypeId; model.IsManagerApprovedHidden = model.IsManagerApproved; model.IsChiefApprovedHidden = model.IsChiefApproved; //model.IsPersonnelApprovedHidden = model.IsPersonnelApproved; model.IsStaffApprovedHidden = model.IsStaffApproved; //model.DateCreatedHidden = model.DateCreated; }
protected void SetFlagsState(int id, User current,UserRole currRole, Appointment entity, AppointmentEditModel model) { SetFlagsState(model, false); if (entity != null) { model.NonActual = entity.NonActual; var candidates = entity.Candidates!=null?entity.Candidates.Where(x => x.Status != Reports.Core.Enum.EmploymentStatus.REJECTED):null; if (candidates == null || !candidates.Any()) { model.IsNonActualButtonAvailable = true; } } model.StaffBossId = ConfigurationService.StaffBossId.HasValue?ConfigurationService.StaffBossId.Value:0; if(model.Id == 0) { if ((currRole & UserRole.Manager) != UserRole.Manager && currRole!= UserRole.StaffManager) throw new ArgumentException(string.Format(StrUserNotManager, current.Id)); model.IsEditable = true; model.IsSaveAvailable = true; model.IsManagerApproveAvailable = true; model.ApproveForAllAvailable = true; return; } model.IsManagerApproved = entity.ManagerDateAccept.HasValue; model.IsChiefApproved = entity.ChiefDateAccept.HasValue; //model.IsPersonnelApproved = entity.PersonnelDateAccept.HasValue; model.IsStaffApproved = entity.StaffDateAccept.HasValue; model.IsDeleted = entity.DeleteDate.HasValue; if (entity.AcceptManager != null && entity.ManagerDateAccept.HasValue) model.ManagerFio = entity.AcceptManager.FullName; if (entity.AcceptChief != null && entity.ChiefDateAccept.HasValue) model.ChiefFio = entity.AcceptChief.FullName; //if (entity.AcceptPersonnel != null && entity.PersonnelDateAccept.HasValue) // model.PersonnelFio = entity.AcceptPersonnel.FullName; if (entity.AcceptStaff != null && entity.StaffDateAccept.HasValue) model.StaffFio = entity.AcceptStaff.FullName; bool isApprovedReportExists = AppointmentReportDao.IsApprovedReportForAppointmentIdExists(entity.Id); if(entity.DeleteDate.HasValue) { model.DeleteUser = entity.DeleteUser.FullName; if (entity.AcceptStaff != null) model.IsStaffReceiveRejectMail = true; // todo Need flag on entity ? /*if (entity.AcceptStaff != null) model.StaffFio = entity.AcceptStaff.FullName;*/ } switch (currRole) { case UserRole.Manager: if(current.Id == entity.Creator.Id && !entity.DeleteDate.HasValue) { if(!isApprovedReportExists) model.IsManagerRejectAvailable = true; if (!entity.ManagerDateAccept.HasValue) { model.IsManagerApproveAvailable = true; model.IsEditable = true; } else { if (entity.BankAccountantAccept.HasValue) { model.IsChiefApproveAvailable = IsManagerChiefForCreator(current, entity.Creator) && entity.BankAccountantAccept.Value; } else { if (entity.Reason.Id == 3 || entity.Reason.Id == 6) model.IsChiefApproveAvailable = IsManagerChiefForCreator(current, entity.Creator); } } } else if (!entity.DeleteDate.HasValue && entity.ManagerDateAccept.HasValue && entity.Creator.Id != current.Id && IsManagerChiefForCreator(current, entity.Creator)) { if (!isApprovedReportExists) model.IsManagerRejectAvailable = true; if (!entity.ChiefDateAccept.HasValue && entity.BankAccountantAccept.HasValue && entity.IsVacationExists && entity.BankAccountantAcceptCount>0) model.IsChiefApproveAvailable = true; else if (!entity.ChiefDateAccept.HasValue) { if (entity.Reason.Id == 3 || entity.Reason.Id == 6) model.IsChiefApproveAvailable = IsManagerChiefForCreator(current, entity.Creator); } } break; case UserRole.StaffManager: if (!entity.DeleteDate.HasValue ) { if(entity.ChiefDateAccept.HasValue && !entity.StaffDateAccept.HasValue) model.IsStaffApproveAvailable = true; if (!entity.StaffDateAccept.HasValue && model.StaffCreatorId == current.Id) { model.ApproveForAllAvailable = true; if (!isApprovedReportExists) model.IsManagerRejectAvailable = true; if (!entity.ManagerDateAccept.HasValue) { model.IsEditable = true; model.IsManagerApproveAvailable = true; } } } break; case UserRole.Estimator: case UserRole.OutsourcingManager: break; case UserRole.ConsultantPersonnel: case UserRole.Security: case UserRole.PersonnelManager: break; default: throw new ArgumentException(string.Format("Недопустимая роль {0}",currRole)); } if ((entity.Creator.Id == current.Id || (entity.StaffCreator!=null && entity.StaffCreator.Id==current.Id)) && !entity.ManagerDateAccept.HasValue) { model.IsEditable = true; model.IsManagerApproveAvailable = true; } model.IsSaveAvailable = model.IsEditable || model.IsManagerApproveAvailable || ((CurrentUser.UserRole & UserRole.StaffManager)>0) || model.IsChiefApproveAvailable || model.IsStaffApproveAvailable || (currRole == UserRole.ConsultantPersonnel && (model.IsVacationExists != 1 || model.BankAccountantAccept != true || model.BankAccountantAcceptCount < int.Parse(model.VacationCount))); }
protected void SetCreatorDepartment(User creator,AppointmentEditModel model) { if ((creator.UserRole & UserRole.Manager) == UserRole.Manager) { List<DepartmentDto> departments; switch (creator.Level) { case 2: departments = AppointmentDao.GetDepartmentsForManager23(creator.Id, 2, false).ToList(); if(departments.Count > 0) { model.DepartmentId = departments[0].Id; model.DepartmentName = departments[0].Name; } break; case 3: departments = AppointmentDao.GetDepartmentsForManager23(creator.Id, 3, false).ToList(); if(departments.Count > 0) { model.DepartmentId = departments[0].Id; model.DepartmentName = departments[0].Name; } break; default: if (creator.Department == null) throw new ValidationException(string.Format(StrNoDepartmentForManager, creator.Id)); model.DepartmentId = creator.Department.Id; model.DepartmentName = creator.Department.Name; break; } } }
public bool CheckDepartment(AppointmentEditModel model,out int level) { level = 0; int departmentId = model.DepartmentId; if ((CurrentUser.UserRole & UserRole.Manager) != UserRole.Manager && model.StaffCreatorId != CurrentUser.Id) return true; Department dep = DepartmentDao.Load(departmentId); if(dep == null) throw new ArgumentException(string.Format(StrDepartmentNotFound,departmentId)); if (!dep.ItemLevel.HasValue) throw new ArgumentException(string.Format(StrDepartmentLevelNotFound, departmentId)); level = dep.ItemLevel.Value; if (dep.ItemLevel.Value != RequeredDepartmentLevel) return false; User currUser; if ((CurrentUser.UserRole & UserRole.Manager) > 0) currUser = UserDao.Load(CurrentUser.Id); else currUser = UserDao.Load(model.UserId);// если еще раз тут будешь, вспомни, что Улькина может создавать за сотрудника if (CurrentUser.UserRole == UserRole.StaffManager) return true; if(currUser == null) throw new ArgumentException(string.Format(StrUserNotFound, model.UserId)); if (currUser.Level < MinManagerLevel || currUser.Level > MaxManagerLevel) throw new ValidationException(string.Format(StrIncorrectManagerLevel, currUser.Level, currUser.Id)); List<DepartmentDto> departments; try//ЗАПЛАТКА { var mr=ManualRoleRecordDao.QueryExpression(x => x.User.Id == CurrentUser.Id && dep.Path.Contains(x.TargetDepartment.Path)); if (mr != null && mr.Any()) return true; } catch (Exception e) { } if (currUser.Department != null && dep.Path.StartsWith(currUser.Department.Path)) return true; switch (currUser.Level) { case 2: IList<int> managers2 = AppointmentDao.GetChildrenManager2ForManager2(currUser.Id); if (managers2.Count > 0) return true; departments = AppointmentDao.GetDepartmentsForManager23(currUser.Id, 2, false).ToList(); return departments.Any(x => dep.Path.StartsWith(x.Path)); case 3: departments = AppointmentDao.GetDepartmentsForManager23(currUser.Id, 3, false).ToList(); return departments.Any(x => dep.Path.StartsWith(x.Path)); default: if (currUser.Department == null) throw new ValidationException(string.Format(StrNoDepartmentForManager, currUser.Id)); return dep.Path.StartsWith(currUser.Department.Path); } }
protected void LoadDictionaries(AppointmentEditModel model) { model.Priorities = new List<IdNameDto> { new IdNameDto{Id=0, Name="-"}, new IdNameDto{Id=1, Name="Срочно"}, new IdNameDto{Id=2, Name="Очень срочно"} }; var creator=UserDao.Load(model.UserId); if (creator != null && creator.Department != null) model.UsersList = UserDao.GetUsersForManagerNotDismissed(creator.Id, UserRole.Manager, creator.Department.Id,model.DateCreated!=null?model.DateCreated:DateTime.Now.ToShortDateString()); if( model.ReasonPositionId>0 && model.UsersList!=null && !model.UsersList.Any(x=>x.Id==model.ReasonPositionId)) { var u = UserDao.Load(model.ReasonPositionId); model.UsersList.Add(new IdNameDto { Id = u.Id, Name = u.Name }); } if( model.Id>0 && model.DateCreated!= null && DateTime.Parse(model.DateCreated)<new DateTime(2015,7,22)) model.UsersList.Add(new IdNameDto{ Id = 0, Name ="-"}); model.Personnels = EmploymentCandidateDao.GetPersonnels(); model.AppointmentEducationTypes=AppointmentEducationTypeDao.LoadAll().Select(x=>new IdNameDto{ Id=x.Id, Name=x.Name}).ToList(); model.Recruters = UserDao.GetStaffList().Select(x => new IdNameDto { Id = x.Id, Name = x.Name }).ToList(); model.Recruters.Add(new IdNameDto { Id = 0, Name = "-" }); model.DepartmentRequiredLevel = 7; model.CommentsModel = GetCommentsModel(model.Id,RequestTypeEnum.Appointment); model.Types = new List<IdNameDto> { new IdNameDto {Id = 0,Name = "Бессрочный"}, new IdNameDto {Id = 1,Name = "Срочный"}, }; //model.Positions = PositionDao.LoadAllSorted().ToList().ConvertAll(x => new IdNameDto {Id = x.Id, Name = x.Name}); model.Reasons = AppointmentReasonDao.LoadAll().ToList().ConvertAll(x => new IdNameDto { Id = x.Id, Name = x.Name }); model.IsVacationExistsValues = new List<IdNameDto> { new IdNameDto {Id = 1,Name = "Есть"}, new IdNameDto {Id = 0,Name = "Нет"}, }; }
protected void ChangeEntityProperties(IUser current, Appointment entity, AppointmentEditModel model, User user,out string error) { error = string.Empty; User currUser = UserDao.Load(current.Id); if (!model.IsDelete && (model.IsEditable || model.IsSaveAvailable)) { //entity.AdditionalRequirements = model.AdditionalRequirements; entity.FIO = model.FIO; entity.isNotifyNeeded=model.isNeedToNotify; entity.Bonus = Decimal.Parse(model.Bonus); entity.PyrusNumber = model.PyrusNumber; entity.City = model.City; entity.Compensation =(String.IsNullOrWhiteSpace(model.Compensation))?"-":model.Compensation; entity.Department = DepartmentDao.Load(model.DepartmentId); entity.EducationRequirements = (String.IsNullOrWhiteSpace(model.EducationRequirements))?"-":model.EducationRequirements; entity.ExperienceRequirements =(String.IsNullOrWhiteSpace( model.ExperienceRequirements))?"-":model.ExperienceRequirements; entity.OtherRequirements =(String.IsNullOrWhiteSpace( model.OtherRequirements))?"-":model.OtherRequirements; //entity.Period = model.Period; entity.PositionName = model.PositionName;//PositionDao.Load(model.PositionId); entity.Reason = AppointmentReasonDao.Load(model.ReasonId); entity.ReasonBeginDate = (model.ReasonId != 3 && !String.IsNullOrWhiteSpace(model.ReasonBeginDate)) ? DateTime.Parse(model.ReasonBeginDate) : new DateTime?(); entity.DesirableBeginDate = model.ShowStaff ? DateTime.Parse(model.DesirableBeginDate) : entity.ReasonBeginDate.HasValue ? entity.ReasonBeginDate.Value+TimeSpan.FromDays(14) : DateTime.Now; //entity.AppointmentEducationTypeId = model.AppointmentEducationType; entity.ReasonPosition = model.ReasonId != 1 && model.ReasonId != 2 ?model.ReasonPosition:null; if (model.ReasonId > 2 && model.ReasonId < 7 && model.ReasonPositionId>0) { entity.ReasonPositionUser = UserDao.Load(model.ReasonPositionId); } entity.Responsibility = (String.IsNullOrWhiteSpace(model.Responsibility))?"-":model.Responsibility; entity.Salary = Decimal.Parse(model.Salary); entity.Schedule = (String.IsNullOrWhiteSpace(model.Schedule))?"-":model.Schedule; entity.Type = model.TypeId == 1?true:false; if (current.UserRole == UserRole.ConsultantPersonnel) { entity.BankAccountant = UserDao.Load(current.Id); entity.IsVacationExists = model.IsVacationExists == 1 ? true : false; model.BankAccountantAccept = true; entity.BankAccountantAccept = model.BankAccountantAccept; entity.BankAccountantAcceptCount = model.BankAccountantAcceptCount; } entity.VacationCount = int.Parse(model.VacationCount); if (model.StaffCreatorId != 0) entity.StaffCreator = UserDao.Load(model.StaffCreatorId); } switch (current.UserRole) { case UserRole.ConsultantPersonnel: if (entity.BankAccountantAccept.HasValue && entity.IsVacationExists) { EmailDto dto = SendEmailForAppointmentManagerAccept(entity.Creator, entity); if (!string.IsNullOrEmpty(dto.Error)) error = string.Format("Заявка обработана успешно,но есть ошибка при отправке оповещений: {0}", dto.Error); } if (entity.BankAccountantAccept.HasValue && !entity.IsVacationExists) { EmailDto dto = SendEmailForBankAccountantReject(entity.Creator, entity); if (!string.IsNullOrEmpty(dto.Error)) error = string.Format("Заявка обработана успешно,но есть ошибка при отправке оповещений: {0}", dto.Error); } break; case UserRole.Manager: if(current.Id == entity.Creator.Id) { if (model.NonActual) { entity.NonActual = model.NonActual; EmploymentCandidateDao.CancelCandidatesByAppointmentId(model.Id); RejectReports(entity.Id, currUser, "Заявка отклонена"); } if(model.IsManagerRejectAvailable && !entity.DeleteDate.HasValue && model.IsDelete) { /*entity.DeleteDate = DateTime.Now; entity.DeleteUser = currUser;*/ RejectAppointment(entity); EmailDto dto = SendEmailForAppointmentReject(currUser, entity); if (!string.IsNullOrEmpty(dto.Error)) error = string.Format("Заявка обработана успешно,но есть ошибка при отправке оповещений: {0}",dto.Error); RejectReports(entity.Id, currUser, "Заявка отклонена"); //if(entity.AcceptStaff != null) // SendEmailForAppointmentReject(entity.AcceptStaff, entity); } if(!entity.DeleteDate.HasValue && model.IsManagerApproveAvailable && model.IsManagerApproved) { entity.ManagerDateAccept = DateTime.Now; entity.AppointmentEducationTypeId = model.AppointmentEducationType; entity.AcceptManager = currUser; //entity.AppointmentEducationTypeId = model.AppointmentEducationType; EmailDto dto = SendEmailForBankAccountant(entity.Creator, entity); //dto = SendEmailForAppointmentManagerAccept(entity.Creator, entity); if (!string.IsNullOrEmpty(dto.Error)) error = string.Format("Заявка обработана успешно,но есть ошибка при отправке оповещений: {0}", dto.Error); var dto2=SendEmailForStaffManager(entity); if (!string.IsNullOrEmpty(dto2.Error)) error = string.Format("Заявка обработана успешно,но есть ошибка при отправке оповещений: {0}", dto2.Error); } if(IsManagerChiefForCreator(currUser,entity.Creator)) if (!entity.DeleteDate.HasValue && model.IsChiefApproveAvailable && model.IsChiefApproved) { entity.ChiefDateAccept = DateTime.Now; entity.AcceptChief = currUser; EmailDto dto = SendEmailForAppointmentChiefAccept(currUser, entity); if (!string.IsNullOrEmpty(dto.Error)) error = string.Format("Заявка обработана успешно,но есть ошибка при отправке оповещений: {0}", dto.Error); if (entity.Recruter == 2) { entity.AcceptStaff = entity.Creator; CreateAppointmentReport(entity); } } } else if(IsManagerChiefForCreator(currUser,entity.Creator)) { if (model.NonActual) { entity.NonActual = model.NonActual; EmploymentCandidateDao.CancelCandidatesByAppointmentId(model.Id); RejectReports(entity.Id, currUser, "Заявка отклонена"); } if (model.IsManagerRejectAvailable && !entity.DeleteDate.HasValue && model.IsDelete) { /*entity.DeleteDate = DateTime.Now; entity.DeleteUser = currUser;*/ RejectAppointment(entity); EmailDto dto = SendEmailForAppointmentReject(currUser, entity); if (!string.IsNullOrEmpty(dto.Error)) error = string.Format("Заявка обработана успешно,но есть ошибка при отправке оповещений: {0}",dto.Error); RejectReports(entity.Id, currUser, "Заявка отклонена"); //if(entity.AcceptStaff != null) // SendEmailForAppointmentReject(entity.AcceptStaff, entity); } if (!entity.DeleteDate.HasValue && model.IsChiefApproveAvailable && model.IsChiefApproved) { entity.ChiefDateAccept = DateTime.Now; entity.AcceptChief = currUser; EmailDto dto = SendEmailForAppointmentChiefAccept(currUser, entity); if (!string.IsNullOrEmpty(dto.Error)) error = string.Format("Заявка обработана успешно,но есть ошибка при отправке оповещений: {0}", dto.Error); if (entity.Recruter == 2) { entity.AcceptStaff = entity.Creator; CreateAppointmentReport(entity); } } } break; case UserRole.StaffManager: if (model.AppointmentEducationType != entity.AppointmentEducationTypeId) { entity.AppointmentEducationTypeId = model.AppointmentEducationType; AppointmentReportDao.Update(x => x.Appointment.Id == entity.Id, y => y.Type = AppointmentEducationTypeDao.Load(entity.AppointmentEducationTypeId)); } if (model.NonActual) { entity.NonActual = model.NonActual; EmploymentCandidateDao.CancelCandidatesByAppointmentId(model.Id); RejectReports(entity.Id, currUser, "Заявка отклонена"); } if (!entity.DeleteDate.HasValue) { entity.NonActual = model.NonActual; if (model.StaffCreatorId == current.Id || entity.Creator.Id == current.Id) { if (model.ApproveForAll) { entity.ManagerDateAccept = DateTime.Now; entity.AcceptManager = currUser; entity.ChiefDateAccept = DateTime.Now; entity.AcceptChief = currUser; entity.StaffDateAccept = DateTime.Now; entity.AcceptStaff = currUser; if (entity.Id == 0) AppointmentDao.SaveAndFlush(entity); CreateAppointmentReport(entity); } else if (model.IsManagerRejectAvailable && model.IsDelete) { /*entity.DeleteDate = DateTime.Now; entity.DeleteUser = currUser;*/ RejectAppointment(entity); RejectReports(entity.Id, currUser, "Заявка отклонена"); } else if (model.IsChiefApproveAvailable && model.IsChiefApproved) { /*if (model.StaffCreatorId == current.Id) {*/ entity.ChiefDateAccept = DateTime.Now; entity.AcceptChief = currUser; //} } else if (model.IsManagerApproveAvailable && model.IsManagerApproved) { entity.ManagerDateAccept = DateTime.Now; entity.AcceptManager = currUser; EmailDto dto = SendEmailForAppointmentManagerAccept(entity.Creator, entity); if (!string.IsNullOrEmpty(dto.Error)) error = string.Format("Заявка обработана успешно,но есть ошибка при отправке оповещений: {0}", dto.Error); } else if (entity.ChiefDateAccept.HasValue && !entity.StaffDateAccept.HasValue && model.IsStaffApproveAvailable && model.IsStaffApproved) { entity.StaffDateAccept = DateTime.Now; var recruters = new List<User>(); if(model.Recruter1id>0) recruters.Add( UserDao.Load(model.Recruter1id)); if(model.Recruter2id>0) recruters.Add( UserDao.Load(model.Recruter2id)); if(model.Recruter3id>0) recruters.Add( UserDao.Load(model.Recruter3id)); entity.Recruters = recruters; //entity.AppointmentEducationTypeId = model.AppointmentEducationType; entity.AcceptStaff = currUser; entity.Priority = model.Priority; CreateAppointmentReport(entity); } } else if (entity.ChiefDateAccept.HasValue && !entity.StaffDateAccept.HasValue && model.IsStaffApproveAvailable && model.IsStaffApproved) { entity.StaffDateAccept = DateTime.Now; entity.AcceptStaff = currUser; //entity.AppointmentEducationTypeId = model.AppointmentEducationType; var recruters = new List<User>(); if (model.Recruter1id > 0) recruters.Add(UserDao.Load(model.Recruter1id)); if (model.Recruter2id > 0) recruters.Add(UserDao.Load(model.Recruter2id)); if (model.Recruter3id > 0) recruters.Add(UserDao.Load(model.Recruter3id)); entity.Recruters = recruters; entity.Priority = model.Priority; CreateAppointmentReport(entity); } } break; case UserRole.Estimator: case UserRole.OutsourcingManager: break; default: throw new ArgumentException(string.Format("Недопустимая роль {0}", current.UserRole)); } }