|
@@ -38,34 +38,39 @@ namespace MTWorkHR.Application.Services
|
|
|
|
|
|
public override async Task<OrderAllocationDto> Create(OrderAllocationDto input)
|
|
|
{
|
|
|
- var orderType = await _unitOfWork.OrderType.GetByIdAsync(input.OrderTypeId);
|
|
|
- var leaveType = input.LeaveTypeId.HasValue && input.LeaveTypeId > 0 ? await _unitOfWork.LeaveType.GetByIdAsync(input.LeaveTypeId.Value): null;
|
|
|
- var employees = await _user.GetAllEmployees();
|
|
|
- var period = DateTime.Now.Year;
|
|
|
- var allocations = new List<OrderAllocation>();
|
|
|
- foreach (var emp in employees)
|
|
|
+ try
|
|
|
{
|
|
|
- if (await _unitOfWork.OrderAllocation.AllocationExists(emp.Id, orderType.Id, input.LeaveTypeId, period))
|
|
|
- continue;
|
|
|
- allocations.Add(new OrderAllocation
|
|
|
+ var orderType = await _unitOfWork.OrderType.GetByIdAsync(input.OrderTypeId);
|
|
|
+ var leaveType = input.LeaveTypeId.HasValue && input.LeaveTypeId > 0 ? await _unitOfWork.LeaveType.GetByIdAsync(input.LeaveTypeId.Value) : null;
|
|
|
+ var employees = await _user.GetAllEmployees();
|
|
|
+ var period = DateTime.Now.Year;
|
|
|
+ var allocations = new List<OrderAllocation>();
|
|
|
+ foreach (var emp in employees)
|
|
|
{
|
|
|
- EmployeeId = emp.Id,
|
|
|
- OrderTypeId = orderType.Id,
|
|
|
- LeaveTypeId = leaveType != null ? leaveType.Id : null,
|
|
|
- NumberOfDays = leaveType != null ? leaveType.DefaultDays : orderType.DefaultDays,
|
|
|
- Period = period
|
|
|
- });
|
|
|
- }
|
|
|
+ if (await _unitOfWork.OrderAllocation.AllocationExists(emp.Id, orderType.Id, input.LeaveTypeId, period))
|
|
|
+ continue;
|
|
|
+ allocations.Add(new OrderAllocation
|
|
|
+ {
|
|
|
+ EmployeeId = emp.Id,
|
|
|
+ OrderTypeId = orderType.Id,
|
|
|
+ LeaveTypeId = leaveType != null ? leaveType.Id : null,
|
|
|
+ NumberOfDays = leaveType != null ? leaveType.DefaultDays : orderType.DefaultDays,
|
|
|
+ Period = period
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
- await _unitOfWork.OrderAllocation.AddRangeAsync(allocations);
|
|
|
- await _unitOfWork.CompleteAsync();
|
|
|
+ await _unitOfWork.OrderAllocation.AddRangeAsync(allocations);
|
|
|
+ await _unitOfWork.CompleteAsync();
|
|
|
|
|
|
-
|
|
|
+ }catch(Exception ex)
|
|
|
+ {
|
|
|
+ var msg = ex.Message;
|
|
|
+ }
|
|
|
return input;
|
|
|
|
|
|
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
|
|
|
|
|
|
|