Ver código fonte

OrderAllocation_request

zinab_elgendy 10 meses atrás
pai
commit
bb81f7a9ba
47 arquivos alterados com 8442 adições e 5 exclusões
  1. 39 0
      MTWorkHR.API/Controllers/LookupController.cs
  2. 63 0
      MTWorkHR.API/Controllers/OrderAllocationController.cs
  3. 69 0
      MTWorkHR.API/Controllers/OrderRequestController.cs
  4. 3 0
      MTWorkHR.Application/ApplicationServiceRegistration.cs
  5. 1 1
      MTWorkHR.Application/Dtos/Attendance/AttendanceDto.cs
  6. 19 0
      MTWorkHR.Application/Dtos/Attendance/LeaveTypeDto.cs
  7. 26 0
      MTWorkHR.Application/Dtos/Attendance/OrderAllocationDto.cs
  8. 29 0
      MTWorkHR.Application/Dtos/Attendance/OrderRequestDto.cs
  9. 19 0
      MTWorkHR.Application/Dtos/Attendance/OrderTypeDto.cs
  10. 1 0
      MTWorkHR.Application/Identity/IUserService.cs
  11. 5 0
      MTWorkHR.Application/Mapper/MappingProfile.cs
  12. 1 1
      MTWorkHR.Application/Middlewares/LoggingMiddleware.cs
  13. 45 0
      MTWorkHR.Application/Services/Base/LookupService.cs
  14. 11 0
      MTWorkHR.Application/Services/Interfaces/ILeaveAllocationService.cs
  15. 13 0
      MTWorkHR.Application/Services/Interfaces/ILookupService.cs
  16. 13 0
      MTWorkHR.Application/Services/Interfaces/IOrderRequestService.cs
  17. 72 0
      MTWorkHR.Application/Services/User/OrderAllocationService.cs
  18. 108 0
      MTWorkHR.Application/Services/User/OrderRequestService.cs
  19. 12 0
      MTWorkHR.Application/Services/User/UserService.cs
  20. 1 1
      MTWorkHR.Core/Entities/Attendance/Attendance.cs
  21. 17 0
      MTWorkHR.Core/Entities/Attendance/LeaveType.cs
  22. 27 0
      MTWorkHR.Core/Entities/Attendance/OrderAllocation.cs
  23. 32 0
      MTWorkHR.Core/Entities/Attendance/OrderRequest.cs
  24. 17 0
      MTWorkHR.Core/Entities/Attendance/OrderType.cs
  25. 1 0
      MTWorkHR.Core/Global/Enum/ApprovalStatusEnum.cs
  26. 1 1
      MTWorkHR.Core/Global/Enum/LeaveTypeEnum.cs
  27. 15 0
      MTWorkHR.Core/IRepositories/User/ILeaveTypeRepository.cs
  28. 18 0
      MTWorkHR.Core/IRepositories/User/IOrderAllocationRepository.cs
  29. 16 0
      MTWorkHR.Core/IRepositories/User/IOrderRequestRepository.cs
  30. 15 0
      MTWorkHR.Core/IRepositories/User/IOrderTypeRepository.cs
  31. 4 0
      MTWorkHR.Core/IUnitOfWork/IUnitOfWork.cs
  32. 61 0
      MTWorkHR.Infrastructure/Configurations/LeaveTypeConfiguration.cs
  33. 61 0
      MTWorkHR.Infrastructure/Configurations/OrderTypeConfiguration.cs
  34. 5 0
      MTWorkHR.Infrastructure/DBContext/HRDataContext.cs
  35. 4 0
      MTWorkHR.Infrastructure/InfrastructureServiceRegistration.cs
  36. 2190 0
      MTWorkHR.Infrastructure/Migrations/20240318090642_orderReq.Designer.cs
  37. 130 0
      MTWorkHR.Infrastructure/Migrations/20240318090642_orderReq.cs
  38. 2241 0
      MTWorkHR.Infrastructure/Migrations/20240319090340_altrOrder.Designer.cs
  39. 161 0
      MTWorkHR.Infrastructure/Migrations/20240319090340_altrOrder.cs
  40. 2248 0
      MTWorkHR.Infrastructure/Migrations/20240320120546_leaveType.Designer.cs
  41. 224 0
      MTWorkHR.Infrastructure/Migrations/20240320120546_leaveType.cs
  42. 283 0
      MTWorkHR.Infrastructure/Migrations/HRDataContextModelSnapshot.cs
  43. 19 0
      MTWorkHR.Infrastructure/Repositories/User/LeaveTypeRepository.cs
  44. 43 0
      MTWorkHR.Infrastructure/Repositories/User/OrderAllocationRepository.cs
  45. 26 0
      MTWorkHR.Infrastructure/Repositories/User/OrderRequestRepository.cs
  46. 19 0
      MTWorkHR.Infrastructure/Repositories/User/OrderTypeRepository.cs
  47. 14 1
      MTWorkHR.Infrastructure/UnitOfWork/UnitOfWork.cs

+ 39 - 0
MTWorkHR.API/Controllers/LookupController.cs

@@ -0,0 +1,39 @@
+using Microsoft.AspNetCore.Authorization;
+
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+using MTWorkHR.Application.Identity;
+using MTWorkHR.Application.Models;
+using MTWorkHR.Application.Services.Interfaces;
+using MTWorkHR.Identity.Services;
+
+namespace MTWorkHR.API.Controllers
+{
+    [Route("api/[controller]")]
+    [ApiController]
+    public class LookupController : ControllerBase
+    {
+        private readonly ILookupService _LookupService;
+        public LookupController(ILookupService UserLookupService)
+        {
+            this._LookupService = UserLookupService;
+        }
+        [HttpGet("GetAllLeaveType")]
+        [ProducesResponseType(StatusCodes.Status200OK)]
+
+        public async Task<ActionResult<List<LeaveTypeDto>>> GetAllLeaveType()
+        {
+            return await _LookupService.GetAllLeaveType();
+        }
+        [HttpGet("GetAllOrderType")]
+        [ProducesResponseType(StatusCodes.Status200OK)]
+
+        public async Task<ActionResult<List<OrderTypeDto>>> GetAllOrderType()
+        {
+            return await _LookupService.GetAllOrderType();
+        }
+
+
+
+    }
+}

+ 63 - 0
MTWorkHR.API/Controllers/OrderAllocationController.cs

@@ -0,0 +1,63 @@
+using Microsoft.AspNetCore.Authorization;
+
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+using MTWorkHR.Application.Identity;
+using MTWorkHR.Application.Models;
+using MTWorkHR.Application.Services.Interfaces;
+using MTWorkHR.Identity.Services;
+
+namespace MTWorkHR.API.Controllers
+{
+    [Route("api/[controller]")]
+    [ApiController]
+    public class OrderAllocationController : ControllerBase
+    {
+        private readonly IOrderAllocationService _OrderAllocationService;
+        public OrderAllocationController(IOrderAllocationService UserOrderAllocationService)
+        {
+            this._OrderAllocationService = UserOrderAllocationService;
+        }
+        [HttpGet("GetAll")]
+        [ProducesResponseType(StatusCodes.Status200OK)]
+
+        public async Task<ActionResult<List<OrderAllocationDto>>> GetAll([FromQuery] PagingInputDto pagingInput)
+        {
+            return Ok(await _OrderAllocationService.GetAll(pagingInput));
+        }
+        [HttpGet("Get")]
+        [ProducesResponseType(StatusCodes.Status200OK)]
+
+        public async Task<ActionResult<OrderAllocationDto>> Get(long OrderAllocationId)
+        {
+            return Ok(await _OrderAllocationService.GetById(OrderAllocationId));
+        }
+
+
+        [HttpPost("Create")]
+        [ProducesResponseType(StatusCodes.Status200OK)]
+        public async Task<ActionResult<OrderAllocationDto>> Create([FromBody] OrderAllocationDto input)
+        {
+            return await _OrderAllocationService.Create(input);
+        }
+
+        [HttpPost("Update")]
+        [ProducesResponseType(StatusCodes.Status200OK)]
+
+        public async Task Update([FromBody] OrderAllocationDto input)
+        {
+            await _OrderAllocationService.Update(input);
+        }
+
+        [HttpPost("Delete")]
+        [ProducesResponseType(StatusCodes.Status200OK)]
+
+        public async Task Delete(long id)
+        {
+            await _OrderAllocationService.Delete(id);
+        }
+
+
+
+    }
+}

+ 69 - 0
MTWorkHR.API/Controllers/OrderRequestController.cs

