1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- using Microsoft.AspNetCore.Identity;
- using Microsoft.AspNetCore.WebUtilities;
- using Microsoft.EntityFrameworkCore;
- using Microsoft.Extensions.Configuration;
- using MTWorkHR.Application.Identity;
- using MTWorkHR.Application.Mapper;
- using MTWorkHR.Application.Models;
- using MTWorkHR.Core.Global;
- using MTWorkHR.Core.IRepositories;
- using MTWorkHR.Core.UnitOfWork;
- using MTWorkHR.Infrastructure.Entities;
- using MTWorkHR.Application.Services.Interfaces;
- using MTWorkHR.Core.Email;
- using MTWorkHR.Core.Entities;
- using MTWorkHR.Infrastructure.UnitOfWorks;
- namespace MTWorkHR.Application.Services
- {
- public class AttendanceService : BaseService<Attendance, AttendanceDto, AttendanceDto>, IAttendanceService
- {
- private readonly IUnitOfWork _unitOfWork;
- public AttendanceService(IUnitOfWork unitOfWork):base(unitOfWork)
- {
- _unitOfWork = unitOfWork;
- }
- public override async Task<AttendanceDto> Create(AttendanceDto input)
- {
- var entitiy = MapperObject.Mapper.Map<Attendance>(input);
- if (entitiy is null)
- throw new AppException(ExceptionEnum.MapperIssue);
- var newEntity = await _unitOfWork.Attendance.AddAsync(entitiy);
- var Success = await _unitOfWork.CompleteAsync();
- var response = Mapper.MapperObject.Mapper.Map<AttendanceDto>(newEntity);
- return response;
- }
- public override async Task<AttendanceDto> Update(AttendanceDto input)
- {
- var entity = await _unitOfWork.Attendance.GetAttendanceByUserId(input.UserId, input.AttendanceDate);
- if (entity is null)
- throw new AppException(ExceptionEnum.RecordNotExist);
- entity.CheckOutTime = input.CheckOutTime;
- entity.LeaveType = input.LeaveType;
- entity.LeaveReason = input.LeaveReason;
-
- await _unitOfWork.CompleteAsync();
- var response = Mapper.MapperObject.Mapper.Map<AttendanceDto>(entity);
- return response;
- }
- }
- }
|