浏览代码

attendance api

zinab_elgendy 10 月之前
父节点
当前提交
95901e3be2

+ 0 - 1
MTWorkHR.Application/Dtos/Attendance/AttendanceDto.cs

@@ -15,7 +15,6 @@ namespace MTWorkHR.Application.Models
         [Required]
         public string UserId { get; set; }
         public string? UserName { get; set; }
-        public DateTime? LoginTime { get; set; }
         public DateTime? CheckInTime { get; set; }
         public DateTime? CheckOutTime { get; set; }
         public DateTime AttendanceDate { get; set; }

+ 0 - 2
MTWorkHR.Application/Dtos/Identity/CompanyDto.cs

@@ -10,8 +10,6 @@ namespace MTWorkHR.Application.Models
 {
     public class CompanyDto : EntityDto
     {
-        public long UserId { get; set; }
-
         public string CompanyName { get; set; }
 
         public string CRNumber { get; set; }

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

@@ -68,7 +68,7 @@ namespace MTWorkHR.Application.Mapper
                 .ForMember(d => d.CreateDate, o => o.Ignore());
             CreateMap<MeetingUser, MeetingUserDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore());
 
-            CreateMap<Attendance, AttendanceDto>().ReverseMap()
+            CreateMap<Attendance, AttendanceDto>().ForMember(d=> d.WeekDay , o=> o.MapFrom(s=> s.AttendanceDate.DayOfWeek)).ReverseMap()
                 .ForMember(d => d.CreateDate, o => o.Ignore());
 
 

+ 23 - 3
MTWorkHR.Application/Services/User/AttendanceService.cs

@@ -25,14 +25,34 @@ namespace MTWorkHR.Application.Services
             _unitOfWork = unitOfWork;
         }
 
-        public override async Task<AttendanceDto> GetById(long id)
+
+        public override async Task<AttendanceDto> Create(AttendanceDto input)
         {
-            var entity = await _unitOfWork.Attendance.GetByIdWithAllChildren(id);
-            var response = MapperObject.Mapper.Map<AttendanceDto>(entity);
+            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;
+        }
 
     }
 }

+ 0 - 1
MTWorkHR.Core/Entities/Attendance/Attendance.cs

@@ -14,7 +14,6 @@ namespace MTWorkHR.Core.Entities
         [Required]
         public string UserId { get; set; }
         public string? UserName { get; set; }
-        public DateTime? LoginTime { get; set; }
         public DateTime? CheckInTime { get; set; }
         public DateTime? CheckOutTime { get; set; }
         public DateTime AttendanceDate { get; set; }

+ 2 - 3
MTWorkHR.Core/IRepositories/User/IAttendanceRepository.cs

@@ -8,10 +8,9 @@ using System.Threading.Tasks;
 
 namespace MTWorkHR.Core.IRepositories
 {
-    public interface ITeamRepository : IRepository<Team>
+    public interface IAttendanceRepository : IRepository<Attendance>
     {
-        Task<Team> GetByIdWithAllChildren(long id);
-     //   Task<bool> AssignAdminManager(string userId, long teamId, bool isAdmin);
+        Task<Attendance> GetAttendanceByUserId(string userId, DateTime attendanceDate);
 
     }
 }

+ 3 - 2
MTWorkHR.Core/IRepositories/User/ITeamRepository.cs

@@ -8,9 +8,10 @@ using System.Threading.Tasks;
 
 namespace MTWorkHR.Core.IRepositories
 {
-    public interface IAttendanceRepository : IRepository<Attendance>
+    public interface ITeamRepository : IRepository<Team>
     {
-        Task<Attendance> GetByIdWithAllChildren(long id);
+        Task<Team> GetByIdWithAllChildren(long id);
+        Task<bool> AssignAdminManager(string userId, long teamId, bool isAdmin);
 
     }
 }

+ 1 - 4
MTWorkHR.Infrastructure/Migrations/20240311151145_attendance.Designer.cs

@@ -12,7 +12,7 @@ using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
 namespace MTWorkHR.Infrastructure.Migrations
 {
     [DbContext(typeof(HRDataContext))]
-    [Migration("20240311151145_attendance")]
+    [Migration("20240313083213_attendance")]
     partial class attendance
     {
         /// <inheritdoc />
@@ -83,9 +83,6 @@ namespace MTWorkHR.Infrastructure.Migrations
                     b.Property<int>("LeaveType")
                         .HasColumnType("int");
 
-                    b.Property<DateTime?>("LoginTime")
-                        .HasColumnType("datetime2");
-
                     b.Property<DateTime?>("UpdateDate")
                         .HasColumnType("datetime2")
                         .HasColumnOrder(4);

+ 0 - 1
MTWorkHR.Infrastructure/Migrations/20240311151145_attendance.cs

@@ -67,7 +67,6 @@ namespace MTWorkHR.Infrastructure.Migrations
                     DeleteUserId = table.Column<string>(type: "nvarchar(450)", maxLength: 450, nullable: true),
                     UserId = table.Column<string>(type: "nvarchar(max)", nullable: false),
                     UserName = table.Column<string>(type: "nvarchar(max)", nullable: true),
-                    LoginTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                     CheckInTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                     CheckOutTime = table.Column<DateTime>(type: "datetime2", nullable: true),
                     AttendanceDate = table.Column<DateTime>(type: "datetime2", nullable: false),

+ 0 - 3
MTWorkHR.Infrastructure/Migrations/HRDataContextModelSnapshot.cs

@@ -80,9 +80,6 @@ namespace MTWorkHR.Infrastructure.Migrations
                     b.Property<int>("LeaveType")
                         .HasColumnType("int");
 
-                    b.Property<DateTime?>("LoginTime")
-                        .HasColumnType("datetime2");
-
                     b.Property<DateTime?>("UpdateDate")
                         .HasColumnType("datetime2")
                         .HasColumnOrder(4);

+ 6 - 3
MTWorkHR.Infrastructure/Repositories/User/AttendanceRepository.cs

@@ -16,10 +16,13 @@ namespace MTWorkHR.Infrastructure.Repositories
             dbSet = context.Set<Attendance>();
 
         }
-        public async Task<Attendance> GetByIdWithAllChildren(long id)
+       
+
+        public async Task<Attendance> GetAttendanceByUserId(string userId, DateTime attendanceDate)
         {
-            return await dbSet
-                .FirstOrDefaultAsync(x => x.Id == id);
+             var result = await dbSet
+                .FirstOrDefaultAsync(x => x.UserId == userId && x.AttendanceDate.Date == attendanceDate.Date);
+            return result;
         }
     }
 }