@@ -0,0 +1,69 @@
+using Microsoft.AspNetCore.Authorization;
+
+using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Mvc;
+using MTWorkHR.Application.Identity;
+using MTWorkHR.Application.Models;
+using MTWorkHR.Application.Services.Interfaces;
+using MTWorkHR.Identity.Services;
+
+namespace MTWorkHR.API.Controllers
+{
+    [Route("api/[controller]")]
+    [ApiController]
+    public class OrderRequestController : ControllerBase
+    {
+        private readonly IOrderRequestService _LeaveRequestService;
+        public OrderRequestController(IOrderRequestService UserLeaveRequestService)
+        {
+            this._LeaveRequestService = UserLeaveRequestService;
+        }
+        [HttpGet("GetAll")]
+        [ProducesResponseType(StatusCodes.Status200OK)]
+
+        public async Task<ActionResult<List<OrderRequestDto>>> GetAll([FromQuery] PagingInputDto pagingInput)
+        {
+            return Ok(await _LeaveRequestService.GetAll(pagingInput));
+        }
+        [HttpGet("Get")]
+        [ProducesResponseType(StatusCodes.Status200OK)]
+
+        public async Task<ActionResult<OrderRequestDto>> Get(long LeaveRequestId)
+        {
+            return Ok(await _LeaveRequestService.GetById(LeaveRequestId));
+        }
+
+
+        [HttpPost("Create")]
+        [ProducesResponseType(StatusCodes.Status200OK)]
+        public async Task<ActionResult<OrderRequestDto>> Create([FromBody] OrderRequestDto input)
+        {
+            return await _LeaveRequestService.Create(input);
+        }
+
+        [HttpPost("Update")]
+        [ProducesResponseType(StatusCodes.Status200OK)]
+
+        public async Task Update([FromBody] OrderRequestDto input)
+        {
+            await _LeaveRequestService.Update(input);
+        }
+
+        [HttpPost("Delete")]
+        [ProducesResponseType(StatusCodes.Status200OK)]
+
+        public async Task Delete(long id)
+        {
+            await _LeaveRequestService.Delete(id);
+        }
+        [HttpPost("ChangeStatus")]
+        [ProducesResponseType(StatusCodes.Status200OK)]
+
+        public async Task ChangeStatus(long id, int statusId)
+        {
+            await _LeaveRequestService.ChangeStatus(id, statusId);
+        }
+
+
+    }
+}

+ 3 - 0
MTWorkHR.Application/ApplicationServiceRegistration.cs

@@ -29,6 +29,9 @@ namespace MTWorkHR.Application
             services.AddScoped<ITeamService, TeamService>();
             services.AddScoped<IMeetingService, MeetingService>();
             services.AddScoped<IAttendanceService, AttendanceService>();
+            services.AddScoped<IOrderAllocationService, OrderAllocationService>();
+            services.AddScoped<IOrderRequestService, OrderRequestService>();
+            services.AddScoped<ILookupService, LookupService>();
             
             return services;
         }

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

@@ -19,7 +19,7 @@ namespace MTWorkHR.Application.Models
         public DateTime? CheckOutTime { get; set; }
         public DateTime AttendanceDate { get; set; }
         public string? WeekDay { get; set; }
-        public LeaveTypeEnum LeaveType { get; set; }
+        public CheckOutEnum LeaveType { get; set; }
 
         [MaxLength(250)]
         public string? LeaveReason { get; set; }

+ 19 - 0
MTWorkHR.Application/Dtos/Attendance/LeaveTypeDto.cs

@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using MTWorkHR.Application.Models;
+using MTWorkHR.Core.Entities.Base;
+using MTWorkHR.Core.Global;
+
+namespace MTWorkHR.Application.Models
+{
+    public class LeaveTypeDto : EntityDto
+    {
+        public string NameAr { get; set; }
+        public string NameEn { get; set; }
+        public int DefaultDays { get; set; }
+    }
+}

+ 26 - 0
MTWorkHR.Application/Dtos/Attendance/OrderAllocationDto.cs

@@ -0,0 +1,26 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using MTWorkHR.Application.Models;
+using MTWorkHR.Core.Entities;
+using MTWorkHR.Core.Entities.Base;
+using MTWorkHR.Core.Global;
+
+namespace MTWorkHR.Application.Models
+{
+    public class OrderAllocationDto : EntityDto
+    {
+        public int? NumberOfDays { get; set; }
+        public int OrderTypeId { get; set; }
+        public string? EmployeeId { get; set; }
+        public int? LeaveTypeId { get; set; }
+        public int? Period { get; set; }
+        public OrderTypeDto? OrderType { get; set; }
+        public Employee? Employee { get; set; }
+        public LeaveTypeDto? LeaveType { get; set; }
+    
+    }
+}

+ 29 - 0
MTWorkHR.Application/Dtos/Attendance/OrderRequestDto.cs

@@ -0,0 +1,29 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using MTWorkHR.Application.Models;
+using MTWorkHR.Core.Entities;
+using MTWorkHR.Core.Entities.Base;
+using MTWorkHR.Core.Global;
+
+namespace MTWorkHR.Application.Models
+{
+    public class OrderRequestDto : EntityDto
+    {
+        public DateTime StartDate { get; set; }
+        public DateTime EndDate { get; set; }
+        public string RequestingEmployeeId { get; set; }
+        public int OrderTypeId { get; set; }
+        public int? LeaveTypeId { get; set; }
+        public string? RequestComments { get; set; }
+        public ApprovalStatusEnum OrderStatus { get; set; }
+        public int? CountryId { get; set; }
+        public int? CityId { get; set; }
+        public OrderTypeDto? OrderType { get; set; }
+        public LeaveTypeDto? LeaveType { get; set; }
+        public Employee? Employee { get; set; }
+    }
+}

+ 19 - 0
MTWorkHR.Application/Dtos/Attendance/OrderTypeDto.cs

@@ -0,0 +1,19 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using MTWorkHR.Application.Models;
+using MTWorkHR.Core.Entities.Base;
+using MTWorkHR.Core.Global;
+
+namespace MTWorkHR.Application.Models
+{
+    public class OrderTypeDto :EntityDto
+    {
+        public string NameAr { get; set; }
+        public string NameEn { get; set; }
+        public int DefaultDays { get; set; }
+    }
+}

+ 1 - 0
MTWorkHR.Application/Identity/IUserService.cs

@@ -12,6 +12,7 @@ namespace MTWorkHR.Application.Identity
     {
         Task<List<UserDto>> GetAll();
         Task<UserDto> GetById(string userId);
+        Task<List<UserDto>> GetAllEmployees();
 
 
         Task Delete(string id);

+ 5 - 0
MTWorkHR.Application/Mapper/MappingProfile.cs

@@ -2,6 +2,7 @@
 using Microsoft.AspNetCore.Identity;
 using MTWorkHR.Application.Models;
 using MTWorkHR.Core.Entities;
+using MTWorkHR.Core.Entities.User;
 using MTWorkHR.Core.Global;
 using MTWorkHR.Infrastructure.Entities;
 using System;
@@ -71,6 +72,10 @@ namespace MTWorkHR.Application.Mapper
             CreateMap<Attendance, AttendanceDto>().ForMember(d=> d.WeekDay , o=> o.MapFrom(s=> s.AttendanceDate.DayOfWeek)).ReverseMap()
                 .ForMember(d => d.CreateDate, o => o.Ignore());
 
+            CreateMap<OrderAllocation, OrderAllocationDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore());
+            CreateMap<OrderRequest, OrderRequestDto>().ReverseMap().ForMember(d => d.CreateDate, o => o.Ignore());
+            CreateMap<OrderType, OrderTypeDto>().ReverseMap();
+            CreateMap<LeaveType, LeaveTypeDto>().ReverseMap();
 
 
         }

+ 1 - 1
MTWorkHR.Application/Middlewares/LoggingMiddleware.cs

@@ -64,7 +64,7 @@ namespace MTWorkHR.Application.Middlewares
                 //**Get Log service and entity info by refliction
 
                 //Get target log entity by the traget controller name
-                Type? entityType = Type.GetType("MTWorkHR.Core.Entities." + controllerName + "Log, MTWorkHR.Core");
+                Type? entityType = Type.GetType("MTWorkHR.Core.Entities." + "User" + "Log, MTWorkHR.Core");
 
                 var logServiceWithGenericType = typeof(LogService<>).MakeGenericType(entityType);
 

+ 45 - 0
MTWorkHR.Application/Services/Base/LookupService.cs

@@ -0,0 +1,45 @@
+using Microsoft.AspNetCore.Identity;
+using Microsoft.AspNetCore.WebUtilities;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.Extensions.Configuration;
+using MTWorkHR.Application.Identity;
+using MTWorkHR.Application.Mapper;
+using MTWorkHR.Application.Models;
+using MTWorkHR.Core.Global;
+using MTWorkHR.Core.IRepositories;
+using MTWorkHR.Core.UnitOfWork;
+using MTWorkHR.Infrastructure.Entities;
+using MTWorkHR.Application.Services.Interfaces;
+using MTWorkHR.Core.Email;
+using MTWorkHR.Core.Entities;
+using MTWorkHR.Infrastructure.UnitOfWorks;
+using MTWorkHR.Core.IDto;
+using MTWorkHR.Infrastructure.Repositories;
+
+namespace MTWorkHR.Application.Services
+{
+    public class LookupService : ILookupService
+    {
+        private readonly IUnitOfWork _unitOfWork;
+
+        public LookupService(IUnitOfWork unitOfWork)
+        {
+            _unitOfWork = unitOfWork;
+        }
+
+        public async Task<List<LeaveTypeDto>> GetAllLeaveType()
+        {
+            var result = await _unitOfWork.LeaveType.GetAllAsync();
+            var list = MapperObject.Mapper.Map<List<LeaveTypeDto>>(result.Item1);
+            return list;
+        }
+
+        public async Task<List<OrderTypeDto>> GetAllOrderType()
+        {
+            var entity = await _unitOfWork.OrderType.GetAllAsync();
+            var response = MapperObject.Mapper.Map<List<OrderTypeDto>>(entity.Item1);
+            return response;
+        }
+
+    }
+}

+ 11 - 0
MTWorkHR.Application/Services/Interfaces/ILeaveAllocationService.cs

