Browse Source

EmployeeMinimal info

zinab_elgendy 1 week ago
parent
commit
198b22eb9a

+ 7 - 0
MTWorkHR.API/Controllers/UserController.cs

@@ -46,6 +46,13 @@ namespace MTWorkHR.API.Controllers
             return Ok(await _userService.GetById(userId));
         }
 
+        [HttpGet("GetEmployeeById")]
+        [AppAuthorize(Permissions = "User")]
+        public async Task<ActionResult<EmployeeInfoDto>> GetEmployeeById([FromQuery] string userId)
+        {
+            return Ok(await _userService.GetEmployeeInfo(userId));
+        }
+
         [HttpGet("GetByEmail")]
         [AppAuthorize(Permissions = "User")]
         public async Task<ActionResult<UserDto>> GetByEmail(string userId)

+ 13 - 0
MTWorkHR.Application/Dtos/Identity/EmployeeAddressDto.cs

@@ -0,0 +1,13 @@
+using System.ComponentModel.DataAnnotations;
+using System.ComponentModel.DataAnnotations.Schema;
+
+namespace MTWorkHR.Application.Models
+{
+    public class EmployeeAddressDto : EntityDto
+    {
+        public int? CountryId { get; set; }
+        public int? CityId { get; set; }
+        public string? CityName { get; set; }
+        public string? CountryName { get; set; }
+    }
+}

+ 42 - 0
MTWorkHR.Application/Dtos/Identity/EmployeeInfoDto.cs

@@ -0,0 +1,42 @@
+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 EmployeeInfoDto
+    {
+        public string? Id { get; set; }
+       
+        public string FirstName { get; set; }
+        public DateTime DateOfBirth { 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; }
+        //------------Education
+        public string? Position { get; set; }
+        public string? QualificationName { get; set; }
+        public string? UniversityName { get; set; }
+        public string? JobTitleName { get; set; }
+        public string? IndustryName { get; set; }
+
+        public long? CompanyId { get; set; }
+        //-------------------Attachments
+        public string? ProfileImagePath { get; set; }
+        public IFormFile? ProfileImage { get; set; }
+        public IFormFile? CVAttach { get; set; }
+        public IFormFile? ExperienceCertificateAttach { get; set; }
+        public IFormFile? ProfCertificateAttach { get; set; }
+        //------------------------Address
+        public EmployeeAddressDto? UserAddress { get; set; }
+
+
+    }
+}

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

@@ -53,7 +53,18 @@ namespace MTWorkHR.Application.Mapper
             CreateMap<UserDto, UserUpdateDto>().ReverseMap();
             CreateMap<UserBasicInfoDto, ApplicationUser>().ReverseMap();
             CreateMap<UserBasicInfoDto, UserDto>().ReverseMap();
-
+            // -------------------view Employee info
+            CreateMap<ApplicationUser, EmployeeInfoDto>()
+              .ForMember(s => s.QualificationName, o => o.MapFrom(s => s.Qualification == null ? "" : GlobalInfo.lang == "ar" ? s.Qualification.NameAr : s.Qualification.NameEn))
+              .ForMember(s => s.JobTitleName, o => o.MapFrom(s => s.JobTitle == null ? "" : GlobalInfo.lang == "ar" ? s.JobTitle.NameAr : s.JobTitle.NameEn))
+              .ForMember(s => s.IndustryName, o => o.MapFrom(s => s.Industry == null ? "" : GlobalInfo.lang == "ar" ? s.Industry.NameAr : s.Industry.NameEn))
+              .ForMember(s => s.UniversityName, o => o.MapFrom(s => s.University == null ? "" : GlobalInfo.lang == "ar" ? s.University.NameAr : s.University.NameEn)
+              );
+            CreateMap<UserAddress, EmployeeAddressDto>()
+              .ForMember(s => s.CountryName, o => o.MapFrom(s => s.Country == null ? "" : GlobalInfo.lang == "ar" ? s.Country.NameAr : s.Country.NameEn))
+              .ForMember(s => s.CityName, o => o.MapFrom(s => s.City == null ? "" : GlobalInfo.lang == "ar" ? s.City.NameAr : s.City.NameEn)
+              );
+            //--------------------------------------
             CreateMap<ApplicationUser, ChatUserDto>()
             .ForMember(s => s.UserId, o => o.MapFrom(s => s.Id )).ReverseMap();
             

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

@@ -17,6 +17,7 @@ namespace MTWorkHR.Application.Identity
         Task<List<UserDto>> GetAllEmployees();
 
         Task<UserDto> GetUserById(string id);
+        Task<EmployeeInfoDto> GetEmployeeInfo(string id);
         Task<string> GetUserFullName(string userId);
         Task Delete(string id);
         Task<UserDto> Create(UserDto input);

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

@@ -144,6 +144,66 @@ namespace MTWorkHR.Application.Services
             response.IsCheckedOut = attendance != null && attendance.CheckOutTime.HasValue;
             return response;
         }
+
+
+        public async Task<EmployeeInfoDto> GetEmployeeInfo(string id)
+        {
+            var entity = await _userManager.Users
+                .Include(x => x.UserRoles)
+                .Include(x => x.UserAddress).ThenInclude(x => x.City)
+                .Include(x => x.UserAddress).ThenInclude(x => x.Country)
+                .Include(x => x.UserAttachments)
+                .Include(x => x.JobTitle)
+                .Include(x => x.Industry)
+                .Include(x => x.University)
+                .Include(x => x.Country)
+                .Include(x => x.Qualification)
+                .FirstOrDefaultAsync(x => x.Id == id);
+            if(entity == null)
+            {
+                throw new AppException(ExceptionEnum.RecordNotExist);
+            }
+            var response = MapperObject.Mapper.Map<EmployeeInfoDto>(entity);
+            if (entity.UserAttachments != null)
+                foreach (var attach in entity.UserAttachments.Where(a => a.Content != null))
+                {
+                    //var stream = new MemoryStream(attach.Content);
+                    //IFormFile file = new FormFile(stream, 0, stream.Length, Path.GetFileNameWithoutExtension(attach.FileName), attach.FileName);
+
+                    using (var stream = new MemoryStream(attach.Content))
+                    {
+                        var file = new FormFile(stream, 0, stream.Length, Path.GetFileNameWithoutExtension(attach.FileName), attach.FilePath)
+                        {
+                            Headers = new HeaderDictionary(),
+                            ContentType = attach.ContentType,
+
+                        };
+                        System.Net.Mime.ContentDisposition cd = new System.Net.Mime.ContentDisposition
+                        {
+                            FileName = file.FileName
+                        };
+                        file.ContentDisposition = cd.ToString();
+                        switch (attach.AttachmentTypeId)
+                        {
+                            case 1:
+                                response.CVAttach = file;
+                                break;
+                            case 4:
+                                response.ExperienceCertificateAttach = file;
+                                break;
+                            case 5:
+                                response.ProfCertificateAttach = file;
+                                break;
+                            case 9:
+                                response.ProfileImage = file;
+                                response.ProfileImagePath = attach.FilePath;
+                                break;
+                        }
+                        attach.Content = new byte[0];
+                    }
+                }
+            return response;
+        }
         public async Task<UserDto> GetUserById(string id)
         {
             var entity = await _userManager.Users