public void Should_Map_LeaveReuquestDto_to_LeaveRequest() { // Arrange var _mLeaveRequest = new Mock <LeaveRequest>(); var leaveRequestDto = new LeaveRequestDto { IsActive = true, EmployeeId = null, AmountRequested = 100, StartDateTime = _testDateTime, EndDateTime = _testDateTime, IsApproved = true, IsTaken = true, LeaveTypeId = 1 }; // Act CommonHelperAppService.MapDtoToEntityForUpdating(leaveRequestDto, _mLeaveRequest.Object); // Assert Assert.AreEqual(leaveRequestDto.IsActive, _mLeaveRequest.Object.IsActive); Assert.AreEqual(leaveRequestDto.EmployeeId, _mLeaveRequest.Object.EmployeeId); Assert.AreEqual(leaveRequestDto.AmountRequested, _mLeaveRequest.Object.AmountRequested); Assert.AreEqual(leaveRequestDto.StartDateTime, _mLeaveRequest.Object.StartDateTime); Assert.AreEqual(leaveRequestDto.EndDateTime, _mLeaveRequest.Object.EndDateTime); Assert.AreEqual(leaveRequestDto.IsApproved, _mLeaveRequest.Object.IsApproved); Assert.AreEqual(leaveRequestDto.IsTaken, _mLeaveRequest.Object.IsTaken); Assert.AreEqual(leaveRequestDto.LeaveTypeId, _mLeaveRequest.Object.LeaveTypeId); }
/// <summary> /// 请假申请 /// </summary> public void Request(LeaveRequestDto input) { CheckCanRequest(input); var leave = new LeaveOrder { ApplicantId = input.LeaveerId, LeaveerId = input.LeaveerId, StartTime = input.StartTime, EndOfTime = input.EndOfTime, LeaveDays = input.LeaveDays, LeaveType = input.LeaveType, Reason = input.ReasonForLeave, AttachmentsPath = input.AttachmentsPath, Status = "0" }; foreach (var item in input.Approvers) { AddAndSave(new LeaveApprove { ApproverId = item, OrderId = leave.Id, ApproveLevel = 1 }); } AddAndSave(leave); SaveChanges(); }
public static void MapDtoToEntityForUpdating(LeaveRequestDto leaveRequestDto, LeaveRequest leaveRequest) { leaveRequest.IsActive = leaveRequestDto.IsActive; leaveRequest.StartDateTime = leaveRequestDto.StartDateTime; leaveRequest.EndDateTime = leaveRequestDto.EndDateTime; leaveRequest.AmountRequested = leaveRequestDto.AmountRequested; leaveRequest.EmployeeId = leaveRequestDto.EmployeeId; leaveRequest.LeaveTypeId = leaveRequestDto.LeaveTypeId; leaveRequest.Notes = leaveRequestDto.Notes; leaveRequest.IsApproved = leaveRequestDto.IsApproved; leaveRequest.IsTaken = leaveRequestDto.IsTaken; }
public static void SendLeaveRequestEmail(LeaveRequestDto leaveRequestDto) { var leaveRequestEmailDto = new LeaveRequestEmailDto { RecipientAddress = "*****@*****.**", StaffName = leaveRequestDto.StaffName, LeaveTypName = leaveRequestDto.LeaveTypeName, StartDateTime = leaveRequestDto.StartDateTime.ToString(), EndDateTime = leaveRequestDto.EndDateTime.ToString(), AmountRequested = leaveRequestDto.AmountRequested.ToString(), Notes = leaveRequestDto.Notes }; var msg = CommonSetup(leaveRequestEmailDto.RecipientAddress, EmailType.LeaveRequest); msg.Body = CompileMessageBody(leaveRequestEmailDto); PostEmail(msg); }
private bool CheckIfStaffOnTraining(LeaveRequestDto leaveRequestDto) { long?shiftStaffId = null; shiftStaffId = _unitOfWork.LeaveRequestRepository.Get(t => t.EmployeeId == leaveRequestDto.EmployeeId && t.IsActive && (((t.StartDateTime >= leaveRequestDto.StartDateTime && t.StartDateTime <= leaveRequestDto.EndDateTime) && (t.EndDateTime >= leaveRequestDto.EndDateTime)) || (t.StartDateTime <= leaveRequestDto.StartDateTime && t.EndDateTime >= leaveRequestDto.EndDateTime) || (t.StartDateTime >= leaveRequestDto.StartDateTime && t.EndDateTime <= leaveRequestDto.EndDateTime) || ((t.StartDateTime <= leaveRequestDto.StartDateTime) && (t.EndDateTime >= leaveRequestDto.StartDateTime && t.EndDateTime <= leaveRequestDto.EndDateTime)))) .Select(t => t.EmployeeId) .FirstOrDefault(); if (shiftStaffId != null) { return(true); } return(false); }
// Private Methods private bool CheckIfStaffOnShift(LeaveRequestDto leaveRequestDto) { long?shiftStaffId = null; // check if staff member is on a shift already shiftStaffId = _unitOfWork.ShiftRepository.Get(s => s.EmployeeId == leaveRequestDto.EmployeeId && s.IsActive && (((s.StartDate >= leaveRequestDto.StartDateTime && s.StartDate <= leaveRequestDto.EndDateTime) && (s.EndDate >= leaveRequestDto.EndDateTime)) || (s.StartDate <= leaveRequestDto.StartDateTime && s.EndDate >= leaveRequestDto.EndDateTime) || (s.StartDate >= leaveRequestDto.StartDateTime && s.EndDate <= leaveRequestDto.EndDateTime) || ((s.StartDate <= leaveRequestDto.StartDateTime) && (s.EndDate >= leaveRequestDto.StartDateTime && s.EndDate <= leaveRequestDto.EndDateTime)))) .Select(s => s.EmployeeId) .FirstOrDefault(); if (shiftStaffId != null) { return(true); } return(false); }
/// <summary> /// 检查可不可以申请 /// </summary> private void CheckCanRequest(LeaveRequestDto input) { var leaveDays = Convert.ToDecimal(input.LeaveDays); if (leaveDays > 15) { throw new Exception("请假天数不能大于15天!"); } if (!input.Approvers.Any()) { throw new Exception("请先选择审批人!"); } var currentSemesterId = GetCurrentSemesterId(); if (string.IsNullOrEmpty(currentSemesterId)) { throw new Exception("当前学期未设置,请联系管理员!"); } var limit = Query <LeaveLimit>(p => p.SemesterId.Equals(currentSemesterId) && p.StudentId.Equals(input.LeaveerId)).FirstOrDefaultAsync().Result; if (null == limit) { AddAndSave(new LeaveLimit { SemesterId = currentSemesterId, StudentId = input.LeaveerId, UsedDays = leaveDays }); return; } if ((limit.UsedDays + leaveDays) > 15) { throw new Exception($"您剩余的请假天数不足,请重新设置请假天数,当前剩余天数: {15 - limit.UsedDays}"); } limit.UsedDays += leaveDays; SaveChanges(); }
public void SendLeaveRequestEmail(LeaveRequestDto leaveRequestDto) { throw new System.NotImplementedException(); // MailerService.SendLeaveRequestEmail(leaveRequestDto); }
public int Update(LeaveRequestDto leaveRequestDto, long userId) { var leaveRequest = _unitOfWork.LeaveRequestRepository.GetById(leaveRequestDto.Id); // check start and end date times are the same if (!DateTime.Equals(leaveRequest.StartDateTime, leaveRequestDto.StartDateTime) || !DateTime.Equals(leaveRequest.EndDateTime, leaveRequestDto.EndDateTime) || (!DateTime.Equals(leaveRequest.StartDateTime, leaveRequestDto.StartDateTime) && !DateTime.Equals(leaveRequest.EndDateTime, leaveRequestDto.EndDateTime))) { if (CheckIfStaffOnShift(leaveRequestDto)) { return((int)StaffOn.Shift); } if (CheckIfStaffOnAnnual(leaveRequestDto)) { return((int)StaffOn.Annual); } if (CheckIfStaffOnMaternity(leaveRequestDto)) { return((int)StaffOn.Maternity); } if (CheckIfStaffOnPaternity(leaveRequestDto)) { return((int)StaffOn.Paternity); } if (CheckIfStaffOnSick(leaveRequestDto)) { return((int)StaffOn.Sick); } if (CheckIfStaffOnSuspension(leaveRequestDto)) { return((int)StaffOn.Suspension); } if (CheckIfStaffOnOther(leaveRequestDto)) { return((int)StaffOn.Other); } if (CheckIfStaffOnTraining(leaveRequestDto)) { return((int)StaffOn.Training); } } // All good, so go ahead and update CommonHelperAppService.MapDtoToEntityForUpdating(leaveRequestDto, leaveRequest); _unitOfWork.LeaveRequestRepository.Update(leaveRequest); _unitOfWork.Save(); // Audit _auditLogAppService.Audit( AppConstants.ActionTypeUpdate, AppConstants.LeaveRequestTableName, userId, leaveRequest.Id); return((int)StaffOn.None); }
// CRUD public int Create(LeaveRequestDto leaveRequestDto, long userId) { if (CheckIfStaffOnShift(leaveRequestDto)) { return((int)StaffOn.Shift); } if (CheckIfStaffOnAnnual(leaveRequestDto)) { return((int)StaffOn.Annual); } if (CheckIfStaffOnMaternity(leaveRequestDto)) { return((int)StaffOn.Maternity); } if (CheckIfStaffOnPaternity(leaveRequestDto)) { return((int)StaffOn.Paternity); } if (CheckIfStaffOnSick(leaveRequestDto)) { return((int)StaffOn.Sick); } if (CheckIfStaffOnSuspension(leaveRequestDto)) { return((int)StaffOn.Suspension); } if (CheckIfStaffOnOther(leaveRequestDto)) { return((int)StaffOn.Other); } if (CheckIfStaffOnTraining(leaveRequestDto)) { return((int)StaffOn.Training); } // All good, so go ahead and create var leaveRequest = Mapper.Map <LeaveRequest>(leaveRequestDto); _unitOfWork.LeaveRequestRepository.Create(leaveRequest); _unitOfWork.Save(); // Audit _auditLogAppService.Audit( AppConstants.ActionTypeCreate, AppConstants.LeaveRequestTableName, userId, leaveRequest.Id); // Email Manager for Approval (no need if coming via admin route?) //MailerService.SendLeaveRequestEmail(leaveRequestDto); return((int)StaffOn.None); }