@@ -0,0 +1,11 @@
+
+using MTWorkHR.Application.Models;
+using MTWorkHR.Core.Entities;
+using System.Threading.Tasks;
+
+namespace MTWorkHR.Application.Services.Interfaces
+{
+    public interface IOrderAllocationService : IService<OrderAllocation, OrderAllocationDto, OrderAllocationDto>
+    {
+    }
+}

+ 13 - 0
MTWorkHR.Application/Services/Interfaces/ILookupService.cs

@@ -0,0 +1,13 @@
+
+using MTWorkHR.Application.Models;
+using MTWorkHR.Core.Entities;
+using System.Threading.Tasks;
+
+namespace MTWorkHR.Application.Services.Interfaces
+{
+    public interface ILookupService 
+    {
+        Task<List<OrderTypeDto>> GetAllOrderType();
+        Task<List<LeaveTypeDto>> GetAllLeaveType();
+    }
+}

+ 13 - 0
MTWorkHR.Application/Services/Interfaces/IOrderRequestService.cs

@@ -0,0 +1,13 @@
+
+using MTWorkHR.Application.Models;
+using MTWorkHR.Core.Entities;
+using MTWorkHR.Core.Entities.User;
+using System.Threading.Tasks;
+
+namespace MTWorkHR.Application.Services.Interfaces
+{
+    public interface IOrderRequestService : IService< OrderRequest, OrderRequestDto, OrderRequestDto>
+    {
+        Task<OrderRequestDto> ChangeStatus(long id, int statusId);
+    }
+}

+ 72 - 0
MTWorkHR.Application/Services/User/OrderAllocationService.cs

@@ -0,0 +1,72 @@
+using Microsoft.AspNetCore.Identity;
+using Microsoft.AspNetCore.WebUtilities;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.Extensions.Configuration;
+using MTWorkHR.Application.Identity;
+using MTWorkHR.Application.Mapper;
+using MTWorkHR.Application.Models;
+using MTWorkHR.Core.Global;
+using MTWorkHR.Core.IRepositories;
+using MTWorkHR.Core.UnitOfWork;
+using MTWorkHR.Infrastructure.Entities;
+using MTWorkHR.Application.Services.Interfaces;
+using MTWorkHR.Core.Email;
+using MTWorkHR.Core.Entities;
+using MTWorkHR.Infrastructure.UnitOfWorks;
+
+namespace MTWorkHR.Application.Services
+{
+    public class OrderAllocationService : BaseService<OrderAllocation, OrderAllocationDto, OrderAllocationDto>, IOrderAllocationService
+    {
+        private readonly IUnitOfWork _unitOfWork;
+        private readonly IUserService _user;
+      
+        public OrderAllocationService(IUnitOfWork unitOfWork, IUserService user) :base(unitOfWork)
+        {
+            _unitOfWork = unitOfWork;
+            _user = user;
+        }
+
+
+        public override async Task<OrderAllocationDto> GetById(long id)
+        {
+            var entity = await _unitOfWork.OrderAllocation.GetByIdWithAllChildren(id);
+            var response = MapperObject.Mapper.Map<OrderAllocationDto>(entity);
+            return response;
+        }
+
+
+        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)
+            {
+                if (await _unitOfWork.OrderAllocation.AllocationExists(emp.Id, orderType.Id, period))
+                    continue;
+                allocations.Add(new OrderAllocation
+                {
+                    EmployeeId = emp.Id,
+                    OrderTypeId = orderType.Id,
+                    NumberOfDays = leaveType != null ? leaveType.DefaultDays : orderType.DefaultDays,
+                    Period = period
+                });
+            }
+
+            await _unitOfWork.OrderAllocation.AddRangeAsync(allocations);
+            await _unitOfWork.CompleteAsync();
+
+           
+            return input;
+
+
+        }
+
+
+
+
+    }
+}

+ 108 - 0
MTWorkHR.Application/Services/User/OrderRequestService.cs

@@ -0,0 +1,108 @@
+using Microsoft.AspNetCore.Identity;
+using Microsoft.AspNetCore.WebUtilities;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.Extensions.Configuration;
+using MTWorkHR.Application.Identity;
+using MTWorkHR.Application.Mapper;
+using MTWorkHR.Application.Models;
+using MTWorkHR.Core.Global;
+using MTWorkHR.Core.IRepositories;
+using MTWorkHR.Core.UnitOfWork;
+using MTWorkHR.Infrastructure.Entities;
+using MTWorkHR.Application.Services.Interfaces;
+using MTWorkHR.Core.Email;
+using MTWorkHR.Core.Entities;
+using MTWorkHR.Infrastructure.UnitOfWorks;
+using MTWorkHR.Core.Entities.User;
+using Azure;
+using System.Security.Claims;
+using MTWorkHR.Core.Entities.Base;
+
+namespace MTWorkHR.Application.Services
+{
+    public class OrderRequestService : BaseService<OrderRequest, OrderRequestDto, OrderRequestDto>, IOrderRequestService
+    {
+        private readonly IUnitOfWork _unitOfWork;
+        private readonly IMailSender _emailSender;
+        private readonly ApplicationUserManager _userManager;
+
+        public OrderRequestService(IUnitOfWork unitOfWork, IMailSender emailSender, ApplicationUserManager userManager) : base(unitOfWork)
+        {
+            _unitOfWork = unitOfWork;
+            _emailSender = emailSender;
+            _userManager = userManager;
+        }
+
+
+        public override async Task<OrderRequestDto> GetById(long id)
+        {
+            var entity = await _unitOfWork.OrderRequest.GetByIdAsync(id);
+            var response = MapperObject.Mapper.Map<OrderRequestDto>(entity);
+            return response;
+        }
+        public override async Task<OrderRequestDto> Create(OrderRequestDto input)
+        {
+            var period = DateTime.Now.Year;
+            var allocation = await _unitOfWork.OrderAllocation.GetUserAllocations(input.RequestingEmployeeId, input.OrderTypeId, input.LeaveTypeId.HasValue?input.LeaveTypeId.Value:0, period);
+
+            if (allocation is null)
+            {
+                throw new AppException(ExceptionEnum.RecordNotExist, "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.RecordNotExist, "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();
+
+            try
+            {
+                var requestingEmployee = await _userManager.Users.FirstOrDefaultAsync(x => x.Id == input.RequestingEmployeeId);
+                var sendMailResult = await _emailSender.SendEmail(new EmailMessage
+                {
+                    To = requestingEmployee.Email,
+                    Body = $"Your leave request for {input.StartDate:D} to {input.EndDate:D} " +
+                    $"has been submitted successfully.",
+                    Subject = "Leave Request Submitted",
+                    userId = input.RequestingEmployeeId
+                });
+                if (!sendMailResult)
+                {
+                    throw new AppException("User created, but could not send the email!");
+                }
+            }
+            catch (Exception ex)
+            {
+                //// Log or handle error, but don't throw...
+            }
+            var response = MapperObject.Mapper.Map<OrderRequestDto>(orderRequest);
+
+            return response;
+        }
+
+
+        public async Task<OrderRequestDto> ChangeStatus(long id, int statusId )
+        {
+            var orderRequest = await _unitOfWork.OrderRequest.GetByIdAsync(id);
+            orderRequest.OrderStatus = (ApprovalStatusEnum)statusId;
+            if (orderRequest.OrderStatus == ApprovalStatusEnum.Approved)
+            {
+                var allocation = await _unitOfWork.OrderAllocation.GetUserAllocations(orderRequest.RequestingEmployeeId, orderRequest.OrderTypeId, orderRequest.LeaveTypeId.HasValue ? orderRequest.LeaveTypeId.Value : 0, DateTime.Now.Year);
+                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);
+            return response;
+        }
+
+
+
+    }
+}

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

@@ -66,6 +66,18 @@ namespace MTWorkHR.Application.Services
             }).ToList();
         }
 
