Explorar el Código

employee in attendance.GetAll

zinab_elgendy hace 4 meses
padre
commit
b035ebaeef

+ 1 - 1
MTWorkHR.API/Program.cs

@@ -20,7 +20,7 @@ var config = new AppSettingsConfiguration();
 // Add services to the container.
 builder.Services.AddDbContext<HRDataContext>(options =>
 {
-    options.UseSqlServer(config.ConnectionStrings.LocalConnectionString);
+    options.UseSqlServer(config.ConnectionStrings.MTWorkHRConnectionString);
   //  options.UseSqlServer(builder.Configuration.GetSection("ConnectionStrings:MTWorkHRConnectionString").Value);
 });
 

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

@@ -24,7 +24,8 @@ namespace MTWorkHR.Application.Models
 
         [MaxLength(250)]
         public string? LeaveReason { get; set; }
-        
+        public UserBasicInfoDto? Employee { get; set; }
+
 
 
     }

+ 34 - 0
MTWorkHR.Application/Dtos/Identity/UserBasicInfoDto.cs

@@ -0,0 +1,34 @@
+using Microsoft.AspNetCore.Http;
+using MTWorkHR.Core.Global;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace MTWorkHR.Application.Models
+{
+    public class UserBasicInfoDto
+    {
+        public string? Id { get; set; }
+       
+        public string FirstName { get; set; }
+        public DateTime DateOfBirth { get; set; }
+       
+        public string IdNumber { get; set; }
+        public string LastName { get; set; }
+        public string Email { get; set; }
+
+        public string? FavoriteName { get; set; }
+
+        public string PhoneNumber { get; set; }
+        public UserTypeEnum UserType { get; set; }
+      
+        public string? Position { get; set; }
+        public long? CompanyId { get; set; }
+
+        public IFormFile? ProfileImage { get; set; }
+      
+    }
+}

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

@@ -51,7 +51,9 @@ namespace MTWorkHR.Application.Mapper
 
             CreateMap<ApplicationUser, UserUpdateDto>().ForMember(m => m.Password, op => op.Ignore());
             CreateMap<UserDto, UserUpdateDto>().ReverseMap();
-
+            CreateMap<UserBasicInfoDto, ApplicationUser>().ReverseMap();
+            CreateMap<UserBasicInfoDto, UserDto>().ReverseMap();
+            
             CreateMap<AttachmentDto, UserAttachment>().ReverseMap();
             CreateMap<UserAddress, UserAddressDto>()
               .ForMember(s => s.CountryName, o => o.MapFrom(s => s.Country == null ? "" : GlobalInfo.lang == "ar" ? s.Country.NameAr : s.Country.NameEn))

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

@@ -14,6 +14,7 @@ using MTWorkHR.Core.Email;
 using MTWorkHR.Core.Entities;
 using System.Linq.Dynamic.Core;
 using System.Linq;
+using Microsoft.AspNetCore.Http;
 
 namespace MTWorkHR.Application.Services
 {
@@ -21,11 +22,13 @@ namespace MTWorkHR.Application.Services
     {
         private readonly IUnitOfWork _unitOfWork;
         private readonly GlobalInfo _globalInfo;
+        private readonly IUserService _userService;
 
-        public AttendanceService(IUnitOfWork unitOfWork, GlobalInfo globalInfo) :base(unitOfWork)
+        public AttendanceService(IUnitOfWork unitOfWork, GlobalInfo globalInfo, IUserService userService) :base(unitOfWork)
         {
             _unitOfWork = unitOfWork;
             _globalInfo = globalInfo;
+            _userService = userService;
         }
         public async Task<PagingResultDto<AttendanceDto>> GetAll(AttendancePagingInputDto PagingInputDto)
         {
@@ -70,7 +73,7 @@ namespace MTWorkHR.Application.Services
             var list = MapperObject.Mapper
                 .Map<IList<AttendanceDto>>(await page.ToListAsync());
 
-            
+
             //var dayGroupByUser = list.GroupBy(m => new { m.UserId,m.WeekDay, m.UserName, AttendanceDate = m.AttendanceDate.Date }).Select
             //  (g => new AttendanceDto { 
             //      UserId = g.Key.UserId, UserName=g.Key.UserName,
@@ -79,7 +82,35 @@ namespace MTWorkHR.Application.Services
             //      TotalHours = g.Sum(s=> s.TotalHours) 
             //  }).ToList();
 
-
+            foreach (var item in list)
+            {
+                if (item.UserId != null)
+                {
+                    var user = await _userService.GetUserWithAttachmentById(item.UserId);
+                    if (user != null)
+                    {
+                        var entitiy = MapperObject.Mapper.Map<UserBasicInfoDto>(user);
+                        item.Employee = entitiy;
+                        var attach = user.UserAttachments?.FirstOrDefault(a => a.AttachmentTypeId == 9);
+                        if (attach != null)
+                            using (var stream = new MemoryStream(attach.Content))
+                            {
+                                var file = new FormFile(stream, 0, stream.Length, Path.GetFileNameWithoutExtension(attach.FileName), attach.FileName)
+                                {
+                                    Headers = new HeaderDictionary(),
+                                    ContentType = attach.ContentType,
+                                };
+
+                                System.Net.Mime.ContentDisposition cd = new System.Net.Mime.ContentDisposition
+                                {
+                                    FileName = file.FileName
+                                };
+                                file.ContentDisposition = cd.ToString();
+                                item.Employee.ProfileImage = file;
+                            }
+                    }
+                }
+            }
             var response = new PagingResultDto<AttendanceDto>
             {
                 Result = list ,
@@ -107,6 +138,7 @@ namespace MTWorkHR.Application.Services
             }
             else
             {
+                throw new AppException(ExceptionEnum.UserAlreadyCheckedIn);
                 var response = Mapper.MapperObject.Mapper.Map<AttendanceDto>(oldEntity);
                 return response;
             }

+ 2 - 0
MTWorkHR.Core/Global/AppExceptions.cs

@@ -39,6 +39,8 @@ namespace MTWorkHR.Core.Global
             {24, "Email Not Exist" },
             {25, "Phone Already Exist" },
             {26, "User Not Exist" },
+            {26, "User already checked in" },
+
         };
     }
 }

+ 1 - 0
MTWorkHR.Core/Global/Enum/ExceptionEnum.cs

@@ -34,5 +34,6 @@ namespace MTWorkHR.Core.Global
         EmailNotExist = 24,
         RecordPhoneAlreadyExist = 25,
         UserNotExist=26,
+        UserAlreadyCheckedIn= 27,
     }
 }

+ 1 - 1
MTWorkHR.Infrastructure/InfrastructureServiceRegistration.cs

@@ -31,7 +31,7 @@ namespace MTWorkHR.Infrastructure
             
             services.AddDbContext<HRDataContext>(options =>
                 options.UseSqlServer(
-                    config.ConnectionStrings.LocalConnectionString  //configuration.GetSection("ConnectionString:MTWorkHRConnectionString").Value
+                    config.ConnectionStrings.MTWorkHRConnectionString  //configuration.GetSection("ConnectionString:MTWorkHRConnectionString").Value
                     ));
            
             services.AddIdentity<ApplicationUser, ApplicationRole>().AddEntityFrameworkStores<HRDataContext>().AddDefaultTokenProviders();