zinab_elgendy 2 months ago
parent
commit
dd49d221f1

+ 0 - 2
MTWorkHR.API/Controllers/ContractController.cs

@@ -15,8 +15,6 @@ namespace MTWorkHR.API.Controllers
     public class ContractController : ControllerBase
     {
         private readonly IContractService _ContractService;
-        private readonly IContractTaskAttachmentService _ContractTaskAttachmentService;
-        private readonly IProjectStageAttachmentService _ProjectStageAttachmentService;
         private readonly IFileService _fileService;
 
         public ContractController(IContractService UserContractService, IFileService fileService)

+ 32 - 0
MTWorkHR.API/Controllers/HRController.cs

@@ -0,0 +1,32 @@
+using Microsoft.AspNetCore.Authorization;
+
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+using MTWorkHR.Application.Filters;
+using MTWorkHR.Application.Models;
+using MTWorkHR.Application.Services;
+using MTWorkHR.Application.Services.Interfaces;
+
+namespace MTWorkHR.API.Controllers
+{
+    [Route("api/[controller]")]
+    [ApiController]
+    [AppAuthorize]
+    public class HRController : ControllerBase
+    {
+        private readonly IContractService _ContractService;
+
+        public HRController(IContractService UserContractService, IFileService fileService)
+        {
+            _ContractService = UserContractService;
+        }
+        [HttpGet("GetAll")]
+        [ProducesResponseType(StatusCodes.Status200OK)]
+
+        public async Task<ActionResult<List<ContractDto>>> GetAll([FromQuery] ContractPagingInputDto pagingInput)
+        {
+            return Ok(await _ContractService.GetAllForHr(pagingInput));
+        }
+       
+    }
+}

+ 89 - 25
MTWorkHR.Application/Services/Contract/ContractService.cs

@@ -69,6 +69,8 @@ namespace MTWorkHR.Application.Services
         //    var response = Mapper.MapperObject.Mapper.Map<ContractDto>(entity);
         //    return response;
         //}
+       
+
         public async Task<PagingResultDto<ContractDto>> GetAll(ContractPagingInputDto PagingInputDto)
         {
             var res = await _unitOfWork.Contract.GetAllWithChildrenAsync();
@@ -76,7 +78,61 @@ namespace MTWorkHR.Application.Services
 
             if (_globalInfo.UserType != UserTypeEnum.Business)
             {
-               // query = query.Where(m => m.ContractUsers != null && m.ContractUsers.Count > 0 && m.ContractUsers.Count(u=> u.AssignedUserId == _globalInfo.UserId) > 0);
+                // query = query.Where(m => m.ContractUsers != null && m.ContractUsers.Count > 0 && m.ContractUsers.Count(u=> u.AssignedUserId == _globalInfo.UserId) > 0);
+
+            }
+            if (PagingInputDto.Filter != null)
+            {
+                var filter = PagingInputDto.Filter;
+                query = query.Where(u => u.JobDescription != null && u.JobDescription.Contains(filter));
+            }
+
+            if (PagingInputDto.ContractStatusId != null)
+            {
+                query = query.Where(u => (int)u.ContractStatusId == PagingInputDto.ContractStatusId);
+            }
+            if (PagingInputDto.ContractTypeId != null)
+            {
+                query = query.Where(u => (int)u.ContractTypeId == PagingInputDto.ContractTypeId);
+            }
+
+            var order = query.OrderBy(PagingInputDto.OrderByField + " " + PagingInputDto.OrderType);
+
+            var page = order.Skip((PagingInputDto.PageNumber * PagingInputDto.PageSize) - PagingInputDto.PageSize).Take(PagingInputDto.PageSize);
+
+            var total = await query.CountAsync();
+
+            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,
+                Total = total
+            };
+
+            return response;
+        }
+        public async Task<PagingResultDto<ContractDto>> GetAllForHr(ContractPagingInputDto PagingInputDto)
+        {
+            var res = await _unitOfWork.Contract.GetAllWithChildrenAsync();
+            var query = res.Item1;
+
+            if (_globalInfo.UserType != UserTypeEnum.Business)
+            {
+                // query = query.Where(m => m.ContractUsers != null && m.ContractUsers.Count > 0 && m.ContractUsers.Count(u=> u.AssignedUserId == _globalInfo.UserId) > 0);
 
             }
             if (PagingInputDto.Filter != null)
@@ -124,11 +180,11 @@ namespace MTWorkHR.Application.Services
                     }
                 }
             }
-         
-         
 
-           
-           
+
+
+
+
             var response = new PagingResultDto<ContractDto>
             {
                 Result = list,
@@ -156,28 +212,36 @@ namespace MTWorkHR.Application.Services
             return result;
         }
 