+        public async Task<List<UserDto>> GetAllEmployees()
+        {
+            var employees = await _userManager.GetUsersInRoleAsync("Employee");
+            return employees.Select(e => new UserDto
+            {
+                Email = e.Email,
+                FirstName = e.FirstName,
+                LastName = e.LastName,
+                Id = e.Id
+            }).ToList();
+        }
+
         public async Task Delete(string id)
         {
             var user = await _userManager.FindByIdAsync(id);

+ 1 - 1
MTWorkHR.Core/Entities/Attendance/Attendance.cs

@@ -17,7 +17,7 @@ namespace MTWorkHR.Core.Entities
         public DateTime? CheckInTime { get; set; }
         public DateTime? CheckOutTime { get; set; }
         public DateTime AttendanceDate { get; set; }
-        public LeaveTypeEnum LeaveType { get; set; }
+        public CheckOutEnum LeaveType { get; set; }
 
         [MaxLength(250)]
         public string? LeaveReason { get; set; }

+ 17 - 0
MTWorkHR.Core/Entities/Attendance/LeaveType.cs

@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using MTWorkHR.Core.Entities.Base;
+
+namespace MTWorkHR.Core.Entities
+{
+    public class LeaveType : Entity
+    {
+        public string NameAr { get; set; }
+        public string NameEn { get; set; }
+        public int DefaultDays { get; set; }
+    }
+}

+ 27 - 0
MTWorkHR.Core/Entities/Attendance/OrderAllocation.cs

@@ -0,0 +1,27 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.ComponentModel.DataAnnotations.Schema;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using MTWorkHR.Core.Entities.Base;
+
+namespace MTWorkHR.Core.Entities
+{
+    public class OrderAllocation : AuditEntity
+    {
+        public int NumberOfDays { get; set; }
+        [ForeignKey("OrderTypeId")]
+        public OrderType OrderType { get; set; }
+        public long OrderTypeId { get; set; }
+
+        [ForeignKey("LeaveTypeId")]
+        public LeaveType? LeaveType { get; set; }
+        public long? LeaveTypeId { get; set; }
+
+        public int Period { get; set; }
+        public string EmployeeId { get; set; }
+
+    }
+}

+ 32 - 0
MTWorkHR.Core/Entities/Attendance/OrderRequest.cs

@@ -0,0 +1,32 @@
+using MTWorkHR.Core.Entities.Base;
+using MTWorkHR.Core.Global;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.ComponentModel.DataAnnotations.Schema;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace MTWorkHR.Core.Entities.User
+{
+    public class OrderRequest : FullAuditEntity
+    {
+        public DateTime StartDate { get; set; }
+        public DateTime? EndDate { get; set; }
+        [Required]
+        [ForeignKey("OrderTypeId")]
+        public OrderType OrderType { get; set; }
+        public long OrderTypeId { get; set; }
+        [ForeignKey("LeaveTypeId")]
+        public LeaveType? LeaveType { get; set; }
+        public long? LeaveTypeId { get; set; }
+
+        public string? RequestComments { get; set; }
+        public ApprovalStatusEnum? OrderStatus { get; set; }
+        public string RequestingEmployeeId { get; set; }
+        public int? CountryId{ get; set; }
+        public int? CityId { get; set; }
+
+    }
+}

+ 17 - 0
MTWorkHR.Core/Entities/Attendance/OrderType.cs

@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using MTWorkHR.Core.Entities.Base;
+
+namespace MTWorkHR.Core.Entities
+{
+    public class OrderType : Entity
+    {
+        public string NameAr { get; set; }
+        public string NameEn { get; set; }
+        public int DefaultDays { get; set; }
+    }
+}

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

@@ -11,5 +11,6 @@ namespace MTWorkHR.Core.Global
         Pending = 1,
         Approved = 2,
         Rejected = 3,
+        Canceled = 4,
     }
 }

+ 1 - 1
MTWorkHR.Core/Global/Enum/LeaveTypeEnum.cs

