Explorar o código

AttendanceDate save

zinab_elgendy hai 1 mes
pai
achega
5808a7c3c4

+ 1 - 2
MTWorkHR.Application/Mapper/MappingProfile.cs

@@ -105,8 +105,7 @@ namespace MTWorkHR.Application.Mapper
             CreateMap<Attendance, AttendanceDto>().ForMember(d=> d.WeekDay , o=> o.MapFrom(s=> s.AttendanceDate.DayOfWeek))
                 .ForMember(d => d.TotalHours, o => o.MapFrom(s =>(s.CheckInTime.HasValue && s.CheckOutTime.HasValue) ? (s.CheckOutTime.Value - s.CheckInTime.Value).TotalHours:0));
 
-            CreateMap<AttendanceDto, Attendance>().ForMember(d => d.CreateDate, o => o.Ignore())
-                .ForMember(d => d.AttendanceDate, o => o.Ignore());
+            CreateMap<AttendanceDto, Attendance>().ForMember(d => d.CreateDate, o => o.Ignore());
             CreateMap<OrderAllocation, OrderAllocationDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore());
             CreateMap<OrderRequest, OrderRequestDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore());
             CreateMap<OrderType, OrderTypeDto>().ReverseMap();

+ 6 - 0
MTWorkHR.Application/Services/User/AttendanceService.cs

@@ -134,6 +134,8 @@ namespace MTWorkHR.Application.Services
 
         public override async Task<AttendanceDto> Create(AttendanceDto input)
         {
+            if (input.CheckInTime.HasValue)
+                input.AttendanceDate = input.CheckInTime.Value.Date;
             var oldEntity = await _unitOfWork.Attendance.GetAttendanceByUserId(input.UserId, input.AttendanceDate);
             if (oldEntity is null)
             {
@@ -159,6 +161,10 @@ namespace MTWorkHR.Application.Services
         public override async Task<AttendanceDto> Update(AttendanceDto input)
         {
             Attendance? entity = null;
+            if (input.CheckInTime.HasValue)
+                input.AttendanceDate = input.CheckInTime.Value.Date;
+            else if (input.CheckOutTime.HasValue)
+                input.AttendanceDate = input.CheckOutTime.Value.Date;
             if (input.Id > 0)
                 entity = await _unitOfWork.Attendance.GetByIdAsync(input.Id);
             else