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> GetAllLeaveType() { var result = await _unitOfWork.LeaveType.GetAllAsync(); var list = MapperObject.Mapper.Map>(result.Item1); return list; } public async Task> GetAllOrderType() { var entity = await _unitOfWork.OrderType.GetAllAsync(); var response = MapperObject.Mapper.Map>(entity.Item1); return response; } public async Task> GetAllCountries() { var entity = await _unitOfWork.CountryLookup.GetAllAsync(); var response = MapperObject.Mapper.Map>(entity.Item1); return response; } public async Task> GetCityByCountry(long CountryId) { // List city = new List { new CityDto { NameEn = "Riyadh", NameAr = "الرياض", CountryId=1, Id = 1 }, new CityDto { NameEn = "Giddah", CountryId = 1, NameAr = "جده", Id = 2 }}; var cityList = await _unitOfWork.City.GetAllAsync(); var filterList = cityList.Item1.Where(c=> c.CountryId == CountryId); var response = MapperObject.Mapper.Map>(filterList); return response; } public async Task> GetAllIndustries() { var entity = await _unitOfWork.Industry.GetAllAsync(); var response = MapperObject.Mapper.Map>(entity.Item1); return response; } public async Task> GetAllJobTitles() { var entity = await _unitOfWork.JobTitle.GetAllAsync(); var response = MapperObject.Mapper.Map>(entity.Item1); return response; } public async Task> GetAllQualifications() { var entity = await _unitOfWork.Qualification.GetAllAsync(); var response = MapperObject.Mapper.Map>(entity.Item1); return response; } public async Task> GetAllUniversities() { var entity = await _unitOfWork.University.GetAllAsync(); var response = MapperObject.Mapper.Map>(entity.Item1); return response; } public async Task> GetAllUserTaskStatus() { var entity = await _unitOfWork.UserTaskStatus.GetAllAsync(); var response = MapperObject.Mapper.Map>(entity.Item1); return response; } public async Task> 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>(countries); return response; } } }