@@ -6,7 +6,7 @@ using System.Threading.Tasks;
 
 namespace MTWorkHR.Core.Global
 {
-    public enum LeaveTypeEnum
+    public enum CheckOutEnum
     {
         Leave = 1,
         Meeting = 2,

+ 15 - 0
MTWorkHR.Core/IRepositories/User/ILeaveTypeRepository.cs

@@ -0,0 +1,15 @@
+using MTWorkHR.Core.Entities;
+using MTWorkHR.Core.IRepositories.Base;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace MTWorkHR.Core.IRepositories
+{
+    public interface ILeaveTypeRepository : IRepository<LeaveType>
+    {
+
+    }
+}

+ 18 - 0
MTWorkHR.Core/IRepositories/User/IOrderAllocationRepository.cs

@@ -0,0 +1,18 @@
+using MTWorkHR.Core.Entities;
+using MTWorkHR.Core.IRepositories.Base;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace MTWorkHR.Core.IRepositories
+{
+    public interface IOrderAllocationRepository : IRepository<OrderAllocation>
+    {
+        Task<bool> AllocationExists(string userId, long orderTypeId, int period);
+        Task<OrderAllocation> GetByIdWithAllChildren(long id);
+        Task<OrderAllocation> GetUserAllocations(string userId, long orderTypeId, long leaveTypeId, int period);
+
+    }
+}

+ 16 - 0
MTWorkHR.Core/IRepositories/User/IOrderRequestRepository.cs

@@ -0,0 +1,16 @@
+using MTWorkHR.Core.Entities;
+using MTWorkHR.Core.Entities.User;
+using MTWorkHR.Core.IRepositories.Base;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace MTWorkHR.Core.IRepositories
+{
+    public interface IOrderRequestRepository : IRepository<OrderRequest>
+    {
+
+    }
+}

+ 15 - 0
MTWorkHR.Core/IRepositories/User/IOrderTypeRepository.cs

@@ -0,0 +1,15 @@
+using MTWorkHR.Core.Entities;
+using MTWorkHR.Core.IRepositories.Base;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace MTWorkHR.Core.IRepositories
+{
+    public interface IOrderTypeRepository : IRepository<OrderType>
+    {
+
+    }
+}

+ 4 - 0
MTWorkHR.Core/IUnitOfWork/IUnitOfWork.cs

@@ -18,6 +18,10 @@ namespace MTWorkHR.Core.UnitOfWork
         ITeamRepository Team{ get; }
         IMeetingRepository Meeting{ get; }
         IAttendanceRepository Attendance { get; }
+        IOrderTypeRepository OrderType { get; }
+        IOrderRequestRepository OrderRequest { get; }
+        IOrderAllocationRepository OrderAllocation { get; }
+        ILeaveTypeRepository LeaveType{ get; }
         Task<int> CompleteAsync();
 
         void BeginTran();

+ 61 - 0
MTWorkHR.Infrastructure/Configurations/LeaveTypeConfiguration.cs

@@ -0,0 +1,61 @@
+using Microsoft.AspNetCore.Identity;
+using Microsoft.EntityFrameworkCore.Metadata.Builders;
+using Microsoft.EntityFrameworkCore;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using MTWorkHR.Infrastructure.Entities;
+using MTWorkHR.Core.Entities.Base;
+using MTWorkHR.Core.Entities;
+
+namespace MTWorkHR.Infrastructure.Configurations
+{
+    public class LeaveTypeConfiguration : IEntityTypeConfiguration<LeaveType>
+    {
+        
+        public void Configure(EntityTypeBuilder<LeaveType> builder)
+        {
+            
+            builder.HasData(
+                new LeaveType
+                {
+                    Id = 1,
+                    NameEn = "Annual Leave",
+                    NameAr = "أجازة سنوية",
+                    DefaultDays = 21
+                },
+                 new LeaveType
+                 {
+                     Id = 2,
+                     NameEn = "Sick Leave",
+                     NameAr = "أجازة مرضية",
+                     DefaultDays = 15
+                 },
+                new LeaveType
+                {
+                    Id = 3,
+                    NameEn = "Marriage Leave",
+                    NameAr = "أجازة زواج",
+                    DefaultDays = 20
+                },
+                new LeaveType
+                {
+                    Id = 4,
+                    NameEn = "Paternity leave", //(after closed from employee / manager)
+                    NameAr = "أجازة وضع",
+                    DefaultDays = 10
+
+                },
+                new LeaveType
+                {
+                    Id = 5,
+                    NameEn = "Emergency leave",
+                    NameAr = "أجازة طارئة",
+                    DefaultDays = 10
+                }
+               ) ;
+        }
+    }
+}

+ 61 - 0
MTWorkHR.Infrastructure/Configurations/OrderTypeConfiguration.cs

@@ -0,0 +1,61 @@
+using Microsoft.AspNetCore.Identity;
+using Microsoft.EntityFrameworkCore.Metadata.Builders;
+using Microsoft.EntityFrameworkCore;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using MTWorkHR.Infrastructure.Entities;
+using MTWorkHR.Core.Entities.Base;
+using MTWorkHR.Core.Entities;
+
+namespace MTWorkHR.Infrastructure.Configurations
+{
+    public class OrderTypeConfiguration : IEntityTypeConfiguration<OrderType>
+    {
+        
+        public void Configure(EntityTypeBuilder<OrderType> builder)
+        {
+            
+            builder.HasData(
+                new OrderType
+                {
+                    Id = 1,
+                    NameEn = "Leave",
+                    NameAr = "إذن",
+                    DefaultDays = 2
+                },
+                 new OrderType
+                 {
+                     Id = 2,
+                     NameEn = "Medical",
+                     NameAr = "طبية",
+                     DefaultDays = 15
+                 },
+                new OrderType
+                {
+                    Id = 3,
+                    NameEn = "Overtime",
+                    NameAr = "وقت إضافي",
+                    DefaultDays = 20
+                },
+                new OrderType
+                {
+                    Id = 4,
+                    NameEn = "Business trip", //(after closed from employee / manager)
+                    NameAr = "رحلة عمل",
+                    DefaultDays = 0
+
+                },
+                new OrderType
+                {
+                    Id = 5,
+                    NameEn = "Course",
+                    NameAr = "دورة تدريبية",
+                    DefaultDays = 0
+                }
+               ) ;
+        }
+    }
+}

+ 5 - 0
MTWorkHR.Infrastructure/DBContext/HRDataContext.cs

@@ -6,6 +6,7 @@ using MTWorkHR.Core.Global;
 using MTWorkHR.Infrastructure.Entities;
 using MTWorkHR.Infrastructure.Data;
 using System.Reflection.Emit;
+using MTWorkHR.Core.Entities.User;
 
 
 namespace MTWorkHR.Infrastructure.DBContext
@@ -36,6 +37,10 @@ namespace MTWorkHR.Infrastructure.DBContext
         public DbSet<Team> Teams { get; set; }
         public DbSet<Meeting> Meetings { get; set; }
         public DbSet<Attendance> Attendances { get; set; }
+        public DbSet<OrderType> OrderTypes { get; set; }
+        public DbSet<LeaveType> LeaveTypes { get; set; }
+        public DbSet<OrderAllocation> OrderAllocations { get; set; }
+        public DbSet<OrderRequest> OrderRequests { get; set; }
         //------------------------Logs------------------------
         public DbSet<UserLog> UserLogs { get; set; }
         public DbSet<AuthLog> AuthLogs { get; set; }

+ 4 - 0
MTWorkHR.Infrastructure/InfrastructureServiceRegistration.cs

@@ -68,6 +68,10 @@ namespace MTWorkHR.Infrastructure
             services.AddScoped(typeof(ITeamRepository), typeof(TeamRepository));
             services.AddScoped(typeof(IMeetingRepository), typeof(MeetingRepository));
             services.AddScoped(typeof(IAttendanceRepository), typeof(AttendanceRepository));
+            services.AddScoped(typeof(IOrderAllocationRepository), typeof(OrderAllocationRepository));
+            services.AddScoped(typeof(IOrderRequestRepository), typeof(OrderRequestRepository));
+            services.AddScoped(typeof(IOrderTypeRepository), typeof(OrderTypeRepository));
+            services.AddScoped(typeof(ILeaveTypeRepository), typeof(LeaveTypeRepository));
 
 
 

Diferenças do arquivo suprimidas por serem muito extensas
+ 2190 - 0
MTWorkHR.Infrastructure/Migrations/20240318090642_orderReq.Designer.cs


+ 130 - 0
MTWorkHR.Infrastructure/Migrations/20240318090642_orderReq.cs

@@ -0,0 +1,130 @@
+using System;
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional
+
+namespace MTWorkHR.Infrastructure.Migrations
+{
+    /// <inheritdoc />
+    public partial class orderReq : Migration
+    {
+        /// <inheritdoc />
+        protected override void Up(MigrationBuilder migrationBuilder)
+        {
+            migrationBuilder.CreateTable(
+                name: "OrderTypes",
+                columns: table => new
+                {
+                    Id = table.Column<long>(type: "bigint", nullable: false)
+                        .Annotation("SqlServer:Identity", "1, 1"),
+                    CreateUser = table.Column<string>(type: "nvarchar(450)", maxLength: 450, nullable: true),
+                    UpdateUser = table.Column<string>(type: "nvarchar(450)", maxLength: 450, nullable: true),
+                    CreateDate = table.Column<DateTime>(type: "datetime2", nullable: false),
+                    UpdateDate = table.Column<DateTime>(type: "datetime2", nullable: true),
+                    NameAr = table.Column<string>(type: "nvarchar(max)", nullable: false),
+                    NameEn = table.Column<string>(type: "nvarchar(max)", nullable: false),
+                    DefaultDays = table.Column<int>(type: "int", nullable: false)
+                },
+                constraints: table =>
+                {
+                    table.PrimaryKey("PK_OrderTypes", x => x.Id);
+                });
+
+            migrationBuilder.CreateTable(
+                name: "OrderAllocations",
+                columns: table => new
+                {
+                    Id = table.Column<long>(type: "bigint", nullable: false)
+                        .Annotation("SqlServer:Identity", "1, 1"),
+                    CreateUser = table.Column<string>(type: "nvarchar(450)", maxLength: 450, nullable: true),
+                    UpdateUser = table.Column<string>(type: "nvarchar(450)", maxLength: 450, nullable: true),
+                    CreateDate = table.Column<DateTime>(type: "datetime2", nullable: false),
+                    UpdateDate = table.Column<DateTime>(type: "datetime2", nullable: true),
+                    NumberOfDays = table.Column<int>(type: "int", nullable: false),
+                    OrderTypeId = table.Column<long>(type: "bigint", nullable: false),
+                    Period = table.Column<int>(type: "int", nullable: false),
+                    EmployeeId = table.Column<string>(type: "nvarchar(max)", nullable: false)
+                },
+                constraints: table =>
+                {
+                    table.PrimaryKey("PK_OrderAllocations", x => x.Id);
+                    table.ForeignKey(
+                        name: "FK_OrderAllocations_OrderTypes_OrderTypeId",
+                        column: x => x.OrderTypeId,
+                        principalTable: "OrderTypes",
+                        principalColumn: "Id",
+                        onDelete: ReferentialAction.Cascade);
+                });
+
+            migrationBuilder.CreateTable(
+                name: "OrderRequests",
+                columns: table => new
+                {
+                    Id = table.Column<long>(type: "bigint", nullable: false)
+                        .Annotation("SqlServer:Identity", "1, 1"),
+                    CreateUser = table.Column<string>(type: "nvarchar(450)", maxLength: 450, nullable: true),
+                    UpdateUser = table.Column<string>(type: "nvarchar(450)", maxLength: 450, nullable: true),
+                    CreateDate = table.Column<DateTime>(type: "datetime2", nullable: false),
+                    UpdateDate = table.Column<DateTime>(type: "datetime2", nullable: true),
+                    IsDeleted = table.Column<bool>(type: "bit", nullable: false),
+                    DeleteUserId = table.Column<string>(type: "nvarchar(450)", maxLength: 450, nullable: true),
+                    StartDate = table.Column<DateTime>(type: "datetime2", nullable: false),
+                    EndDate = table.Column<DateTime>(type: "datetime2", nullable: false),
+                    OrderTypeId = table.Column<long>(type: "bigint", nullable: false),
+                    DateRequested = table.Column<DateTime>(type: "datetime2", nullable: false),
+                    RequestComments = table.Column<string>(type: "nvarchar(max)", nullable: true),
+                    DateActioned = table.Column<DateTime>(type: "datetime2", nullable: true),
+                    IsApproved = table.Column<bool>(type: "bit", nullable: true),
+                    IsCancelled = table.Column<bool>(type: "bit", nullable: false),
+                    RequestingEmployeeId = table.Column<string>(type: "nvarchar(max)", nullable: false)
+                },
+                constraints: table =>
+                {
+                    table.PrimaryKey("PK_OrderRequests", x => x.Id);
+                    table.ForeignKey(
+                        name: "FK_OrderRequests_OrderTypes_OrderTypeId",
+                        column: x => x.OrderTypeId,
+                        principalTable: "OrderTypes",
+                        principalColumn: "Id",
+                        onDelete: ReferentialAction.Cascade);
+                });
+
+            migrationBuilder.InsertData(
+                table: "OrderTypes",
+                columns: new[] { "Id", "CreateDate", "CreateUser", "DefaultDays", "NameAr", "NameEn", "UpdateDate", "UpdateUser" },
+                values: new object[,]
+                {
+                    { 1L, new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), null, 2, "إذن", "Leave", null, null },
+                    { 2L, new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), null, 15, "أجازة مرضية", "Sick Leave", null, null },
+                    { 3L, new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), null, 20, "وقت إضافي", "Overtime", null, null },
+                    { 4L, new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), null, 0, "رحلة عمل", "Business trip", null, null },
+                    { 5L, new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), null, 0, "دورة تدريبية", "Course", null, null }
+                });
+
+            migrationBuilder.CreateIndex(
+                name: "IX_OrderAllocations_OrderTypeId",
+                table: "OrderAllocations",
+                column: "OrderTypeId");
+
+            migrationBuilder.CreateIndex(
+                name: "IX_OrderRequests_OrderTypeId",
+                table: "OrderRequests",
+                column: "OrderTypeId");
+        }
+
+        /// <inheritdoc />
+        protected override void Down(MigrationBuilder migrationBuilder)
+        {
+            migrationBuilder.DropTable(
+                name: "OrderAllocations");
+
+            migrationBuilder.DropTable(
+                name: "OrderRequests");
+
+            migrationBuilder.DropTable(
+                name: "OrderTypes");
+        }
+    }
+}

Diferenças do arquivo suprimidas por serem muito extensas
+ 2241 - 0
MTWorkHR.Infrastructure/Migrations/20240319090340_altrOrder.Designer.cs


+ 161 - 0
MTWorkHR.Infrastructure/Migrations/20240319090340_altrOrder.cs

