Browse Source

EmployeeName

zinab_elgendy 1 month ago
parent
commit
aada842a23

+ 4 - 2
MTWorkHR.Application/Dtos/Contract/ContractAllowanceDto.cs

@@ -7,6 +7,7 @@ using System.Text;
 using System.Threading.Tasks;
 using MTWorkHR.Core.Entities.Base;
 using MTWorkHR.Core.Global;
+using Newtonsoft.Json;
 
 namespace MTWorkHR.Application.Models
 {
@@ -17,8 +18,9 @@ namespace MTWorkHR.Application.Models
         [Required]
         public long AllowanceType { get; set; }
         public string? AllowanceDesc { get; set; }
-        public decimal EntitlementPercent { get; set; }// اختيار (مبلغ – يكتب المبلغ)    أو  (نسبة من الراتب – ويظهر المبلغ توماتك)      
-        public decimal EntitlementAmount { get; set; }
+        [JsonProperty(Required = Required.AllowNull)]
+        public decimal? EntitlementPercent { get; set; } = 0;// اختيار (مبلغ – يكتب المبلغ)    أو  (نسبة من الراتب – ويظهر المبلغ توماتك)      
+        public decimal? EntitlementAmount { get; set; } = 0;
         public string? PaymentType { get; set; } // PaymentTypeEnum
 
     }

+ 4 - 0
MTWorkHR.Application/Dtos/Contract/ContractDto.cs

@@ -21,6 +21,10 @@ namespace MTWorkHR.Application.Models
         public string CompanyRepresentativeId { get; set; }
        
         public string UserId { get; set; }
+        [JsonProperty(Required = Required.AllowNull)]
+        public string? EmployeeName { get; set; }
+        [JsonProperty(Required = Required.AllowNull)]
+        public string? EmployeeEmail { get; set; }
       
         public int? JobId { get; set; }
         public int? AcademicQualificationId { get; set; }

+ 12 - 0
MTWorkHR.Application/Services/Contract/ContractService.cs

@@ -98,6 +98,18 @@ namespace MTWorkHR.Application.Services
             var list = MapperObject.Mapper
                 .Map<IList<ContractDto>>(await page.ToListAsync());
 
+            foreach (var item in list)
+            {
+                if (item.UserId != null)
+                {
+                    var user = await _userService.GetUserWithAttachmentById(item.UserId);
+                    if (user != null)
+                    {
+                        item.EmployeeName = user.FirstName + " " + user.LastName;
+                        item.EmployeeEmail = user.Email;
+                    }
+                }
+            }
             var response = new PagingResultDto<ContractDto>
             {
                 Result = list,

+ 25 - 20
MTWorkHR.Application/Services/User/OrderAllocationService.cs

@@ -38,34 +38,39 @@ namespace MTWorkHR.Application.Services
 
         public override async Task<OrderAllocationDto> Create(OrderAllocationDto input)
         {
-            var orderType = await _unitOfWork.OrderType.GetByIdAsync(input.OrderTypeId);
-            var leaveType = input.LeaveTypeId.HasValue && input.LeaveTypeId > 0 ? await _unitOfWork.LeaveType.GetByIdAsync(input.LeaveTypeId.Value): null;
-            var employees = await _user.GetAllEmployees();
-            var period = DateTime.Now.Year;
-            var allocations = new List<OrderAllocation>();
-            foreach (var emp in employees)
+            try
             {
-                if (await _unitOfWork.OrderAllocation.AllocationExists(emp.Id, orderType.Id, input.LeaveTypeId, period))
-                    continue;
-                allocations.Add(new OrderAllocation
+                var orderType = await _unitOfWork.OrderType.GetByIdAsync(input.OrderTypeId);
+                var leaveType = input.LeaveTypeId.HasValue && input.LeaveTypeId > 0 ? await _unitOfWork.LeaveType.GetByIdAsync(input.LeaveTypeId.Value) : null;
+                var employees = await _user.GetAllEmployees();
+                var period = DateTime.Now.Year;
+                var allocations = new List<OrderAllocation>();
+                foreach (var emp in employees)
                 {
-                    EmployeeId = emp.Id,
-                    OrderTypeId = orderType.Id,
-                    LeaveTypeId = leaveType != null ? leaveType.Id : null,
-                    NumberOfDays = leaveType != null ? leaveType.DefaultDays : orderType.DefaultDays,
-                    Period = period
-                });
-            }
+                    if (await _unitOfWork.OrderAllocation.AllocationExists(emp.Id, orderType.Id, input.LeaveTypeId, period))
+                        continue;
+                    allocations.Add(new OrderAllocation
+                    {
+                        EmployeeId = emp.Id,
+                        OrderTypeId = orderType.Id,
+                        LeaveTypeId = leaveType != null ? leaveType.Id : null,
+                        NumberOfDays = leaveType != null ? leaveType.DefaultDays : orderType.DefaultDays,
+                        Period = period
+                    });
+                }
 
-            await _unitOfWork.OrderAllocation.AddRangeAsync(allocations);
-            await _unitOfWork.CompleteAsync();
+                await _unitOfWork.OrderAllocation.AddRangeAsync(allocations);
+                await _unitOfWork.CompleteAsync();
 
-           
+            }catch(Exception ex)
+            {
+                var msg = ex.Message;
+            }
             return input;
 
 
         }
-
+