/// <summary> /// Processes the leave request approval status change hr. /// </summary> /// <param name="leaveRequestInfo">The leave request information.</param> /// <returns></returns> public string ProcessLeaveRequestApprovalStatusChangeHr(ILeaveRequestViewModel leaveRequestInfo) { // get the user that's logged in...this user should ideally be the Hr admin for the company var currentUserId = (int)session.GetSessionValue(SessionKey.UserId); return(ProcessLeaveRequestApprovalStatusChange(leaveRequestInfo, currentUserId)); }
/// <summary> /// Processes the leave request approval status change supervisor. /// </summary> /// <param name="leaveRequestInfo">The leave request information.</param> /// <returns></returns> public string ProcessLeaveRequestApprovalStatusChangeSupervisor(ILeaveRequestViewModel leaveRequestInfo) { // get the user that's logged in...this user should ideally be the supervisor var currentUserId = (int)session.GetSessionValue(SessionKey.UserId); var currentUser = usersRepository.GetUserById(currentUserId); // use the current user's email to get their employee record var currentEmployee = employeeRepository.GetEmployeeByEmail(currentUser.Email); return(ProcessLeaveRequestApprovalStatusChange(leaveRequestInfo, supervisorId: currentEmployee.EmployeeId)); }
/// <summary> /// Saves the leave request information. /// </summary> /// <param name="leaveRequestModelInfo">The leave request model information.</param> /// <returns></returns> /// <exception cref="ArgumentNullException">leaveRequestModelInfo</exception> public string SaveLeaveRequestInfo(ILeaveRequestViewModel leaveRequestModelInfo) { if (leaveRequestModelInfo == null) { throw new ArgumentNullException(nameof(leaveRequestModelInfo)); } var result = string.Empty; var newLeaveRequest = new LeaveRequest { EmployeeID = leaveRequestModelInfo.EmployeeID, LeaveTypeID = leaveRequestModelInfo.LeaveTypeID, DateLeaveStart = leaveRequestModelInfo.DateLeaveStart, DateLeaveEnds = leaveRequestModelInfo.DateLeaveEnds, Comment = leaveRequestModelInfo.Comment, LeaveStatusID = 3, DateRequested = DateTime.Now, DateCreated = DateTime.Now, CompanyID = leaveRequestModelInfo.CompanyId, }; try { using ( var dbContext = (HRMSEntities)this.dbContextFactory.GetDbContext(ObjectContextType.HRMS)) { dbContext.LeaveRequests.Add(newLeaveRequest); dbContext.SaveChanges(); } } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { //result = string.Format("SaveEmploymentHistoryInfo - {0} , {1}", e.Message, //e.InnerException != null ? e.InnerException.Message : ""); Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); // raise a new exception nesting // the current instance as InnerException raise = new InvalidOperationException(message, raise); } } throw raise; } return(result); }
/// <summary> /// Creates the leave request update view. /// </summary> /// <param name="leaveRequestInfo">The leave request information.</param> /// <param name="viewModelData">The view model data.</param> /// <returns></returns> public ILeaveRequestViewModel CreateLeaveRequestUpdateView(ILeaveRequestViewModel leaveRequestInfo, Hashtable viewModelData) { // Extract relevant data from the viewModelData var leaveTypeCollection = viewModelData["leaveTypeCollection"] as List <ILeaveType>; var leaveStatusCollection = viewModelData["leaveStatusCollection"] as List <ILeaveStatus>; var processingMessage = (string)viewModelData["processingMessage"]; var employeeName = (string)viewModelData["employeeName"]; var approvingAuthorityName = (string)viewModelData["approvingAuthorityName"]; var hrApproverName = (string)viewModelData["hrApproverName"]; var leaveStatusName = (string)viewModelData["leaveStatusName"]; var leaveTypeName = (string)viewModelData["leaveTypeName"]; var annualLeaveDuration = (int)viewModelData["annualLeaveDuration"]; var employeeId = (int)viewModelData["employeeId"]; // Get the dropdown list items var leaveTypeDDL = GetDropDownList.LeaveTypeListItems(leaveTypeCollection, leaveRequestInfo.LeaveTypeID); var leaveStatusDDL = GetDropDownList.LeaveStatusListItems(leaveStatusCollection, leaveRequestInfo.LeaveStatusID); var viewModel = new LeaveRequestViewModel { ProcessingMessage = processingMessage, LeaveTypeDropDown = leaveTypeDDL, LeaveStatusDropDown = leaveStatusDDL, LeaveID = leaveRequestInfo.LeaveID, EmployeeID = leaveRequestInfo.EmployeeID, LeaveTypeID = leaveRequestInfo.LeaveTypeID, DateLeaveStart = leaveRequestInfo.DateLeaveStart, DateLeaveEnds = leaveRequestInfo.DateLeaveEnds, Comment = leaveRequestInfo.Comment, LeaveStatusID = leaveRequestInfo.LeaveStatusID, DateRequested = leaveRequestInfo.DateRequested, ApprovingAuthorityID = leaveRequestInfo.ApprovingAuthorityID, HRApproverID = leaveRequestInfo.HRApproverID, ApprovingAuthorityComment = leaveRequestInfo.ApprovingAuthorityComment, HRApproverComment = leaveRequestInfo.HRApproverComment, DateApprovedDept = leaveRequestInfo.DateApprovedDept, DateApprovedHR = leaveRequestInfo.DateApprovedHR, DateCreated = leaveRequestInfo.DateCreated, EmployeeName = employeeName, ApprovingAuthorityName = approvingAuthorityName, HRApproverName = hrApproverName, LeaveStatusName = leaveStatusName, LeaveTypeName = leaveTypeName, AnnualLeaveDuration = annualLeaveDuration }; return(viewModel); }
/// <summary> /// Gets the leave request update view. /// </summary> /// <param name="leaveRequestInfo">The leave request information.</param> /// <param name="message">The message.</param> /// <returns></returns> /// <exception cref="ArgumentNullException">leaveRequestInfo</exception> public ILeaveRequestViewModel GetLeaveRequestUpdateView(ILeaveRequestViewModel leaveRequestInfo, string message) { if (leaveRequestInfo == null) { throw new ArgumentNullException(nameof(leaveRequestInfo)); } // get necessary data to build the view model for this leave request var viewModelData = new Hashtable(); viewModelData.Add("processingMessage", message); var leaveStatusCollection = leaveRepository.GetLeaveStatusList(); viewModelData.Add("leaveStatusCollection", leaveStatusCollection); var employee = employeeRepository.GetOnBoarderById(leaveRequestInfo.EmployeeID); var employeeGrade = gradeRepository.GetGradeById(employee.GradeId); var leaveTypeCollection = leaveRepository.GetLeaveTypeListForCompanyId(employee.CompanyId); viewModelData.Add("leaveTypeCollection", leaveTypeCollection); viewModelData.Add("employeeId", employee.EmployeeId); viewModelData.Add("employeeName", employee.FirstName + " " + employee.LastName); viewModelData.Add("hrApproverName", null); viewModelData.Add("approvingAuthorityName", null); viewModelData.Add("annualLeaveDuration", employeeGrade.AnnualLeaveDuration); if (leaveRequestInfo.HRApproverID != null) { int hrApproverId = leaveRequestInfo.HRApproverID ?? -1; var hrApprover = usersRepository.GetUserById(hrApproverId); viewModelData["hrApproverName"] = hrApprover.FirstName + " " + hrApprover.LastName; } if (leaveRequestInfo.ApprovingAuthorityID != null) { int approvingAuthorityId = leaveRequestInfo.HRApproverID ?? -1; var approvingAuthority = employeeRepository.GetOnBoarderById(approvingAuthorityId); viewModelData["approvingAuthorityName"] = approvingAuthority.FirstName + " " + approvingAuthority.LastName; } var viewModel = leaveRequestViewModelFactory.CreateLeaveRequestUpdateView(leaveRequestInfo, viewModelData); return(viewModel); }
/// <summary> /// Processes the leave request create. /// </summary> /// <param name="leaveRequestInfo">The leave request information.</param> /// <returns></returns> /// <exception cref="ArgumentNullException">leaveRequestInfo</exception> public string ProcessLeaveRequestCreate(ILeaveRequestViewModel leaveRequestInfo) { if (leaveRequestInfo == null) { throw new ArgumentNullException(nameof(leaveRequestInfo)); } string processingMessage = string.Empty; //This date setting segment might end up being removed //Because I repeated it again in the view model factory //And I've not yet decided where it should stay, so it's in both for now leaveRequestInfo.DateRequested = DateTime.Now; leaveRequestInfo.DateCreated = DateTime.Now; var leaveData = this.leaveRepository.GetLatestLeaveRequestByEmployeeId(leaveRequestInfo.EmployeeID); //if (leaveData != null) //{ // if ((leaveData.DateLeaveEnds - leaveData.DateLeaveStart).TotalDays > 0 && leaveData.LeaveStatusId == 1) // { // processingMessage = Messages.LeaveRunning; // return processingMessage; // } // if (leaveData.LeaveStatusId == 3) // { // processingMessage = Messages.LeavePending; // return processingMessage; // } //} processingMessage = leaveRepository.SaveLeaveRequestInfo(leaveRequestInfo); return(processingMessage); }
/// <summary> /// Processes the leave request approval status change. /// </summary> /// <param name="leaveRequestInfo">The leave request information.</param> /// <param name="hrUserId">The hr user identifier.</param> /// <param name="supervisorId">The supervisor identifier.</param> /// <returns></returns> /// <exception cref="ArgumentNullException">leaveRequestInfo</exception> public string ProcessLeaveRequestApprovalStatusChange(ILeaveRequestViewModel leaveRequestInfo, int hrUserId = -1, int supervisorId = -1) { if (leaveRequestInfo == null) { throw new ArgumentNullException(nameof(leaveRequestInfo)); } if (hrUserId >= 0) { leaveRequestInfo.HRApproverID = hrUserId; leaveRequestInfo.DateApprovedHR = DateTime.Now; } else if (supervisorId >= 0) { leaveRequestInfo.ApprovingAuthorityID = supervisorId; leaveRequestInfo.DateApprovedDept = DateTime.Now; } var processingMessage = leaveRepository.UpdateLeaveRequestInfo(leaveRequestInfo); return(processingMessage); }
/// <summary> /// Updates the leave request information. /// </summary> /// <param name="leaveRequestInfo">The leave request information.</param> /// <returns></returns> /// <exception cref="ArgumentNullException">leaveRequestDetails</exception> public string UpdateLeaveRequestInfo(ILeaveRequestViewModel leaveRequestInfo) { var result = string.Empty; try { using ( var dbContext = (HRMSEntities)this.dbContextFactory.GetDbContext(ObjectContextType.HRMS)) { var leaveRequestDetails = dbContext.LeaveRequests.SingleOrDefault(x => x.LeaveID == leaveRequestInfo.LeaveID); if (leaveRequestDetails == null) { throw new ArgumentNullException(nameof(leaveRequestDetails)); } // Store the leaveRequestViewModel in the database leaveRequestDetails.DateLeaveStart = leaveRequestInfo.DateLeaveStart; leaveRequestDetails.DateLeaveEnds = leaveRequestInfo.DateLeaveEnds; leaveRequestDetails.LeaveStatusID = leaveRequestInfo.LeaveStatusID; leaveRequestDetails.DateApprovedHR = DateTime.UtcNow; leaveRequestDetails.HRApproverComment = leaveRequestInfo.HRApproverComment; leaveRequestDetails.HRApproverID = leaveRequestInfo.HRApproverID; dbContext.SaveChanges(); } } catch (Exception e) { result = string.Format("Update Leave Request- {0} , {1}", e.Message, e.InnerException != null ? e.InnerException.Message : ""); } return(result); }