-        private async void addVacationAllocation(int noVacationDays, string employeeId, long contractId)
+        private async Task addVacationAllocation(int noVacationDays, string employeeId, long contractId)
         {
-            await _orderAllocationService.Create(new OrderAllocationDto { ContractId = contractId, EmployeeId = employeeId, OrderTypeId = 1, LeaveTypeId = 1, NumberOfDays = noVacationDays, Period = DateTime.Now.Year });
-            var orderTypes = await _unitOfWork.OrderType.GetAllAsync();
-            var leaveTypes = await _unitOfWork.LeaveType.GetAllAsync();
-            foreach(var orderType in orderTypes.Item1)
+            try 
+            { 
+                await _orderAllocationService.Create(new OrderAllocationDto { ContractId = contractId, EmployeeId = employeeId, OrderTypeId = 1, LeaveTypeId = 1, NumberOfDays = noVacationDays, Period = DateTime.Now.Year });
+               // var orderTypes = await _unitOfWork.OrderType.GetAllAsync();
+               // var leaveTypes = await _unitOfWork.LeaveType.GetAllAsync();
+                //foreach (var orderType in orderTypes.Item1)
+                //{
+                //    foreach (var leaveType in leaveTypes.Item1)
+                //    {
+                //        if (orderType.Id != 1 && leaveType.Id != 1 && (leaveType.DefaultDays > 0 || orderType.DefaultDays > 0))
+                //        {
+                //            await _orderAllocationService.Create(new OrderAllocationDto
+                //            {
+                //                ContractId = contractId,
+                //                EmployeeId = employeeId,
+                //                OrderTypeId = (int)orderType.Id,
+                //                LeaveTypeId = (int)leaveType.Id,
+                //                NumberOfDays = leaveType.DefaultDays > 0 ? leaveType.DefaultDays : orderType.DefaultDays,
+                //                Period = DateTime.Now.Year
+                //            }
+                //            );
+                //        }
+                //    }
+                //}
+            }
+            catch(Exception ex)
             {
-                foreach (var leaveType in leaveTypes.Item1)
-                {
-                    if(orderType.Id !=1 && leaveType.Id != 1 && (leaveType.DefaultDays> 0 || orderType.DefaultDays > 0))
-                    {
-                        await _orderAllocationService.Create(new OrderAllocationDto 
-                        { 
-                            ContractId = contractId, 
-                            EmployeeId = employeeId, 
-                            OrderTypeId =(int) orderType.Id, 
-                            LeaveTypeId = (int)leaveType.Id, 
-                            NumberOfDays = leaveType.DefaultDays > 0 ? leaveType.DefaultDays : orderType.DefaultDays, 
-                            Period = DateTime.Now.Year }
-                        );
-                    }
-                }
+                throw ;
             }
             
         }

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

@@ -8,6 +8,7 @@ namespace MTWorkHR.Application.Services.Interfaces
     public interface IContractService : IService<Contract, ContractDto, ContractDto>
     {
         Task<PagingResultDto<ContractDto>> GetAll(ContractPagingInputDto PagingInputDto);
+        Task<PagingResultDto<ContractDto>> GetAllForHr(ContractPagingInputDto PagingInputDto);
         Task<bool> ChangeStatus(long contractId, int statusId);
 
     }

+ 19 - 12
MTWorkHR.Application/Services/User/OrderRequestService.cs

@@ -130,20 +130,24 @@ namespace MTWorkHR.Application.Services
             {
                 input.RequestingEmployeeId = _globalInfo.UserId;
             }
-            var allocation = await _unitOfWork.OrderAllocation.GetUserAllocations(input.RequestingEmployeeId, input.OrderTypeId, input.LeaveTypeId, period);
-
-            if (allocation is null)
-            {
-                throw new AppException(ExceptionEnum.NoVacationBalance, "You do not have any allocations for this leave type.");
-            }
-            else
+            if(input.OrderTypeId == 1 &&  input.LeaveTypeId == 1) // Annual vacation in contract
             {
-                int daysRequested = (int)(input.EndDate - input.StartDate).TotalDays;
-                if (daysRequested > allocation.NumberOfDays)
+                var allocation = await _unitOfWork.OrderAllocation.GetUserAllocations(input.RequestingEmployeeId, input.OrderTypeId, input.LeaveTypeId, period);
+
+                if (allocation is null)
+                {
+                    throw new AppException(ExceptionEnum.NoVacationBalance, "You do not have any allocations for this leave type.");
+                }
+                else
                 {
-                    throw new AppException(ExceptionEnum.NoVacationBalance, "You do not have enough days for this request");
+                    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);
             orderRequest = await _unitOfWork.OrderRequest.AddAsync(orderRequest);
             await _unitOfWork.CompleteAsync();
@@ -205,8 +209,11 @@ namespace MTWorkHR.Application.Services
             if (orderRequest.OrderStatus == ApprovalStatusEnum.Approved)
             {
                 var allocation = await _unitOfWork.OrderAllocation.GetUserAllocations(orderRequest.RequestingEmployeeId, orderRequest.OrderTypeId, orderRequest.LeaveTypeId, DateTime.Now.Year);
-                int daysRequested = !orderRequest.EndDate.HasValue ? 1 : (int)(orderRequest.EndDate.Value - orderRequest.StartDate).TotalDays;
-                allocation.NumberOfDays -= daysRequested;
+                if (allocation != null)
+                {
+                    int daysRequested = !orderRequest.EndDate.HasValue ? 1 : (int)(orderRequest.EndDate.Value - orderRequest.StartDate).TotalDays;
+                    allocation.NumberOfDays -= daysRequested;
+                }
             }
             await _unitOfWork.CompleteAsync();
             var response = MapperObject.Mapper.Map<OrderRequestDto>(orderRequest);