12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- 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;
- using MTWorkHR.Core.Entities.Base;
- 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;
- }
- public async Task<List<CountryDto>> GetAllCountries()
- {
- var entity = await _unitOfWork.CountryLookup.GetAllAsync();
- var response = MapperObject.Mapper.Map<List<CountryDto>>(entity.Item1);
- return response;
- }
- public async Task<List<IndustryDto>> GetAllIndustries()
- {
- var entity = await _unitOfWork.Industry.GetAllAsync();
- var response = MapperObject.Mapper.Map<List<IndustryDto>>(entity.Item1);
- return response;
- }
- public async Task<List<JobTitleDto>> GetAllJobTitles()
- {
- var entity = await _unitOfWork.JobTitle.GetAllAsync();
- var response = MapperObject.Mapper.Map<List<JobTitleDto>>(entity.Item1);
- return response;
- }
- public async Task<List<CountryDto>> CreateCountries()
- {
- // init the service
- var service = new Countries.NET.CountriesService();
- // to get the list of all countries:
- var countriesEnglish = service.GetAsKeyValue();
- var countriesArabic = service.GetAsKeyValue("ara", true);
- var countries = countriesArabic.Select(x => new CountryLookup { Code = x.Key, NameAr = x.Value }).ToList();
- foreach(var c in countries)
- {
- var countryEng = countriesEnglish.FirstOrDefault(cc => cc.Key == c.Code);
- c.NameEn = countryEng.Value;
- }
- await _unitOfWork.CountryLookup.AddRangeAsync(countries);
- await _unitOfWork.CompleteAsync();
- var response = MapperObject.Mapper.Map<List<CountryDto>>(countries);
- return response;
- }
- }
- }
|