LookupService.cs 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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<IndustryDto>> GetAllIndustries()
  47. {
  48. var entity = await _unitOfWork.Industry.GetAllAsync();
  49. var response = MapperObject.Mapper.Map<List<IndustryDto>>(entity.Item1);
  50. return response;
  51. }
  52. public async Task<List<JobTitleDto>> GetAllJobTitles()
  53. {
  54. var entity = await _unitOfWork.JobTitle.GetAllAsync();
  55. var response = MapperObject.Mapper.Map<List<JobTitleDto>>(entity.Item1);
  56. return response;
  57. }
  58. public async Task<List<CountryDto>> CreateCountries()
  59. {
  60. // init the service
  61. var service = new Countries.NET.CountriesService();
  62. // to get the list of all countries:
  63. var countriesEnglish = service.GetAsKeyValue();
  64. var countriesArabic = service.GetAsKeyValue("ara", true);
  65. var countries = countriesArabic.Select(x => new CountryLookup { Code = x.Key, NameAr = x.Value }).ToList();
  66. foreach(var c in countries)
  67. {
  68. var countryEng = countriesEnglish.FirstOrDefault(cc => cc.Key == c.Code);
  69. c.NameEn = countryEng.Value;
  70. }
  71. await _unitOfWork.CountryLookup.AddRangeAsync(countries);
  72. await _unitOfWork.CompleteAsync();
  73. var response = MapperObject.Mapper.Map<List<CountryDto>>(countries);
  74. return response;
  75. }
  76. }
  77. }