@@ -0,0 +1,161 @@
+using System;
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace MTWorkHR.Infrastructure.Migrations
+{
+    /// <inheritdoc />
+    public partial class altrOrder : Migration
+    {
+        /// <inheritdoc />
+        protected override void Up(MigrationBuilder migrationBuilder)
+        {
+            migrationBuilder.DropColumn(
+                name: "DateActioned",
+                table: "OrderRequests");
+
+            migrationBuilder.DropColumn(
+                name: "DateRequested",
+                table: "OrderRequests");
+
+            migrationBuilder.DropColumn(
+                name: "IsApproved",
+                table: "OrderRequests");
+
+            migrationBuilder.DropColumn(
+                name: "IsCancelled",
+                table: "OrderRequests");
+
+            migrationBuilder.AlterColumn<DateTime>(
+                name: "EndDate",
+                table: "OrderRequests",
+                type: "datetime2",
+                nullable: true,
+                oldClrType: typeof(DateTime),
+                oldType: "datetime2");
+
+            migrationBuilder.AddColumn<int>(
+                name: "CityId",
+                table: "OrderRequests",
+                type: "int",
+                nullable: true);
+
+            migrationBuilder.AddColumn<int>(
+                name: "CountryId",
+                table: "OrderRequests",
+                type: "int",
+                nullable: true);
+
+            migrationBuilder.AddColumn<long>(
+                name: "LeaveTypeId",
+                table: "OrderRequests",
+                type: "bigint",
+                nullable: true);
+
+            migrationBuilder.AddColumn<int>(
+                name: "OrderStatus",
+                table: "OrderRequests",
+                type: "int",
+                nullable: true);
+
+            migrationBuilder.CreateTable(
+                name: "LeaveTypes",
+                columns: table => new
+                {
+                    Id = table.Column<long>(type: "bigint", nullable: false)
+                        .Annotation("SqlServer:Identity", "1, 1"),
+                    CreateUser = table.Column<string>(type: "nvarchar(450)", maxLength: 450, nullable: true),
+                    UpdateUser = table.Column<string>(type: "nvarchar(450)", maxLength: 450, nullable: true),
+                    CreateDate = table.Column<DateTime>(type: "datetime2", nullable: false),
+                    UpdateDate = table.Column<DateTime>(type: "datetime2", nullable: true),
+                    NameAr = table.Column<string>(type: "nvarchar(max)", nullable: false),
+                    NameEn = table.Column<string>(type: "nvarchar(max)", nullable: false),
+                    DefaultDays = table.Column<int>(type: "int", nullable: false)
+                },
+                constraints: table =>
+                {
+                    table.PrimaryKey("PK_LeaveTypes", x => x.Id);
+                });
+
+            migrationBuilder.CreateIndex(
+                name: "IX_OrderRequests_LeaveTypeId",
+                table: "OrderRequests",
+                column: "LeaveTypeId");
+
+            migrationBuilder.AddForeignKey(
+                name: "FK_OrderRequests_LeaveTypes_LeaveTypeId",
+                table: "OrderRequests",
+                column: "LeaveTypeId",
+                principalTable: "LeaveTypes",
+                principalColumn: "Id");
+        }
+
+        /// <inheritdoc />
+        protected override void Down(MigrationBuilder migrationBuilder)
+        {
+            migrationBuilder.DropForeignKey(
+                name: "FK_OrderRequests_LeaveTypes_LeaveTypeId",
+                table: "OrderRequests");
+
+            migrationBuilder.DropTable(
+                name: "LeaveTypes");
+
+            migrationBuilder.DropIndex(
+                name: "IX_OrderRequests_LeaveTypeId",
+                table: "OrderRequests");
+
+            migrationBuilder.DropColumn(
+                name: "CityId",
+                table: "OrderRequests");
+
+            migrationBuilder.DropColumn(
+                name: "CountryId",
+                table: "OrderRequests");
+
+            migrationBuilder.DropColumn(
+                name: "LeaveTypeId",
+                table: "OrderRequests");
+
+            migrationBuilder.DropColumn(
+                name: "OrderStatus",
+                table: "OrderRequests");
+
+            migrationBuilder.AlterColumn<DateTime>(
+                name: "EndDate",
+                table: "OrderRequests",
+                type: "datetime2",
+                nullable: false,
+                defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
+                oldClrType: typeof(DateTime),
+                oldType: "datetime2",
+                oldNullable: true);
+
+            migrationBuilder.AddColumn<DateTime>(
+                name: "DateActioned",
+                table: "OrderRequests",
+                type: "datetime2",
+                nullable: true);
+
+            migrationBuilder.AddColumn<DateTime>(
+                name: "DateRequested",
+                table: "OrderRequests",
+                type: "datetime2",
+                nullable: false,
+                defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));
+
+            migrationBuilder.AddColumn<bool>(
+                name: "IsApproved",
+                table: "OrderRequests",
+                type: "bit",
+                nullable: true);
+
+            migrationBuilder.AddColumn<bool>(
+                name: "IsCancelled",
+                table: "OrderRequests",
+                type: "bit",
+                nullable: false,
+                defaultValue: false);
+        }
+    }
+}

Diferenças do arquivo suprimidas por serem muito extensas
+ 2248 - 0
MTWorkHR.Infrastructure/Migrations/20240320120546_leaveType.Designer.cs


+ 224 - 0
MTWorkHR.Infrastructure/Migrations/20240320120546_leaveType.cs

@@ -0,0 +1,224 @@
+using System;
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional
+
+namespace MTWorkHR.Infrastructure.Migrations
+{
+    /// <inheritdoc />
+    public partial class leaveType : Migration
+    {
+        /// <inheritdoc />
+        protected override void Up(MigrationBuilder migrationBuilder)
+        {
+            migrationBuilder.DropColumn(
+                name: "CreateDate",
+                table: "OrderTypes");
+
+            migrationBuilder.DropColumn(
+                name: "CreateUser",
+                table: "OrderTypes");
+
+            migrationBuilder.DropColumn(
+                name: "UpdateDate",
+                table: "OrderTypes");
+
+            migrationBuilder.DropColumn(
+                name: "UpdateUser",
+                table: "OrderTypes");
+
+            migrationBuilder.DropColumn(
+                name: "CreateDate",
+                table: "LeaveTypes");
+
+            migrationBuilder.DropColumn(
+                name: "CreateUser",
+                table: "LeaveTypes");
+
+            migrationBuilder.DropColumn(
+                name: "UpdateDate",
+                table: "LeaveTypes");
+
+            migrationBuilder.DropColumn(
+                name: "UpdateUser",
+                table: "LeaveTypes");
+
+            migrationBuilder.AddColumn<long>(
+                name: "LeaveTypeId",
+                table: "OrderAllocations",
+                type: "bigint",
+                nullable: true);
+
+            migrationBuilder.InsertData(
+                table: "LeaveTypes",
+                columns: new[] { "Id", "DefaultDays", "NameAr", "NameEn" },
+                values: new object[,]
+                {
+                    { 1L, 21, "أجازة سنوية", "Annual Leave" },
+                    { 2L, 15, "أجازة مرضية", "Sick Leave" },
+                    { 3L, 20, "أجازة زواج", "Marriage Leave" },
+                    { 4L, 10, "أجازة وضع", "Paternity leave" },
+                    { 5L, 10, "أجازة طارئة", "Emergency leave" }
+                });
+
+            migrationBuilder.UpdateData(
+                table: "OrderTypes",
+                keyColumn: "Id",
+                keyValue: 2L,
+                columns: new[] { "NameAr", "NameEn" },
+                values: new object[] { "طبية", "Medical" });
+
+            migrationBuilder.CreateIndex(
+                name: "IX_OrderAllocations_LeaveTypeId",
+                table: "OrderAllocations",
+                column: "LeaveTypeId");
+
+            migrationBuilder.AddForeignKey(
+                name: "FK_OrderAllocations_LeaveTypes_LeaveTypeId",
+                table: "OrderAllocations",
+                column: "LeaveTypeId",
+                principalTable: "LeaveTypes",
+                principalColumn: "Id");
+        }
+
+        /// <inheritdoc />
+        protected override void Down(MigrationBuilder migrationBuilder)
+        {
+            migrationBuilder.DropForeignKey(
+                name: "FK_OrderAllocations_LeaveTypes_LeaveTypeId",
+                table: "OrderAllocations");
+
+            migrationBuilder.DropIndex(
+                name: "IX_OrderAllocations_LeaveTypeId",
+                table: "OrderAllocations");
+
+            migrationBuilder.DeleteData(
+                table: "LeaveTypes",
+                keyColumn: "Id",
+                keyValue: 1L);
+
+            migrationBuilder.DeleteData(
+                table: "LeaveTypes",
+                keyColumn: "Id",
+                keyValue: 2L);
+
+            migrationBuilder.DeleteData(
+                table: "LeaveTypes",
+                keyColumn: "Id",
+                keyValue: 3L);
+
+            migrationBuilder.DeleteData(
+                table: "LeaveTypes",
+                keyColumn: "Id",
+                keyValue: 4L);
+
+            migrationBuilder.DeleteData(
+                table: "LeaveTypes",
+                keyColumn: "Id",
+                keyValue: 5L);
+
+            migrationBuilder.DropColumn(
+                name: "LeaveTypeId",
+                table: "OrderAllocations");
+
+            migrationBuilder.AddColumn<DateTime>(
+                name: "CreateDate",
+                table: "OrderTypes",
+                type: "datetime2",
+                nullable: false,
+                defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified))
+                .Annotation("Relational:ColumnOrder", 3);
+
+            migrationBuilder.AddColumn<string>(
+                name: "CreateUser",
+                table: "OrderTypes",
+                type: "nvarchar(450)",
+                maxLength: 450,
+                nullable: true)
+                .Annotation("Relational:ColumnOrder", 1);
+
+            migrationBuilder.AddColumn<DateTime>(
+                name: "UpdateDate",
+                table: "OrderTypes",
+                type: "datetime2",
+                nullable: true)
+                .Annotation("Relational:ColumnOrder", 4);
+
+            migrationBuilder.AddColumn<string>(
+                name: "UpdateUser",
+                table: "OrderTypes",
+                type: "nvarchar(450)",
+                maxLength: 450,
+                nullable: true)
+                .Annotation("Relational:ColumnOrder", 2);
+
+            migrationBuilder.AddColumn<DateTime>(
+                name: "CreateDate",
+                table: "LeaveTypes",
+                type: "datetime2",
+                nullable: false,
+                defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified))
+                .Annotation("Relational:ColumnOrder", 3);
+
+            migrationBuilder.AddColumn<string>(
+                name: "CreateUser",
+                table: "LeaveTypes",
+                type: "nvarchar(450)",
+                maxLength: 450,
+                nullable: true)
+                .Annotation("Relational:ColumnOrder", 1);
+
+            migrationBuilder.AddColumn<DateTime>(
+                name: "UpdateDate",
+                table: "LeaveTypes",
+                type: "datetime2",
+                nullable: true)
+                .Annotation("Relational:ColumnOrder", 4);
+
+            migrationBuilder.AddColumn<string>(
+                name: "UpdateUser",
+                table: "LeaveTypes",
+                type: "nvarchar(450)",
+                maxLength: 450,
+                nullable: true)
+                .Annotation("Relational:ColumnOrder", 2);
+
+            migrationBuilder.UpdateData(
+                table: "OrderTypes",
+                keyColumn: "Id",
+                keyValue: 1L,
+                columns: new[] { "CreateDate", "CreateUser", "UpdateDate", "UpdateUser" },
+                values: new object[] { new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), null, null, null });
+
+            migrationBuilder.UpdateData(
+                table: "OrderTypes",
+                keyColumn: "Id",
+                keyValue: 2L,
+                columns: new[] { "CreateDate", "CreateUser", "NameAr", "NameEn", "UpdateDate", "UpdateUser" },
+                values: new object[] { new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), null, "أجازة مرضية", "Sick Leave", null, null });
+
+            migrationBuilder.UpdateData(
+                table: "OrderTypes",
+                keyColumn: "Id",
+                keyValue: 3L,
+                columns: new[] { "CreateDate", "CreateUser", "UpdateDate", "UpdateUser" },
+                values: new object[] { new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), null, null, null });
+
+            migrationBuilder.UpdateData(
+                table: "OrderTypes",
+                keyColumn: "Id",
+                keyValue: 4L,
+                columns: new[] { "CreateDate", "CreateUser", "UpdateDate", "UpdateUser" },
+                values: new object[] { new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), null, null, null });
+
+            migrationBuilder.UpdateData(
+                table: "OrderTypes",
+                keyColumn: "Id",
+                keyValue: 5L,
+                columns: new[] { "CreateDate", "CreateUser", "UpdateDate", "UpdateUser" },
+                values: new object[] { new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified), null, null, null });
+        }
+    }
+}

