public int CreateAppointmentReport(Appointment entity/*,User creator*/) { int id = 0; int secondnumber = 0; var reports = AppointmentReportDao.QueryExpression(x => x.Appointment.Id == entity.Id); if (reports != null && reports.Any()) { foreach (var el in reports) { if (el.SecondNumber > secondnumber) secondnumber = el.SecondNumber; } } secondnumber++; AppointmentReport report = new AppointmentReport { Appointment = entity, Creator = entity.AcceptStaff!=null?entity.AcceptStaff:UserDao.Load(CurrentUser.Id) , CreateDate = DateTime.Now, EditDate = DateTime.Now, Email = string.Empty, Name = entity.FIO!=null?entity.FIO:"", Number = RequestNextNumberDao.GetNextNumberForType((int)RequestTypeEnum.AppointmentReport), SecondNumber = secondnumber, Phone = string.Empty, Type = AppointmentEducationTypeDao.Get(entity.AppointmentEducationTypeId), IsColloquyPassed=entity.Recruter==2?true:new bool?(), }; if (entity.Recruter == 2) report.StaffDateAccept = DateTime.Now; AppointmentReportDao.Save(report); id = report.Id; return id; }
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 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 SetManagerInfoModel(User user, ManagerInfoModel model,Appointment appointment, AppointmentReport appointmentReport) { if(appointmentReport != null) model.StaffName = appointmentReport.Creator.FullName; else if(appointment != null) { AppointmentReport rep = AppointmentReportDao.LoadForAppointmentId(appointment.Id).FirstOrDefault(); if(rep != null) model.StaffName = rep.Creator.FullName; } #region Заполнение списка вышестоящих руководителей IList<User> chiefs = GetChiefsForManager(user.Id) //.Where<User>(chief => chief.Level >= 4) .OrderByDescending<User, int?>(chief => chief.Level) .ToList<User>(); // + руководители по ручным привязкам IList<User> manualRoleManagers = ManualRoleRecordDao.GetManualRoleHoldersForUser(user.Id, UserManualRole.ApprovesEmployment); foreach (var manualRoleManager in manualRoleManagers) { if (!chiefs.Contains(manualRoleManager)) { chiefs.Add(manualRoleManager); } } StringBuilder chiefsBuilder = new StringBuilder(); foreach (var chief in chiefs) { chiefsBuilder.AppendFormat("{0} ({1}), ", chief.Name, chief.Position == null ? "<не указана>" : chief.Position.Name); } // Cut off trailing ", " if (chiefsBuilder.Length >= 2) { chiefsBuilder.Remove(chiefsBuilder.Length - 2, 2); } model.Chiefs = chiefsBuilder.ToString(); #endregion if(appointment!=null) model.DocumentNumber = appointment.Number.ToString(); model.Department = user.Department == null ? string.Empty : user.Department.Name; model.Organization = user.Organization != null ? user.Organization.Name : string.Empty; model.Position = user.Position != null ? user.Position.Name : string.Empty; model.UserName = user.FullName; model.ManagerId = user.Id; }
protected EmailDto SendEmailForBankAccountantReject(User user, Appointment entity) { string BankAccountantEmail = user.Email; if (string.IsNullOrEmpty(BankAccountantEmail)) throw new ValidationException("У пользователя нет почты"); string body = String.Format("Заявка №{0} от {1} на поиск кандидата не одобрена.", entity.Number, entity.CreateDate); string subject = "Заявка на поиск сотрудника не одобрена"; return SendEmail(BankAccountantEmail, subject, body); }
protected EmailDto SendEmailForStaffManager(Appointment entity) { string staffManagerEmail = ConfigurationService.AppointmentStaffManagerEmail; if (string.IsNullOrEmpty(staffManagerEmail)) throw new ValidationException(StrEmailForStaffManagerNotFound); DepartmentDto dep3 = AppointmentDao.GetDepartmentForPathAndLevel(entity.Department.Path, 3); if (dep3 == null) Log.ErrorFormat(StrEmailForAppointmentManagerAcceptDepartment3NotFound, entity.Department.Id); string body = string.Format("Создана заявка № {0} на подбор {1}, дирекция {2} сотрудником {3}", entity.Number, entity.PositionName, dep3 == null ? "<не найдено в базе данных>" : dep3.Name, entity.Creator.Name); string subject = "Создана заявка на поиск кандидата."; return SendEmail(staffManagerEmail, subject, body); }
protected EmailDto SendEmailForAppointmentReject(User user, Appointment entity) { string to = string.Empty; if (entity.ManagerDateAccept.HasValue) { if (!string.IsNullOrEmpty(entity.AcceptManager.Email)) to += entity.AcceptManager.Email; else Log.ErrorFormat("No email for manager (id {0})",entity.AcceptManager.Id); } if (entity.ChiefDateAccept.HasValue) { if (!string.IsNullOrEmpty(entity.AcceptChief.Email)) { if (string.IsNullOrEmpty(to)) to = entity.AcceptChief.Email; else to += ";" + entity.AcceptChief.Email; } else Log.ErrorFormat("No email for chief (id {0})", entity.AcceptChief.Id); } /*if (entity.PersonnelDateAccept.HasValue) { if (!string.IsNullOrEmpty(entity.AcceptPersonnel.Email)) { if (string.IsNullOrEmpty(to)) to = entity.AcceptPersonnel.Email; else to += ";" + entity.AcceptPersonnel.Email; } else Log.ErrorFormat("No email for personnel (id {0})", entity.AcceptPersonnel.Id); }*/ if (entity.StaffDateAccept.HasValue) { if (!string.IsNullOrEmpty(entity.AcceptStaff.Email)) { if (string.IsNullOrEmpty(to)) to = entity.AcceptStaff.Email; else to += ";" + entity.AcceptStaff.Email; } else Log.ErrorFormat("No email for staff (id {0})", entity.AcceptStaff.Id); } string body; string subject = GetSubjectAndBodyForAppointmentRejectRequest(user, entity, out body); return SendEmail(to, subject, body); }
protected EmailDto SendEmailForBankAccountant(User user, Appointment entity) { string BankAccountantEmail = ConfigurationService.AppointmentPersonnelManagerEmail; if (string.IsNullOrEmpty(BankAccountantEmail)) throw new ValidationException(StrEmailForStaffManagerNotFound); string body=String.Format("Создана заявка №{0} от {1} на поиск кандидата в {2}",entity.Number,entity.CreateDate,entity.Department.Name); string subject = "Создана заявка на поиск сотрудника"; return SendEmail(BankAccountantEmail, subject, body); }
/*protected EmailDto SendEmailForAppointmentPersonnelAccept(User personnel, Appointment entity) { string staffManagerEmail = ConfigurationService.AppointmentStaffManagerEmail; if (string.IsNullOrEmpty(staffManagerEmail)) throw new ValidationException(StrEmailForStaffManagerNotFound); string body; string subject = GetSubjectAndBodyForAppointmentManagerAcceptRequest(personnel, entity, out body); return SendEmail(staffManagerEmail, subject, body); }*/ protected EmailDto SendEmailForAppointmentManagerAccept(User creator, Appointment entity) { string to = string.Empty; //IdNameDto user; List<IdNameDto> users; var chiefs = GetChiefsForManager(creator.Id).OrderByDescending(x=>x.Level); if (chiefs.Any()) foreach(var el in chiefs) { if (String.IsNullOrWhiteSpace(el.Email)) continue; string b; string s = GetSubjectAndBodyForAppointmentManagerAcceptRequest(creator, entity, out b); return SendEmail(el.Email, s, b); } #region Анахронизм switch (creator.UserRole) { case UserRole.Manager: switch (creator.Level) { case 2: users = AppointmentDao.GetParentForManager2(creator.Id); if (users.Count == 0) { Log.ErrorFormat(StrEmailForAppointmentManagerAcceptParent2NotFound, creator.Id); return new EmailDto { Error = string.Format(StrEmailForAppointmentManagerAcceptParent2NotFound, creator.Id) }; } foreach (IdNameDto usr in users) { if (string.IsNullOrEmpty(usr.Name)) Log.WarnFormat("No email for manager (id {0})", usr.Id); else { if (string.IsNullOrEmpty(to)) to = usr.Name; else to += ";" + usr.Name; } } /*if (user == null) { Log.ErrorFormat(StrEmailForAppointmentManagerAcceptParent2NotFound, creator.Id); return new EmailDto { Error = string.Format(StrEmailForAppointmentManagerAcceptParent2NotFound, creator.Id) }; } if (string.IsNullOrEmpty(user.Name)) { Log.ErrorFormat(StrEmailForAppointmentManagerAcceptNoEmail, user.Id); return new EmailDto { Error = string.Format(StrEmailForAppointmentManagerAcceptNoEmail, user.Id) }; } to = user.Name;*/ break; case 3: users = AppointmentDao.GetParentForManager3(creator.Id); if (users.Count == 0) { Log.ErrorFormat(StrEmailForAppointmentManagerAcceptParent3NotFound, creator.Id); return new EmailDto { Error = string.Format(StrEmailForAppointmentManagerAcceptParent3NotFound, creator.Id) }; } foreach (IdNameDto usr in users) { if (string.IsNullOrEmpty(usr.Name)) Log.WarnFormat("No email for manager (id {0})", usr.Id); else { if (string.IsNullOrEmpty(to)) to = usr.Name; else to += ";" + usr.Name; } } /*if(user == null) { Log.ErrorFormat(StrEmailForAppointmentManagerAcceptParent3NotFound, creator.Id); return new EmailDto { Error = string.Format(StrEmailForAppointmentManagerAcceptParent3NotFound, creator.Id) }; } if (string.IsNullOrEmpty(user.Name)) { Log.ErrorFormat(StrEmailForAppointmentManagerAcceptNoEmail, user.Id); return new EmailDto { Error = string.Format(StrEmailForAppointmentManagerAcceptNoEmail, user.Id) }; } to = user.Name;*/ break; case 4: users = AppointmentDao.GetParentForManager4Department(creator.Department.Id); if (users.Count == 0) { Log.ErrorFormat(StrEmailForAppointmentManagerAcceptParentNotFound, creator.Id); return new EmailDto { Error = string.Format(StrEmailForAppointmentManagerAcceptParentNotFound, creator.Id) }; } foreach (IdNameDto usr in users) { if (string.IsNullOrEmpty(usr.Name)) Log.WarnFormat("No email for manager (id {0})", usr.Id); else { if (string.IsNullOrEmpty(to)) to = usr.Name; else to += ";" + usr.Name; } } break; case 5: case 6: users = AppointmentDao.GetForManagersParentDepartment(creator.Department.Id); if (users.Count == 0) { Log.ErrorFormat(StrEmailForAppointmentManagerAcceptParentNotFound, creator.Id); return new EmailDto { Error = string.Format(StrEmailForAppointmentManagerAcceptParentNotFound, creator.Id) }; } foreach (IdNameDto usr in users) { if (string.IsNullOrEmpty(usr.Name)) Log.WarnFormat("No email for manager (id {0})", usr.Id); else { if (string.IsNullOrEmpty(to)) to = usr.Name; else to += ";"+ usr.Name; } } break; default: throw new ArgumentException(string.Format(StrEmailForAppointmentManagerAcceptIncorrectManagerLevel, creator.Id)); } break; default: throw new ArgumentException(string.Format(StrEmailForAppointmentManagerAcceptIncorrectRole, creator.Id)); } if (string.IsNullOrEmpty(to)) { Log.ErrorFormat(StrEmailForAppointmentManagerAcceptNoEmails, creator.Id); return new EmailDto { Error = string.Format(StrEmailForAppointmentManagerAcceptNoEmails, creator.Id) }; } string body; string subject = GetSubjectAndBodyForAppointmentManagerAcceptRequest(creator, entity, out body); return SendEmail(to, subject, body); #endregion }
protected EmailDto SendEmailForAppointmentChiefAccept(User chief, Appointment entity) { string staffManagerEmail = ConfigurationService.AppointmentStaffManagerEmail; if (string.IsNullOrEmpty(staffManagerEmail)) throw new ValidationException(StrEmailForStaffManagerNotFound); string body; string subject = GetSubjectAndBodyForAppointmentManagerAcceptRequest(chief, entity, out body); return SendEmail(staffManagerEmail, subject, body); }
protected void RejectAppointment(Appointment entity) { entity.AcceptChief = null; entity.AcceptManager = null; entity.AcceptStaff = null; entity.BankAccountantAccept = null; entity.ChiefDateAccept = null; entity.ManagerDateAccept = null; entity.StaffDateAccept = null; }
protected string GetSubjectAndBodyForAppointmentRejectRequest(User user, Appointment entity, out string body) { DepartmentDto dep3 = AppointmentDao.GetDepartmentForPathAndLevel(entity.Department.Path, 3); if (dep3 == null) Log.ErrorFormat(StrEmailForAppointmentManagerAcceptDepartment3NotFound, entity.Department.Id); body = string.Format(StrEmailForAppointmentManagerRejectText, entity.Number, entity.PositionName, dep3 == null ? "<не найдена в базе данных>" : dep3.Name, user.FullName); const string subject = StrEmailForAppointmentManagerRejectSubject; return subject; }
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)); } }