AttendanceService.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. using Microsoft.AspNetCore.Identity;
  2. using Microsoft.AspNetCore.WebUtilities;
  3. using Microsoft.EntityFrameworkCore;
  4. using Microsoft.Extensions.Configuration;
  5. using MTWorkHR.Application.Identity;
  6. using MTWorkHR.Application.Mapper;
  7. using MTWorkHR.Application.Models;
  8. using MTWorkHR.Core.Global;
  9. using MTWorkHR.Core.IRepositories;
  10. using MTWorkHR.Core.UnitOfWork;
  11. using MTWorkHR.Infrastructure.Entities;
  12. using MTWorkHR.Application.Services.Interfaces;
  13. using MTWorkHR.Core.Email;
  14. using MTWorkHR.Core.Entities;
  15. using MTWorkHR.Infrastructure.UnitOfWorks;
  16. namespace MTWorkHR.Application.Services
  17. {
  18. public class AttendanceService : BaseService<Attendance, AttendanceDto, AttendanceDto>, IAttendanceService
  19. {
  20. private readonly IUnitOfWork _unitOfWork;
  21. public AttendanceService(IUnitOfWork unitOfWork):base(unitOfWork)
  22. {
  23. _unitOfWork = unitOfWork;
  24. }
  25. public override async Task<AttendanceDto> Create(AttendanceDto input)
  26. {
  27. var entitiy = MapperObject.Mapper.Map<Attendance>(input);
  28. if (entitiy is null)
  29. throw new AppException(ExceptionEnum.MapperIssue);
  30. var newEntity = await _unitOfWork.Attendance.AddAsync(entitiy);
  31. var Success = await _unitOfWork.CompleteAsync();
  32. var response = Mapper.MapperObject.Mapper.Map<AttendanceDto>(newEntity);
  33. return response;
  34. }
  35. public override async Task<AttendanceDto> Update(AttendanceDto input)
  36. {
  37. var entity = await _unitOfWork.Attendance.GetAttendanceByUserId(input.UserId, input.AttendanceDate);
  38. if (entity is null)
  39. throw new AppException(ExceptionEnum.RecordNotExist);
  40. entity.CheckOutTime = input.CheckOutTime;
  41. entity.LeaveType = input.LeaveType;
  42. entity.LeaveReason = input.LeaveReason;
  43. await _unitOfWork.CompleteAsync();
  44. var response = Mapper.MapperObject.Mapper.Map<AttendanceDto>(entity);
  45. return response;
  46. }
  47. }
  48. }