+ 283 - 0
MTWorkHR.Infrastructure/Migrations/HRDataContextModelSnapshot.cs

@@ -373,6 +373,68 @@ namespace MTWorkHR.Infrastructure.Migrations
                     b.ToTable("FileLogs");
                 });
 
+            modelBuilder.Entity("MTWorkHR.Core.Entities.LeaveType", b =>
+                {
+                    b.Property<long>("Id")
+                        .ValueGeneratedOnAdd()
+                        .HasColumnType("bigint")
+                        .HasColumnOrder(0);
+
+                    SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<long>("Id"));
+
+                    b.Property<int>("DefaultDays")
+                        .HasColumnType("int");
+
+                    b.Property<string>("NameAr")
+                        .IsRequired()
+                        .HasColumnType("nvarchar(max)");
+
+                    b.Property<string>("NameEn")
+                        .IsRequired()
+                        .HasColumnType("nvarchar(max)");
+
+                    b.HasKey("Id");
+
+                    b.ToTable("LeaveTypes");
+
+                    b.HasData(
+                        new
+                        {
+                            Id = 1L,
+                            DefaultDays = 21,
+                            NameAr = "أجازة سنوية",
+                            NameEn = "Annual Leave"
+                        },
+                        new
+                        {
+                            Id = 2L,
+                            DefaultDays = 15,
+                            NameAr = "أجازة مرضية",
+                            NameEn = "Sick Leave"
+                        },
+                        new
+                        {
+                            Id = 3L,
+                            DefaultDays = 20,
+                            NameAr = "أجازة زواج",
+                            NameEn = "Marriage Leave"
+                        },
+                        new
+                        {
+                            Id = 4L,
+                            DefaultDays = 10,
+                            NameAr = "أجازة وضع",
+                            NameEn = "Paternity leave"
+                        },
+                        new
+                        {
+                            Id = 5L,
+                            DefaultDays = 10,
+                            NameAr = "أجازة طارئة",
+                            NameEn = "Emergency leave"
+                        });
+                });
+
             modelBuilder.Entity("MTWorkHR.Core.Entities.Meeting", b =>
                 {
                     b.Property<long>("Id")
@@ -536,6 +598,120 @@ namespace MTWorkHR.Infrastructure.Migrations
                     b.ToTable("MeetingUser");
                 });
 
+            modelBuilder.Entity("MTWorkHR.Core.Entities.OrderAllocation", b =>
+                {
+                    b.Property<long>("Id")
+                        .ValueGeneratedOnAdd()
+                        .HasColumnType("bigint")
+                        .HasColumnOrder(0);
+
+                    SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<long>("Id"));
+
+                    b.Property<DateTime>("CreateDate")
+                        .HasColumnType("datetime2")
+                        .HasColumnOrder(3);
+
+                    b.Property<string>("CreateUser")
+                        .HasMaxLength(450)
+                        .HasColumnType("nvarchar(450)")
+                        .HasColumnOrder(1);
+
+                    b.Property<string>("EmployeeId")
+                        .IsRequired()
+                        .HasColumnType("nvarchar(max)");
+
+                    b.Property<long?>("LeaveTypeId")
+                        .HasColumnType("bigint");
+
+                    b.Property<int>("NumberOfDays")
+                        .HasColumnType("int");
+
+                    b.Property<long>("OrderTypeId")
+                        .HasColumnType("bigint");
+
+                    b.Property<int>("Period")
+                        .HasColumnType("int");
+
+                    b.Property<DateTime?>("UpdateDate")
+                        .HasColumnType("datetime2")
+                        .HasColumnOrder(4);
+
+                    b.Property<string>("UpdateUser")
+                        .HasMaxLength(450)
+                        .HasColumnType("nvarchar(450)")
+                        .HasColumnOrder(2);
+
+                    b.HasKey("Id");
+
+                    b.HasIndex("LeaveTypeId");
+
+                    b.HasIndex("OrderTypeId");
+
+                    b.ToTable("OrderAllocations");
+                });
+
+            modelBuilder.Entity("MTWorkHR.Core.Entities.OrderType", b =>
+                {
+                    b.Property<long>("Id")
+                        .ValueGeneratedOnAdd()
+                        .HasColumnType("bigint")
+                        .HasColumnOrder(0);
+
+                    SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<long>("Id"));
+
+                    b.Property<int>("DefaultDays")
+                        .HasColumnType("int");
+
+                    b.Property<string>("NameAr")
+                        .IsRequired()
+                        .HasColumnType("nvarchar(max)");
+
+                    b.Property<string>("NameEn")
+                        .IsRequired()
+                        .HasColumnType("nvarchar(max)");
+
+                    b.HasKey("Id");
+
+                    b.ToTable("OrderTypes");
+
+                    b.HasData(
+                        new
+                        {
+                            Id = 1L,
+                            DefaultDays = 2,
+                            NameAr = "إذن",
+                            NameEn = "Leave"
+                        },
+                        new
+                        {
+                            Id = 2L,
+                            DefaultDays = 15,
+                            NameAr = "طبية",
+                            NameEn = "Medical"
+                        },
+                        new
+                        {
+                            Id = 3L,
+                            DefaultDays = 20,
+                            NameAr = "وقت إضافي",
+                            NameEn = "Overtime"
+                        },
+                        new
+                        {
+                            Id = 4L,
+                            DefaultDays = 0,
+                            NameAr = "رحلة عمل",
+                            NameEn = "Business trip"
+                        },
+                        new
+                        {
+                            Id = 5L,
+                            DefaultDays = 0,
+                            NameAr = "دورة تدريبية",
+                            NameEn = "Course"
+                        });
+                });
+
             modelBuilder.Entity("MTWorkHR.Core.Entities.Permission", b =>
                 {
                     b.Property<long>("Id")
@@ -888,6 +1064,79 @@ namespace MTWorkHR.Infrastructure.Migrations
                     b.ToTable("TeamUser");
                 });
 
