public MessageResult Approve(ChangeShiftApprovalModel changeShiftApprovalModel) { MessageResult msgResult = new MessageResult(); try { SPWeb spWeb = SPContext.Current.Web; if (changeShiftApprovalModel.Id > 0) { Biz.Models.ChangeShiftManagement changeShiftManagement = _changeShiftManagementDAL.GetByID(changeShiftApprovalModel.Id); string currentApprovalStatus = !string.IsNullOrEmpty(changeShiftManagement.ApprovalStatus) ? changeShiftManagement.ApprovalStatus.ToLower() : string.Empty; if (currentApprovalStatus == ApprovalStatus.Approved.ToLower() || currentApprovalStatus == ApprovalStatus.Cancelled.ToLower() || currentApprovalStatus == ApprovalStatus.Rejected.ToLower()) { return(new MessageResult { Code = (int)ChangeShiftErrorCode.CannotApprove, Message = MessageResultHelper.GetRequestStatusMessage(currentApprovalStatus), ObjectId = 0 }); } string requestExpiredMsg = MessageResultHelper.GetRequestExpiredMessage(changeShiftManagement.RequestDueDate); if (!string.IsNullOrEmpty(requestExpiredMsg)) { return(new MessageResult { Code = (int)BusinessTripErrorCode.CannotApprove, Message = requestExpiredMsg, ObjectId = 0 }); } bool hasApprovalPermission = false; EmployeeInfoDAL _employeeInfoDAL = new EmployeeInfoDAL(spWeb.Url); int approverId = changeShiftApprovalModel.ApproverId; approverId = approverId > 0 ? approverId : changeShiftManagement.DepartmentHead.ID; EmployeeInfo currentApprover = _employeeInfoDAL.GetByADAccount(approverId); if (currentApprover != null) { if (currentApprover.ADAccount.ID == spWeb.CurrentUser.ID) { hasApprovalPermission = true; } else { Delegation delegation = DelegationPermissionManager.IsDelegation(currentApprover.ID, StringConstant.ChangeShiftList.ListUrl, changeShiftManagement.ID); if (delegation != null) { hasApprovalPermission = true; } } } if (hasApprovalPermission == true) { changeShiftManagement.ApprovalStatus = ApprovalStatus.Approved; changeShiftManagement.Comment = changeShiftApprovalModel.Comment; var approver = spWeb.AllUsers.GetByID(approverId); changeShiftManagement.DepartmentHead = new User { UserName = approver.LoginName, FullName = approver.Name }; _changeShiftManagementDAL.SaveItem(changeShiftManagement); // Send approval email to employee SendEmail(spWeb.Url, changeShiftApprovalModel.Id, "ChangeShift_Approve", changeShiftApprovalModel.ApproverName); } } } catch (Exception ex) { msgResult.Code = (int)ChangeShiftErrorCode.Unexpected; msgResult.Message = ex.Message; } return(msgResult); }
public MessageResult ApproveVehicle(VehicleApprovalModel vehicleApprovalModel) { MessageResult msgResult = new MessageResult(); try { SPWeb spWeb = SPContext.Current.Web; if (vehicleApprovalModel.Id > 0) { Biz.Models.VehicleManagement vehicleManagement = _vehicleManagementDAL.GetByID(vehicleApprovalModel.Id); string currentApprovalStatus = vehicleManagement.ApprovalStatus.ToLower(); if (currentApprovalStatus == ApprovalStatus.Approved.ToLower() || currentApprovalStatus == ApprovalStatus.Cancelled.ToLower() || currentApprovalStatus == ApprovalStatus.Rejected.ToLower()) { return(new MessageResult { Code = (int)VehicleErrorCode.CannotApprove, Message = MessageResultHelper.GetRequestStatusMessage(currentApprovalStatus), ObjectId = 0 }); } string requestExpiredMsg = MessageResultHelper.GetRequestExpiredMessage(vehicleManagement.RequestDueDate); if (!string.IsNullOrEmpty(requestExpiredMsg)) { return(new MessageResult { Code = (int)VehicleErrorCode.CannotApprove, Message = requestExpiredMsg, ObjectId = 0 }); } bool hasApprovalPermission = HasApprovalPermission(vehicleApprovalModel.Id.ToString()); DelegationModel delegationModel = GetDelegatedTaskInfo(vehicleApprovalModel.Id.ToString()); bool isDelegated = (delegationModel != null && delegationModel.Requester.LookupId > 0) ? true : false; if (hasApprovalPermission == false && isDelegated == false) { return(msgResult); } EmployeeInfoDAL _employeeInfoDAL = new EmployeeInfoDAL(spWeb.Url); EmployeeInfo approverInfo = _employeeInfoDAL.GetByADAccount(spWeb.CurrentUser.ID); int assigneeId = hasApprovalPermission == true ? approverInfo.ADAccount.ID : (isDelegated == true ? delegationModel.FromEmployee.ID : 0); TaskManagementDAL _taskManagementDAL = new TaskManagementDAL(spWeb.Url); IList <TaskManagement> taskManagementCollection = _taskManagementDAL.GetRelatedTasks(vehicleManagement.ID, StepModuleList.VehicleManagement.ToString()); if (taskManagementCollection != null && taskManagementCollection.Count > 0) { TaskManagement taskOfOriginalAssignee = _taskManagementDAL.GetTaskByAssigneeId(taskManagementCollection, assigneeId); List <TaskManagement> relatedTasks = taskManagementCollection.Where(t => t.ID != taskOfOriginalAssignee.ID).ToList(); User nextAssignee = taskOfOriginalAssignee.NextAssign; if (hasApprovalPermission == true) { taskOfOriginalAssignee.TaskStatus = TaskStatusList.Completed.ToString(); taskOfOriginalAssignee.PercentComplete = 1; taskOfOriginalAssignee.TaskOutcome = TaskOutcome.Approved.ToString(); taskOfOriginalAssignee.Description = vehicleApprovalModel.Comment; _taskManagementDAL.CloseTasks(relatedTasks); _taskManagementDAL.SaveItem(taskOfOriginalAssignee); } else if (isDelegated == true) { TaskManagement clonedTask = _taskManagementDAL.CloneTask(taskOfOriginalAssignee); clonedTask.AssignedTo = approverInfo.ADAccount; clonedTask.TaskStatus = TaskStatusList.Completed.ToString(); clonedTask.PercentComplete = 1; clonedTask.TaskOutcome = TaskOutcome.Approved.ToString(); clonedTask.Description = vehicleApprovalModel.Comment; relatedTasks.Add(taskOfOriginalAssignee); _taskManagementDAL.CloseTasks(relatedTasks); _taskManagementDAL.SaveItem(clonedTask); } if (!string.IsNullOrEmpty(vehicleApprovalModel.Comment)) { vehicleManagement.CommonComment = vehicleManagement.CommonComment.BuildComment(string.Format("{0}: {1}", approverInfo.FullName, vehicleApprovalModel.Comment)); } if (nextAssignee == null) { vehicleManagement.ApprovalStatus = StringConstant.ApprovalStatus.Approved.ToString(); _vehicleManagementDAL.SaveOrUpdate(spWeb, vehicleManagement); EmailTemplateDAL _emailTemplateDAL = new EmailTemplateDAL(spWeb.Url); EmailTemplate emailTemplate = _emailTemplateDAL.GetByKey("VehicleManagement_Approve"); EmployeeInfo toUser = _employeeInfoDAL.GetByID(vehicleManagement.Requester.LookupId); _vehicleManagementDAL.SendEmail(vehicleManagement, emailTemplate, approverInfo, toUser, VehicleTypeOfEmail.Approve, spWeb.Url); } else if (nextAssignee != null && taskManagementCollection != null && taskManagementCollection.Count > 0) { _vehicleManagementDAL.RunWorkFlow(vehicleManagement, taskOfOriginalAssignee); EmailTemplateDAL _emailTemplateDAL = new EmailTemplateDAL(spWeb.Url); EmailTemplate emailTemplate = _emailTemplateDAL.GetByKey("VehicleManagement_Request"); EmployeeInfo toUser = _employeeInfoDAL.GetByADAccount(nextAssignee.ID); _vehicleManagementDAL.SendEmail(vehicleManagement, emailTemplate, approverInfo, toUser, VehicleTypeOfEmail.Request, spWeb.Url); try { List <EmployeeInfo> toUsers = DelegationPermissionManager.GetListOfDelegatedEmployees(toUser.ID, StringConstant.VehicleManagementList.ListUrl, vehicleManagement.ID); _vehicleManagementDAL.SendDelegationEmail(vehicleManagement, emailTemplate, toUsers, spWeb.Url); } catch { } } } } } catch (Exception ex) { msgResult.Code = (int)VehicleErrorCode.Unexpected; msgResult.Message = ex.Message; } return(msgResult); }
public MessageResult CancelBusinessTrip(string Id) { if (!string.IsNullOrEmpty(Id)) { try { Biz.Models.BusinessTripManagement businessTripManagement = _businessTripManagementDAL.GetByID(Convert.ToInt32(Id)); if (businessTripManagement.ID > 0) { string currentApprovalStatus = businessTripManagement.ApprovalStatus.ToLower(); if (businessTripManagement.CreatedBy.ID == businessTripManagement.ModifiedBy.ID && businessTripManagement.CreatedBy.ID == SPContext.Current.Web.CurrentUser.ID && (currentApprovalStatus != ApprovalStatus.Approved.ToLower() && currentApprovalStatus != ApprovalStatus.Cancelled.ToLower() && currentApprovalStatus != ApprovalStatus.Rejected.ToLower())) { TaskManagementDAL _taskManagementDAL = new TaskManagementDAL(SPContext.Current.Site.Url); IList <TaskManagement> taskManagementCollection = _taskManagementDAL.GetRelatedTasks(businessTripManagement.ID, StepModuleList.BusinessTripManagement.ToString()); if (taskManagementCollection != null && taskManagementCollection.Count > 0) { _taskManagementDAL.CloseTasks(taskManagementCollection.ToList()); } businessTripManagement.ApprovalStatus = StringConstant.ApprovalStatus.Cancelled; _businessTripManagementDAL.SaveOrUpdate(SPContext.Current.Web, businessTripManagement); } else { return(new MessageResult { Code = (int)BusinessTripErrorCode.CannotCancel, Message = MessageResultHelper.GetRequestStatusMessage(businessTripManagement.ApprovalStatus.ToLower()), ObjectId = 0 }); } } } catch (Exception ex) { return(new MessageResult { Code = (int)BusinessTripErrorCode.Unexpected, Message = ex.Message, ObjectId = 0 }); } } else { return(new MessageResult { Code = (int)BusinessTripErrorCode.Unexpected, Message = "Cannot find the item", ObjectId = 0 }); } return(new MessageResult { Code = 0, Message = "Successful", ObjectId = 0 }); }
public MessageResult RejectBusinessTrip(BusinessTripManagementModel businessTripManagementModel) { MessageResult msgResult = new MessageResult(); try { SPWeb spWeb = SPContext.Current.Web; if (businessTripManagementModel.Id > 0) { Biz.Models.BusinessTripManagement businessTripManagement = _businessTripManagementDAL.GetByID(businessTripManagementModel.Id); string currentApprovalStatus = businessTripManagement.ApprovalStatus.ToLower(); if (currentApprovalStatus == ApprovalStatus.Approved.ToLower() || currentApprovalStatus == ApprovalStatus.Cancelled.ToLower() || currentApprovalStatus == ApprovalStatus.Rejected.ToLower()) { return(new MessageResult { Code = (int)BusinessTripErrorCode.CannotReject, Message = MessageResultHelper.GetRequestStatusMessage(currentApprovalStatus), ObjectId = 0 }); } string requestExpiredMsg = MessageResultHelper.GetRequestExpiredMessage(businessTripManagement.RequestDueDate); if (!string.IsNullOrEmpty(requestExpiredMsg)) { return(new MessageResult { Code = (int)BusinessTripErrorCode.CannotReject, Message = requestExpiredMsg, ObjectId = 0 }); } bool hasApprovalPermission = HasApprovalPermission(businessTripManagementModel.Id.ToString()); DelegationModel delegationModel = GetDelegatedTaskInfo(businessTripManagementModel.Id.ToString()); bool isDelegated = (delegationModel != null && delegationModel.Requester.LookupId > 0) ? true : false; if (hasApprovalPermission == false && isDelegated == false) { return(msgResult); } EmployeeInfoDAL _employeeInfoDAL = new EmployeeInfoDAL(spWeb.Url); EmployeeInfo approverInfo = _employeeInfoDAL.GetByADAccount(spWeb.CurrentUser.ID); int assigneeId = hasApprovalPermission == true ? approverInfo.ADAccount.ID : (isDelegated == true ? delegationModel.FromEmployee.ID : 0); TaskManagementDAL _taskManagementDAL = new TaskManagementDAL(spWeb.Url); IList <TaskManagement> taskManagementCollection = _taskManagementDAL.GetRelatedTasks(businessTripManagement.ID, StepModuleList.BusinessTripManagement.ToString()); if (taskManagementCollection != null && taskManagementCollection.Count > 0) { TaskManagement taskOfOriginalAssignee = _taskManagementDAL.GetTaskByAssigneeId(taskManagementCollection, assigneeId); List <TaskManagement> relatedTasks = taskManagementCollection.Where(t => t.ID != taskOfOriginalAssignee.ID).ToList(); if (hasApprovalPermission == true) { taskOfOriginalAssignee.TaskStatus = TaskStatusList.Completed.ToString(); taskOfOriginalAssignee.PercentComplete = 1; taskOfOriginalAssignee.TaskOutcome = TaskOutcome.Rejected.ToString(); taskOfOriginalAssignee.Description = businessTripManagementModel.Comment; _taskManagementDAL.CloseTasks(relatedTasks); _taskManagementDAL.SaveItem(taskOfOriginalAssignee); } else if (isDelegated == true) { TaskManagement clonedTask = _taskManagementDAL.CloneTask(taskOfOriginalAssignee); clonedTask.AssignedTo = approverInfo.ADAccount; clonedTask.TaskStatus = TaskStatusList.Completed.ToString(); clonedTask.PercentComplete = 1; clonedTask.TaskOutcome = TaskOutcome.Rejected.ToString(); clonedTask.Description = businessTripManagementModel.Comment; relatedTasks.Add(taskOfOriginalAssignee); _taskManagementDAL.CloseTasks(relatedTasks); _taskManagementDAL.SaveItem(clonedTask); } } if (!string.IsNullOrEmpty(businessTripManagementModel.Comment)) { businessTripManagement.Comment = businessTripManagement.Comment.BuildComment(string.Format("{0}: {1}", approverInfo.FullName, businessTripManagementModel.Comment)); } businessTripManagement.ApprovalStatus = ApprovalStatus.Rejected.ToString(); _businessTripManagementDAL.SaveOrUpdate(spWeb, businessTripManagement); EmailTemplateDAL _emailTemplateDAL = new EmailTemplateDAL(spWeb.Url); EmailTemplate emailTemplate = _emailTemplateDAL.GetByKey("BusinessTripManagement_Reject"); EmployeeInfo toUser = _employeeInfoDAL.GetByID(businessTripManagement.Requester.LookupId); _businessTripManagementDAL.SendEmail(businessTripManagement, emailTemplate, approverInfo, toUser, spWeb.Url, false); } } catch (Exception ex) { msgResult.Code = (int)BusinessTripErrorCode.Unexpected; msgResult.Message = ex.Message; } return(msgResult); }
public MessageResult InsertBusinessTripManagement(BusinessTripManagementModel businessTripManagementModel) { MessageResult msgResult = new MessageResult(); try { SPWeb spWeb = SPContext.Current.Web; if (businessTripManagementModel.Id > 0) { Biz.Models.BusinessTripManagement businessTripObj = _businessTripManagementDAL.GetByID(businessTripManagementModel.Id); if (businessTripObj.ModifiedBy.ID != businessTripObj.CreatedBy.ID && businessTripObj.ApprovalStatus.ToLower() != ApprovalStatus.Rejected.ToLower()) { return(new MessageResult { Code = (int)BusinessTripErrorCode.CannotUpdate, Message = MessageResultHelper.GetRequestStatusMessage(businessTripObj.ApprovalStatus), ObjectId = 0 }); } } Biz.Models.BusinessTripManagement businessTripManagement = businessTripManagementModel.ToEntity(); if (businessTripManagementModel.Id <= 0) { AdditionalEmployeePositionDAL _additionalEmployeePositionDAL = new AdditionalEmployeePositionDAL(SPContext.Current.Site.Url); if (businessTripManagementModel.Driver == null || (businessTripManagementModel.Driver != null && businessTripManagementModel.Driver.LookupId == 0)) { List <Biz.Models.AdditionalEmployeePosition> drivers = _additionalEmployeePositionDAL.GetEmployeesByLevel((int)StringConstant.AdditionalEmployeePosition.Driver, StepModuleList.BusinessTripManagement.ToString()); if (drivers != null && drivers.Count > 0) { businessTripManagement.Driver = new LookupItem() { LookupId = drivers[0].Employee.LookupId, LookupValue = drivers[0].Employee.LookupValue }; } } if (businessTripManagement.Cashier == null || (businessTripManagement.Cashier != null && businessTripManagement.Cashier.LookupId == 0)) { List <Biz.Models.AdditionalEmployeePosition> accountants = _additionalEmployeePositionDAL.GetEmployeesByLevel((int)StringConstant.AdditionalEmployeePosition.Accountant, StepModuleList.BusinessTripManagement.ToString()); if (accountants != null && accountants.Count > 0) { businessTripManagement.Cashier = new LookupItem() { LookupId = accountants[0].Employee.LookupId, LookupValue = accountants[0].Employee.LookupValue }; } } } DateTime startTripDate = DateTime.Now; List <BusinessTripSchedule> businessTripScheduleCollection = new List <BusinessTripSchedule>(); if (businessTripManagementModel.ScheduleList != null && businessTripManagementModel.ScheduleList.Count > 0) { foreach (BusinessTripScheduleModel businessTripScheduleModel in businessTripManagementModel.ScheduleList) { BusinessTripSchedule businessTripSchedule = businessTripScheduleModel.ToEntity(); businessTripScheduleCollection.Add(businessTripSchedule); } startTripDate = businessTripScheduleCollection.Select(e => e.DepartDate).Min().Value; } businessTripManagement = _businessTripManagementDAL.SetDueDate(businessTripManagement, startTripDate); int itemId = _businessTripManagementDAL.SaveOrUpdate(spWeb, businessTripManagement); if (itemId > 0) { if (businessTripManagementModel.EmployeeList != null && businessTripManagementModel.EmployeeList.Count > 0) { // Edit -> DELETE all details -> Insert new items if (businessTripManagementModel.Id > 0) { List <BusinessTripEmployeeDetail> businessTripEmployeeDetails = _businessTripEmployeeDetailDAL.GetItemsByParentId(businessTripManagementModel.Id); _businessTripEmployeeDetailDAL.DeleteItems(businessTripEmployeeDetails.Select(x => x.ID).ToList()); } List <BusinessTripEmployeeDetail> businessTripEmployeeDetailCollection = new List <BusinessTripEmployeeDetail>(); foreach (BusinessTripEmployeeModel employee in businessTripManagementModel.EmployeeList) { BusinessTripEmployeeDetail businessTripEmployeeDetail = new BusinessTripEmployeeDetail(); businessTripEmployeeDetail.BusinessTripManagementID = new LookupItem() { LookupId = itemId }; businessTripEmployeeDetail.Employee = new LookupItem { LookupId = employee.EmployeeId, LookupValue = employee.EmployeeCode }; businessTripEmployeeDetailCollection.Add(businessTripEmployeeDetail); } _businessTripEmployeeDetailDAL.SaveOrUpdate(spWeb, businessTripEmployeeDetailCollection); } if (businessTripManagementModel.ScheduleList != null && businessTripManagementModel.ScheduleList.Count > 0) { // Edit -> DELETE all details -> Insert new items if (businessTripManagementModel.Id > 0) { List <BusinessTripSchedule> businessTripSchedules = _businessTripScheduleDAL.GetItemsByParentId(businessTripManagementModel.Id); _businessTripScheduleDAL.DeleteItems(businessTripSchedules.Select(x => x.ID).ToList()); } foreach (BusinessTripSchedule businessTripSchedule in businessTripScheduleCollection) { businessTripSchedule.ID = 0; businessTripSchedule.BusinessTripManagementID = new LookupItem() { LookupId = itemId }; } _businessTripScheduleDAL.SaveOrUpdate(spWeb, businessTripScheduleCollection); } } businessTripManagement = _businessTripManagementDAL.GetByID(itemId); if ((businessTripManagementModel.Id <= 0 && itemId > 0)) { _businessTripManagementDAL.StartWorkFlow(businessTripManagement); } } catch (Exception ex) { msgResult.Code = (int)BusinessTripErrorCode.Unexpected; msgResult.Message = ex.Message; } return(msgResult); }
public MessageResult Reject(NotOverTimeApprovalModel notOverTimeApprovalModel) { MessageResult msgResult = new MessageResult(); try { SPWeb spWeb = SPContext.Current.Web; if (notOverTimeApprovalModel.Id > 0) { Biz.Models.NotOvertimeManagement notOvertimeManagement = _notOvertimeManagementDAL.GetByID(notOverTimeApprovalModel.Id); string currentApprovalStatus = !string.IsNullOrEmpty(notOvertimeManagement.ApprovalStatus) ? notOvertimeManagement.ApprovalStatus.ToLower() : string.Empty; if (currentApprovalStatus == ApprovalStatus.Approved.ToLower() || currentApprovalStatus == ApprovalStatus.Cancelled.ToLower() || currentApprovalStatus == ApprovalStatus.Rejected.ToLower()) { return new MessageResult { Code = (int)NotOverTimeErrorCode.CannotReject, Message = MessageResultHelper.GetRequestStatusMessage(currentApprovalStatus), ObjectId = 0 }; } string requestExpiredMsg = MessageResultHelper.GetRequestExpiredMessage(notOvertimeManagement.RequestDueDate); if (!string.IsNullOrEmpty(requestExpiredMsg)) { return new MessageResult { Code = (int)NotOverTimeErrorCode.CannotReject, Message = requestExpiredMsg, ObjectId = 0 }; } bool hasRejectPermission = false; EmployeeInfoDAL _employeeInfoDAL = new EmployeeInfoDAL(spWeb.Url); int approverId = notOverTimeApprovalModel.ApproverId; approverId = approverId > 0 ? approverId : notOvertimeManagement.DH.ID; EmployeeInfo currentApprover = _employeeInfoDAL.GetByADAccount(approverId); if (currentApprover != null) { if (currentApprover.ADAccount.ID == spWeb.CurrentUser.ID) { hasRejectPermission = true; } else { Delegation delegation = DelegationPermissionManager.IsDelegation(currentApprover.ID, StringConstant.NotOvertimeList.ListUrl, notOvertimeManagement.ID); if (delegation != null) { hasRejectPermission = true; } } } if (hasRejectPermission == true) { notOvertimeManagement.ApprovalStatus = ApprovalStatus.Rejected; notOvertimeManagement.Comment = notOverTimeApprovalModel.Comment; var approver = spWeb.AllUsers.GetByID(approverId); notOvertimeManagement.DH = new User { UserName = approver.LoginName, FullName = approver.Name }; _notOvertimeManagementDAL.SaveItem(notOvertimeManagement); // Send reject email to employee SendEmail(spWeb.Url, notOverTimeApprovalModel.Id, "LOAbsence_Reject", notOverTimeApprovalModel.ApproverName); } } } catch (Exception ex) { msgResult.Code = (int)NotOverTimeErrorCode.Unexpected; msgResult.Message = ex.Message; } return msgResult; }