123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- using Microsoft.EntityFrameworkCore;
- using MTWorkHR.Application.Identity;
- using MTWorkHR.Application.Mapper;
- using MTWorkHR.Application.Models;
- using MTWorkHR.Core.Global;
- using MTWorkHR.Core.UnitOfWork;
- using MTWorkHR.Application.Services.Interfaces;
- using MTWorkHR.Core.Entities;
- using System.Linq.Dynamic.Core;
- namespace MTWorkHR.Application.Services
- {
- public class ContractService : BaseService<Contract, ContractDto, ContractDto>, IContractService
- {
- private readonly IUnitOfWork _unitOfWork;
- private readonly IUserService _userService;
- private readonly GlobalInfo _globalInfo;
- public ContractService(IUnitOfWork unitOfWork, IUserService userService, GlobalInfo globalInfo) : base(unitOfWork)
- {
- _unitOfWork = unitOfWork;
- _userService = userService;
- _globalInfo = globalInfo;
- }
- public override async Task<ContractDto> GetById(long id)
- {
- var entity = await _unitOfWork.Contract.GetByIdWithAllChildren(id);
- var response = MapperObject.Mapper.Map<ContractDto>(entity);
- return response;
- }
-
- public override async Task<ContractDto> Create(ContractDto input)
- {
- var entity = MapperObject.Mapper.Map<Contract>(input);
- if (entity is null)
- {
- throw new AppException(ExceptionEnum.MapperIssue);
- }
- var team = await _unitOfWork.Contract.AddAsync(entity);
- await _unitOfWork.CompleteAsync();
- var response = MapperObject.Mapper.Map<ContractDto>(team);
- return response;
- }
- //public override async Task<ContractDto> Update(ContractDto input)
- //{
- // var entity = MapperObject.Mapper.Map<Contract>(input);
- // if (entity is null)
- // {
- // throw new AppException(ExceptionEnum.MapperIssue);
- // }
- // var contract = await _unitOfWork.Contract.upd(entity);
- // await _unitOfWork.CompleteAsync();
- // var response = Mapper.MapperObject.Mapper.Map<ContractDto>(entity);
- // return response;
- //}
- public override async Task<PagingResultDto<ContractDto>> GetAll(PagingInputDto 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)
- {
- var filter = PagingInputDto.Filter;
- query = query.Where(u => u.JobDescription.Contains(filter));
- }
- 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());
- var response = new PagingResultDto<ContractDto>
- {
- Result = list,
- Total = total
- };
- return response;
- }
-
- }
- }
|