+            modelBuilder.Entity("MTWorkHR.Core.Entities.User.OrderRequest", b =>
+                {
+                    b.Property<long>("Id")
+                        .ValueGeneratedOnAdd()
+                        .HasColumnType("bigint")
+                        .HasColumnOrder(0);
+
+                    SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<long>("Id"));
+
+                    b.Property<int?>("CityId")
+                        .HasColumnType("int");
+
+                    b.Property<int?>("CountryId")
+                        .HasColumnType("int");
+
+                    b.Property<DateTime>("CreateDate")
+                        .HasColumnType("datetime2")
+                        .HasColumnOrder(3);
+
+                    b.Property<string>("CreateUser")
+                        .HasMaxLength(450)
+                        .HasColumnType("nvarchar(450)")
+                        .HasColumnOrder(1);
+
+                    b.Property<string>("DeleteUserId")
+                        .HasMaxLength(450)
+                        .HasColumnType("nvarchar(450)")
+                        .HasColumnOrder(8);
+
+                    b.Property<DateTime?>("EndDate")
+                        .HasColumnType("datetime2");
+
+                    b.Property<bool>("IsDeleted")
+                        .HasColumnType("bit")
+                        .HasColumnOrder(7);
+
+                    b.Property<long?>("LeaveTypeId")
+                        .HasColumnType("bigint");
+
+                    b.Property<int?>("OrderStatus")
+                        .HasColumnType("int");
+
+                    b.Property<long>("OrderTypeId")
+                        .HasColumnType("bigint");
+
+                    b.Property<string>("RequestComments")
+                        .HasColumnType("nvarchar(max)");
+
+                    b.Property<string>("RequestingEmployeeId")
+                        .IsRequired()
+                        .HasColumnType("nvarchar(max)");
+
+                    b.Property<DateTime>("StartDate")
+                        .HasColumnType("datetime2");
+
+                    b.Property<DateTime?>("UpdateDate")
+                        .HasColumnType("datetime2")
+                        .HasColumnOrder(4);
+
+                    b.Property<string>("UpdateUser")
+                        .HasMaxLength(450)
+                        .HasColumnType("nvarchar(450)")
+                        .HasColumnOrder(2);
+
+                    b.HasKey("Id");
+
+                    b.HasIndex("LeaveTypeId");
+
+                    b.HasIndex("OrderTypeId");
+
+                    b.ToTable("OrderRequests");
+                });
+
             modelBuilder.Entity("MTWorkHR.Core.Entities.UserLog", b =>
                 {
                     b.Property<long>("Id")
@@ -1754,6 +2003,23 @@ namespace MTWorkHR.Infrastructure.Migrations
                     b.Navigation("Meeting");
                 });
 
+            modelBuilder.Entity("MTWorkHR.Core.Entities.OrderAllocation", b =>
+                {
+                    b.HasOne("MTWorkHR.Core.Entities.LeaveType", "LeaveType")
+                        .WithMany()
+                        .HasForeignKey("LeaveTypeId");
+
+                    b.HasOne("MTWorkHR.Core.Entities.OrderType", "OrderType")
+                        .WithMany()
+                        .HasForeignKey("OrderTypeId")
+                        .OnDelete(DeleteBehavior.Cascade)
+                        .IsRequired();
+
+                    b.Navigation("LeaveType");
+
+                    b.Navigation("OrderType");
+                });
+
             modelBuilder.Entity("MTWorkHR.Core.Entities.TeamUser", b =>
                 {
                     b.HasOne("MTWorkHR.Core.Entities.Team", "Team")
@@ -1765,6 +2031,23 @@ namespace MTWorkHR.Infrastructure.Migrations
                     b.Navigation("Team");
                 });
 
+            modelBuilder.Entity("MTWorkHR.Core.Entities.User.OrderRequest", b =>
+                {
+                    b.HasOne("MTWorkHR.Core.Entities.LeaveType", "LeaveType")
+                        .WithMany()
+                        .HasForeignKey("LeaveTypeId");
+
+                    b.HasOne("MTWorkHR.Core.Entities.OrderType", "OrderType")
+                        .WithMany()
+                        .HasForeignKey("OrderTypeId")
+                        .OnDelete(DeleteBehavior.Cascade)
+                        .IsRequired();
+
+                    b.Navigation("LeaveType");
+
+                    b.Navigation("OrderType");
+                });
+
             modelBuilder.Entity("MTWorkHR.Core.Entities.UserTask", b =>
                 {
                     b.HasOne("MTWorkHR.Core.Entities.Project", "Project")

+ 19 - 0
MTWorkHR.Infrastructure/Repositories/User/LeaveTypeRepository.cs

@@ -0,0 +1,19 @@
+using Microsoft.EntityFrameworkCore;
+using MTWorkHR.Core.Entities;
+using MTWorkHR.Core.IDto;
+using MTWorkHR.Core.IRepositories;
+using MTWorkHR.Infrastructure.Entities;
+using MTWorkHR.Infrastructure.DBContext;
+
+namespace MTWorkHR.Infrastructure.Repositories
+{
+    public class LeaveTypeRepository : Repository<LeaveType>, ILeaveTypeRepository
+    {
+        private readonly DbSet<LeaveType> dbSet;
+        public LeaveTypeRepository(HRDataContext context) : base(context)
+        {
+            dbSet = context.Set<LeaveType>();
+        }
+        
+    }
+}

+ 43 - 0
MTWorkHR.Infrastructure/Repositories/User/OrderAllocationRepository.cs

@@ -0,0 +1,43 @@
+using Microsoft.EntityFrameworkCore;
+using MTWorkHR.Core.Entities;
+using MTWorkHR.Core.IDto;
+using MTWorkHR.Core.IRepositories;
+using MTWorkHR.Infrastructure.Entities;
+using MTWorkHR.Infrastructure.DBContext;
+
+namespace MTWorkHR.Infrastructure.Repositories
+{
+    public class OrderAllocationRepository : Repository<OrderAllocation>, IOrderAllocationRepository
+    {
+        private readonly DbSet<OrderAllocation> dbSet;
+        public OrderAllocationRepository(HRDataContext context) : base(context)
+        {
+            dbSet = context.Set<OrderAllocation>();
+
+        }
+        public async Task<OrderAllocation> GetByIdWithAllChildren(long id)
+        {
+            return await dbSet
+                .Include(x => x.OrderType)
+                .FirstOrDefaultAsync(x => x.Id == id);
+        }
+
+
+     
+
+        public async Task<bool> AllocationExists(string userId, long orderTypeId, int period)
+        {
+            return await dbSet.AnyAsync(q => q.EmployeeId == userId
+                                        && q.OrderTypeId == orderTypeId
+                                        && q.Period == period);
+        }
+
+        public async Task<OrderAllocation> GetUserAllocations(string userId, long orderTypeId, long leaveTypeId, int period)
+        {
+            return await dbSet.FirstOrDefaultAsync(q => q.EmployeeId == userId
+                                        && q.OrderTypeId == orderTypeId
+                                          && q.Period == period
+                                          && (leaveTypeId == 0 || leaveTypeId == q.LeaveTypeId));
+        }
+    }
+}

+ 26 - 0
MTWorkHR.Infrastructure/Repositories/User/OrderRequestRepository.cs

@@ -0,0 +1,26 @@
+using Microsoft.EntityFrameworkCore;
+using MTWorkHR.Core.Entities;
+using MTWorkHR.Core.IDto;
+using MTWorkHR.Core.IRepositories;
+using MTWorkHR.Infrastructure.Entities;
+using MTWorkHR.Infrastructure.DBContext;
+using MTWorkHR.Core.Entities.User;
+
+namespace MTWorkHR.Infrastructure.Repositories
+{
+    public class OrderRequestRepository : Repository<OrderRequest>, IOrderRequestRepository
+    {
+        private readonly DbSet<OrderRequest> dbSet;
+        public OrderRequestRepository(HRDataContext context) : base(context)
+        {
+            dbSet = context.Set<OrderRequest>();
+
+        }
+        public async Task<OrderRequest> GetByIdWithAllChildren(long id)
+        {
+            return await dbSet
+                .Include(x => x.OrderType)
+                .FirstOrDefaultAsync(x => x.Id == id);
+        }
+    }
+}

+ 19 - 0
MTWorkHR.Infrastructure/Repositories/User/OrderTypeRepository.cs

@@ -0,0 +1,19 @@
+using Microsoft.EntityFrameworkCore;
+using MTWorkHR.Core.Entities;
+using MTWorkHR.Core.IDto;
+using MTWorkHR.Core.IRepositories;
+using MTWorkHR.Infrastructure.Entities;
+using MTWorkHR.Infrastructure.DBContext;
+
+namespace MTWorkHR.Infrastructure.Repositories
+{
+    public class OrderTypeRepository : Repository<OrderType>, IOrderTypeRepository
+    {
+        private readonly DbSet<OrderType> dbSet;
+        public OrderTypeRepository(HRDataContext context) : base(context)
+        {
+            dbSet = context.Set<OrderType>();
+        }
+        
+    }
+}

+ 14 - 1
MTWorkHR.Infrastructure/UnitOfWork/UnitOfWork.cs

@@ -24,6 +24,10 @@ namespace MTWorkHR.Infrastructure.UnitOfWorks
         public ITeamRepository Team{ get; }
         public IMeetingRepository Meeting{ get; }
         public IAttendanceRepository Attendance { get; }
+        public IOrderTypeRepository OrderType { get; }
+        public ILeaveTypeRepository LeaveType { get; }
+        public IOrderAllocationRepository OrderAllocation { get; }
+        public IOrderRequestRepository OrderRequest { get; }
 
         public UnitOfWork(HRDataContext _context
             , IPermissionRepository permission
@@ -36,6 +40,11 @@ namespace MTWorkHR.Infrastructure.UnitOfWorks
             , ITeamRepository teamRepository
             , IMeetingRepository meetingRepository
             , IAttendanceRepository attendance
+            , IOrderRequestRepository orderRequest
+            , IOrderAllocationRepository orderAllocation
+            , IOrderTypeRepository orderType
+            , ILeaveTypeRepository leaveType
+
             )
         {
             context = _context;
@@ -48,7 +57,11 @@ namespace MTWorkHR.Infrastructure.UnitOfWorks
             this.UserTaskAttachment = userTaskAttachment;
             this.Team = teamRepository;
             this.Meeting = meetingRepository;
-            Attendance = attendance;
+            this.Attendance = attendance;
+            this.OrderType = orderType;
+            this.OrderRequest = orderRequest;
+            this.OrderAllocation = orderAllocation;
+            this.LeaveType = leaveType;
         }
 
         public async Task<int> CompleteAsync()