Browse Source

IsCheckedIn, IsCheckedOut

zinab_elgendy 4 months ago
parent
commit
5fb3ab8d04

+ 3 - 3
MTWorkHR.Application/ApplicationServiceRegistration.cs

@@ -20,10 +20,10 @@ namespace MTWorkHR.Application
 
             services.AddMediatR(Assembly.GetExecutingAssembly());
 
-            services.AddTransient<IAuthService, AuthService>();
-            services.AddTransient<IUserService, UserService>();
+            services.AddScoped<IAuthService, AuthService>();
+            services.AddScoped<IUserService, UserService>();
             //services.AddTransient<IFileService, FileService>();
-            services.AddTransient<IFileService, BlobFileService>();
+            services.AddScoped<IFileService, BlobFileService>();
             services.AddScoped<IProjectService, ProjectService>();
             services.AddScoped<IUserTaskService, UserTaskService>();
             services.AddScoped<IUserTaskAttachmentService, UserTaskAttachmentService>();

+ 2 - 1
MTWorkHR.Application/Dtos/Identity/UserDto.cs

@@ -50,7 +50,8 @@ namespace MTWorkHR.Application.Models
         public decimal IncomeTaxValue { get; set; }
         public string? Position { get; set; }
         public long? CompanyId { get; set; }
-
+        public bool IsCheckedIn { get; set; }
+        public bool IsCheckedOut { get; set; }
         public IFormFile? ProfileImage { get; set; }
         public IFormFile? CVAttach { get; set; }
         public IFormFile? PassportAttach { get; set; }

+ 1 - 0
MTWorkHR.Application/Services/Interfaces/IAttendanceService.cs

@@ -8,6 +8,7 @@ namespace MTWorkHR.Application.Services.Interfaces
     public interface IAttendanceService : IService<Attendance, AttendanceDto, AttendanceDto>
     {
         Task<PagingResultDto<AttendanceDto>> GetAll(AttendancePagingInputDto PagingInputDto);
+        Task<AttendanceDto?> GetAttendanceByUserId(string userId, DateTime attendanceDate);
 
     }
 }

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

@@ -15,6 +15,7 @@ using MTWorkHR.Core.Entities;
 using System.Linq.Dynamic.Core;
 using System.Linq;
 using Microsoft.AspNetCore.Http;
+using MTWorkHR.Core.Entities.Base;
 
 namespace MTWorkHR.Application.Services
 {
@@ -164,5 +165,14 @@ namespace MTWorkHR.Application.Services
             return response;
         }
 
+        public async Task<AttendanceDto?> GetAttendanceByUserId(string userId, DateTime attendanceDate)
+        {
+            var entity = await _unitOfWork.Attendance.GetAttendanceByUserId(userId, attendanceDate);
+            if (entity is null)
+                return null;
+            var response = Mapper.MapperObject.Mapper.Map<AttendanceDto>(entity);
+            return response;
+        }
+
     }
 }

+ 3 - 0
MTWorkHR.Application/Services/User/UserService.cs

@@ -124,6 +124,9 @@ namespace MTWorkHR.Application.Services
                     }
                    
                 }
+            var attendance = await _unitOfWork.Attendance.GetAttendanceByUserId(id, DateTime.Now.Date);
+            response.IsCheckedIn = attendance != null && attendance.CheckInTime.HasValue;
+            response.IsCheckedOut = attendance != null && attendance.CheckOutTime.HasValue;
             return response;
         }
         public async Task<UserDto> GetUserById(string id)