|
@@ -69,6 +69,8 @@ namespace MTWorkHR.Application.Services
|
|
// var response = Mapper.MapperObject.Mapper.Map<ContractDto>(entity);
|
|
// var response = Mapper.MapperObject.Mapper.Map<ContractDto>(entity);
|
|
// return response;
|
|
// return response;
|
|
//}
|
|
//}
|
|
|
|
+
|
|
|
|
+
|
|
public async Task<PagingResultDto<ContractDto>> GetAll(ContractPagingInputDto PagingInputDto)
|
|
public async Task<PagingResultDto<ContractDto>> GetAll(ContractPagingInputDto PagingInputDto)
|
|
{
|
|
{
|
|
var res = await _unitOfWork.Contract.GetAllWithChildrenAsync();
|
|
var res = await _unitOfWork.Contract.GetAllWithChildrenAsync();
|
|
@@ -76,7 +78,61 @@ namespace MTWorkHR.Application.Services
|
|
|
|
|
|
if (_globalInfo.UserType != UserTypeEnum.Business)
|
|
if (_globalInfo.UserType != UserTypeEnum.Business)
|
|
{
|
|
{
|
|
- // query = query.Where(m => m.ContractUsers != null && m.ContractUsers.Count > 0 && m.ContractUsers.Count(u=> u.AssignedUserId == _globalInfo.UserId) > 0);
|
|
|
|
|
|
+ // query = query.Where(m => m.ContractUsers != null && m.ContractUsers.Count > 0 && m.ContractUsers.Count(u=> u.AssignedUserId == _globalInfo.UserId) > 0);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ if (PagingInputDto.Filter != null)
|
|
|
|
+ {
|
|
|
|
+ var filter = PagingInputDto.Filter;
|
|
|
|
+ query = query.Where(u => u.JobDescription != null && u.JobDescription.Contains(filter));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (PagingInputDto.ContractStatusId != null)
|
|
|
|
+ {
|
|
|
|
+ query = query.Where(u => (int)u.ContractStatusId == PagingInputDto.ContractStatusId);
|
|
|
|
+ }
|
|
|
|
+ if (PagingInputDto.ContractTypeId != null)
|
|
|
|
+ {
|
|
|
|
+ query = query.Where(u => (int)u.ContractTypeId == PagingInputDto.ContractTypeId);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var order = query.OrderBy(PagingInputDto.OrderByField + " " + PagingInputDto.OrderType);
|
|
|
|
+
|
|
|
|
+ var page = order.Skip((PagingInputDto.PageNumber * PagingInputDto.PageSize) - PagingInputDto.PageSize).Take(PagingInputDto.PageSize);
|
|
|
|
+
|
|
|
|
+ var total = await query.CountAsync();
|
|
|
|
+
|
|
|
|
+ var list = MapperObject.Mapper
|
|
|
|
+ .Map<IList<ContractDto>>(await page.ToListAsync());
|
|
|
|
+
|
|
|
|
+ foreach (var item in list)
|
|
|
|
+ {
|
|
|
|
+ if (item.UserId != null)
|
|
|
|
+ {
|
|
|
|
+ var user = await _userService.GetUserWithAttachmentById(item.UserId);
|
|
|
|
+ if (user != null)
|
|
|
|
+ {
|
|
|
|
+ item.EmployeeName = user.FirstName + " " + user.LastName;
|
|
|
|
+ item.EmployeeEmail = user.Email;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ var response = new PagingResultDto<ContractDto>
|
|
|
|
+ {
|
|
|
|
+ Result = list,
|
|
|
|
+ Total = total
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ return response;
|
|
|
|
+ }
|
|
|
|
+ public async Task<PagingResultDto<ContractDto>> GetAllForHr(ContractPagingInputDto PagingInputDto)
|
|
|
|
+ {
|
|
|
|
+ var res = await _unitOfWork.Contract.GetAllWithChildrenAsync();
|
|
|
|
+ var query = res.Item1;
|
|
|
|
+
|
|
|
|
+ if (_globalInfo.UserType != UserTypeEnum.Business)
|
|
|
|
+ {
|
|
|
|
+ // query = query.Where(m => m.ContractUsers != null && m.ContractUsers.Count > 0 && m.ContractUsers.Count(u=> u.AssignedUserId == _globalInfo.UserId) > 0);
|
|
|
|
|
|
}
|
|
}
|
|
if (PagingInputDto.Filter != null)
|
|
if (PagingInputDto.Filter != null)
|
|
@@ -124,11 +180,11 @@ namespace MTWorkHR.Application.Services
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
var response = new PagingResultDto<ContractDto>
|
|
var response = new PagingResultDto<ContractDto>
|
|
{
|
|
{
|
|
Result = list,
|
|
Result = list,
|
|
@@ -156,28 +212,36 @@ namespace MTWorkHR.Application.Services
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
- private async void addVacationAllocation(int noVacationDays, string employeeId, long contractId)
|
|
|
|
|
|
+ private async Task addVacationAllocation(int noVacationDays, string employeeId, long contractId)
|
|
{
|
|
{
|
|
- await _orderAllocationService.Create(new OrderAllocationDto { ContractId = contractId, EmployeeId = employeeId, OrderTypeId = 1, LeaveTypeId = 1, NumberOfDays = noVacationDays, Period = DateTime.Now.Year });
|
|
|
|
- var orderTypes = await _unitOfWork.OrderType.GetAllAsync();
|
|
|
|
- var leaveTypes = await _unitOfWork.LeaveType.GetAllAsync();
|
|
|
|
- foreach(var orderType in orderTypes.Item1)
|
|
|
|
|
|
+ try
|
|
|
|
+ {
|
|
|
|
+ await _orderAllocationService.Create(new OrderAllocationDto { ContractId = contractId, EmployeeId = employeeId, OrderTypeId = 1, LeaveTypeId = 1, NumberOfDays = noVacationDays, Period = DateTime.Now.Year });
|
|
|
|
+ // var orderTypes = await _unitOfWork.OrderType.GetAllAsync();
|
|
|
|
+ // var leaveTypes = await _unitOfWork.LeaveType.GetAllAsync();
|
|
|
|
+ //foreach (var orderType in orderTypes.Item1)
|
|
|
|
+ //{
|
|
|
|
+ // foreach (var leaveType in leaveTypes.Item1)
|
|
|
|
+ // {
|
|
|
|
+ // if (orderType.Id != 1 && leaveType.Id != 1 && (leaveType.DefaultDays > 0 || orderType.DefaultDays > 0))
|
|
|
|
+ // {
|
|
|
|
+ // await _orderAllocationService.Create(new OrderAllocationDto
|
|
|
|
+ // {
|
|
|
|
+ // ContractId = contractId,
|
|
|
|
+ // EmployeeId = employeeId,
|
|
|
|
+ // OrderTypeId = (int)orderType.Id,
|
|
|
|
+ // LeaveTypeId = (int)leaveType.Id,
|
|
|
|
+ // NumberOfDays = leaveType.DefaultDays > 0 ? leaveType.DefaultDays : orderType.DefaultDays,
|
|
|
|
+ // Period = DateTime.Now.Year
|
|
|
|
+ // }
|
|
|
|
+ // );
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+ //}
|
|
|
|
+ }
|
|
|
|
+ catch(Exception ex)
|
|
{
|
|
{
|
|
- foreach (var leaveType in leaveTypes.Item1)
|
|
|
|
- {
|
|
|
|
- if(orderType.Id !=1 && leaveType.Id != 1 && (leaveType.DefaultDays> 0 || orderType.DefaultDays > 0))
|
|
|
|
- {
|
|
|
|
- await _orderAllocationService.Create(new OrderAllocationDto
|
|
|
|
- {
|
|
|
|
- ContractId = contractId,
|
|
|
|
- EmployeeId = employeeId,
|
|
|
|
- OrderTypeId =(int) orderType.Id,
|
|
|
|
- LeaveTypeId = (int)leaveType.Id,
|
|
|
|
- NumberOfDays = leaveType.DefaultDays > 0 ? leaveType.DefaultDays : orderType.DefaultDays,
|
|
|
|
- Period = DateTime.Now.Year }
|
|
|
|
- );
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ throw ;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|