LookupService.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. using Microsoft.AspNetCore.Identity;
  2. using Microsoft.AspNetCore.WebUtilities;
  3. using Microsoft.EntityFrameworkCore;
  4. using Microsoft.Extensions.Configuration;
  5. using MTWorkHR.Application.Identity;
  6. using MTWorkHR.Application.Mapper;
  7. using MTWorkHR.Application.Models;
  8. using MTWorkHR.Core.Global;
  9. using MTWorkHR.Core.IRepositories;
  10. using MTWorkHR.Core.UnitOfWork;
  11. using MTWorkHR.Infrastructure.Entities;
  12. using MTWorkHR.Application.Services.Interfaces;
  13. using MTWorkHR.Core.Email;
  14. using MTWorkHR.Core.Entities;
  15. using MTWorkHR.Infrastructure.UnitOfWorks;
  16. using MTWorkHR.Core.IDto;
  17. using MTWorkHR.Infrastructure.Repositories;
  18. using MTWorkHR.Core.Entities.Base;
  19. namespace MTWorkHR.Application.Services
  20. {
  21. public class LookupService : ILookupService
  22. {
  23. private readonly IUnitOfWork _unitOfWork;
  24. public LookupService(IUnitOfWork unitOfWork)
  25. {
  26. _unitOfWork = unitOfWork;
  27. }
  28. public async Task<List<LeaveTypeDto>> GetAllLeaveType()
  29. {
  30. var result = await _unitOfWork.LeaveType.GetAllAsync();
  31. var list = MapperObject.Mapper.Map<List<LeaveTypeDto>>(result.Item1);
  32. return list;
  33. }
  34. public async Task<List<OrderTypeDto>> GetAllOrderType()
  35. {
  36. var entity = await _unitOfWork.OrderType.GetAllAsync();
  37. var response = MapperObject.Mapper.Map<List<OrderTypeDto>>(entity.Item1);
  38. return response;
  39. }
  40. public async Task<List<CountryDto>> GetAllCountries()
  41. {
  42. var entity = await _unitOfWork.CountryLookup.GetAllAsync();
  43. var response = MapperObject.Mapper.Map<List<CountryDto>>(entity.Item1);
  44. return response;
  45. }
  46. public async Task<List<CityDto>> GetCityByCountry(long CountryId)
  47. {
  48. // List<CityDto> city = new List<CityDto> { new CityDto { NameEn = "Riyadh", NameAr = "الرياض", CountryId=1, Id = 1 }, new CityDto { NameEn = "Giddah", CountryId = 1, NameAr = "جده", Id = 2 }};
  49. var cityList = await _unitOfWork.City.GetAllAsync();
  50. var filterList = cityList.Item1.Where(c=> c.CountryId == CountryId);
  51. var response = MapperObject.Mapper.Map<List<CityDto>>(filterList);
  52. return response;
  53. }
  54. public async Task<List<IndustryDto>> GetAllIndustries()
  55. {
  56. var entity = await _unitOfWork.Industry.GetAllAsync();
  57. var response = MapperObject.Mapper.Map<List<IndustryDto>>(entity.Item1);
  58. return response;
  59. }
  60. public async Task<List<JobTitleDto>> GetAllJobTitles()
  61. {
  62. var entity = await _unitOfWork.JobTitle.GetAllAsync();
  63. var response = MapperObject.Mapper.Map<List<JobTitleDto>>(entity.Item1);
  64. return response;
  65. }
  66. public async Task<List<QualificationDto>> GetAllQualifications()
  67. {
  68. var entity = await _unitOfWork.Qualification.GetAllAsync();
  69. var response = MapperObject.Mapper.Map<List<QualificationDto>>(entity.Item1);
  70. return response;
  71. }
  72. public async Task<List<UniversityDto>> GetAllUniversities()
  73. {
  74. var entity = await _unitOfWork.University.GetAllAsync();
  75. var response = MapperObject.Mapper.Map<List<UniversityDto>>(entity.Item1);
  76. return response;
  77. }
  78. public async Task<List<UserTaskStatusDto>> GetAllUserTaskStatus()
  79. {
  80. var entity = await _unitOfWork.UserTaskStatus.GetAllAsync();
  81. var response = MapperObject.Mapper.Map<List<UserTaskStatusDto>>(entity.Item1);
  82. return response;
  83. }
  84. public async Task<List<CountryDto>> CreateCountries()
  85. {
  86. // init the service
  87. var service = new Countries.NET.CountriesService();
  88. // to get the list of all countries:
  89. var countriesEnglish = service.GetAsKeyValue();
  90. var countriesArabic = service.GetAsKeyValue("ara", true);
  91. var countries = countriesArabic.Select(x => new CountryLookup { Code = x.Key, NameAr = x.Value }).ToList();
  92. foreach(var c in countries)
  93. {
  94. var countryEng = countriesEnglish.FirstOrDefault(cc => cc.Key == c.Code);
  95. c.NameEn = countryEng.Value;
  96. }
  97. await _unitOfWork.CountryLookup.AddRangeAsync(countries);
  98. await _unitOfWork.CompleteAsync();
  99. var response = MapperObject.Mapper.Map<List<CountryDto>>(countries);
  100. return response;
  101. }
  102. }
  103. }