Bladeren bron

EmployeeDto for OrderRequest

zinab_elgendy 1 maand geleden
bovenliggende
commit
8f3edcc56b

+ 1 - 1
MTWorkHR.Application/Dtos/Attendance/OrderRequestDto.cs

@@ -21,7 +21,7 @@ namespace MTWorkHR.Application.Models
  
         public OrderTypeDto? OrderType { get; set; }
         public LeaveTypeDto? LeaveType { get; set; }
-        public UserDto? Employee { get; set; }
+        public EmployeeDto? Employee { get; set; }
        
         public long ContractId { get; set; }
         public List<AttachmentDto>? OrderAttachments { get; set; }

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

@@ -55,6 +55,7 @@ namespace MTWorkHR.Application.Models
         public long? CompanyId { get; set; }
         public bool IsCheckedIn { get; set; }
         public bool IsCheckedOut { get; set; }
+        public string? ProfileImagePath { get; set; }
         public IFormFile? ProfileImage { get; set; }
         public IFormFile? CVAttach { get; set; }
         public IFormFile? PassportAttach { get; set; }

+ 20 - 0
MTWorkHR.Application/Dtos/User/EmployeeDto.cs

@@ -0,0 +1,20 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using MTWorkHR.Core.Global;
+
+namespace MTWorkHR.Application.Models
+{
+    public class EmployeeDto 
+    {
+        public string? Id { get; set; }
+        public string? FirstName { get; set; }
+
+        public string? LastName { get; set; }
+        public string? Email { get; set; }
+        public string? ProfileImagePath { get; set; }
+    }
+}

+ 56 - 46
MTWorkHR.Application/Services/User/OrderRequestService.cs

@@ -16,6 +16,7 @@ using MTWorkHR.Infrastructure.UnitOfWorks;
 using System.Linq.Dynamic.Core;
 using Microsoft.AspNetCore.Http;
 using MTWorkHR.Core.Entities.User;
+using MTWorkHR.Core.Entities.Base;
 
 namespace MTWorkHR.Application.Services
 {
@@ -41,7 +42,9 @@ namespace MTWorkHR.Application.Services
         {
             var entity = await _unitOfWork.OrderRequest.GetByIdWithAllChildren(id);
             var response = MapperObject.Mapper.Map<OrderRequestDto>(entity);
-            response.Employee = await _userService.GetUserWithAttachmentById(entity.RequestingEmployeeId);
+            var user = await _userService.GetUserById(entity.RequestingEmployeeId);
+            var image = await _userService.GetProfileImage(entity.RequestingEmployeeId);
+            response.Employee = new EmployeeDto { Id = entity.RequestingEmployeeId, FirstName = user.FirstName, LastName = user.LastName, Email = user.Email, ProfileImagePath = image };
             return response;
         }
       
@@ -94,24 +97,24 @@ namespace MTWorkHR.Application.Services
                     var user = await _userService.GetUserWithAttachmentById(item.RequestingEmployeeId);
                     if (user != null)
                     {
-                        item.Employee = user;
+                        item.Employee = new EmployeeDto { Id = item.RequestingEmployeeId, FirstName = user.FirstName, LastName = user.LastName, Email = user.Email };
                         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;
-                        }
+                        item.Employee.ProfileImagePath = attach?.FilePath;
+                       // 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();
+                        //}
                     }
                 }
             }
@@ -140,23 +143,29 @@ namespace MTWorkHR.Application.Services
                 input.OrderTypeId = 2;
                 input.LeaveTypeId = null;
             }
+            var contract = await _unitOfWork.Contract.GetLatestActiveContract(input.RequestingEmployeeId);
+            if(contract!= null)
+                input.ContractId = contract.Id;
             if (input.OrderTypeId == 1 &&  input.LeaveTypeId == 1) // Annual vacation in contract
             {
-                var contractId = await _unitOfWork.Contract.GetLatestActiveContract(input.RequestingEmployeeId);
-                var allocation = await _unitOfWork.OrderAllocation.GetUserAllocations(input.RequestingEmployeeId, input.OrderTypeId, input.LeaveTypeId, contractId.Id, period);
-                input.ContractId = contractId.Id;
-                if (allocation is null)
-                {
-                    throw new AppException(ExceptionEnum.NoVacationBalance, "You do not have any allocations for this leave type.");
-                }
-                else
+                if (contract != null)
                 {
-                    int daysRequested = (int)(input.EndDate - input.StartDate).TotalDays;
-                    if (daysRequested > allocation.NumberOfDays)
+                    var allocation = await _unitOfWork.OrderAllocation.GetUserAllocations(input.RequestingEmployeeId, input.OrderTypeId, input.LeaveTypeId, contract.Id, period);
+
+                    if (allocation is null)
                     {
-                        throw new AppException(ExceptionEnum.NoVacationBalance, "You do not have enough days for this request");
+                        throw new AppException(ExceptionEnum.NoVacationBalance, "You do not have any allocations for this leave type.");
+                    }
+                    else
+                    {
+                        int daysRequested = (int)(input.EndDate - input.StartDate).TotalDays;
+                        if (daysRequested > allocation.NumberOfDays)
+                        {
+                            throw new AppException(ExceptionEnum.NoVacationBalance, "You do not have enough days for this request");
+                        }
                     }
                 }
+                
             }
           
             var orderRequest = MapperObject.Mapper.Map<OrderRequest>(input);
@@ -189,24 +198,25 @@ namespace MTWorkHR.Application.Services
                 var user = await _userService.GetUserWithAttachmentById(response.RequestingEmployeeId);
                 if (user != null)
                 {
-                    response.Employee = user;
+                    response.Employee = new EmployeeDto { Id = response.RequestingEmployeeId, FirstName = user.FirstName, LastName = user.LastName, Email = user.Email };
                     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();
-                            response.Employee.ProfileImage = file;
-                        }
+                    response.Employee.ProfileImagePath = attach?.FilePath;
+                    //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();
+                    //        response.Employee.ProfileImage = file;
+                    //    }
                 }
             }
             return response;

+ 1 - 1
MTWorkHR.Application/Services/User/UserService.cs

@@ -165,7 +165,7 @@ namespace MTWorkHR.Application.Services
 
         public async Task<string> GetProfileImage(string userId)
         {
-            string imagePath = null;
+            string imagePath = "";
             var user = await _userManager.Users.Include(u => u.UserAttachments)
                 .FirstOrDefaultAsync(x => x.Id == userId);
             if (user != null)