Created
September 6, 2021 13:55
-
-
Save AlBannaTechno/f37a249ba36a1aa88b72bc615cda6df5 to your computer and use it in GitHub Desktop.
eXtra_Mapping
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public async Task<GetAddressDetailMappingResponse> GetMappingDetails(GetAddressMappingData data) | |
{ | |
#region Predefined | |
var ksaCountry = new AddressDetailMappingViewModel() | |
{ | |
DetailId = Guid.Parse("33B45801-854A-42F8-B842-2D1BF42802FB"), | |
DetailMasterCodeid = Constants.MasterCodesID.COUNTRY, | |
DetailName = "Saudi Arabia", | |
DetailNameAR = "المملكة العربية السعودية" | |
}; | |
#endregion | |
#region Check For Area City Combination Existence In Siebel To Google Mapping Table | |
var mappedCityWithArea = await _siebelGoogleMappingRepository.Get(null) | |
.FirstOrDefaultAsync(d => | |
(d.CityGoogleAr.ToLower() == data.AreaName.ToLower() || | |
d.CityGoogleEn.ToLower() == data.CityName.ToLower()) | |
&& | |
(d.AreaGoogleAr.ToLower() == data.AreaName.ToLower() || | |
d.AreaGoogleEn.ToLower() == data.AreaName.ToLower()) | |
); | |
#endregion | |
#region City/Area Compination Not Existed | |
if (mappedCityWithArea == null) | |
{ | |
#region Log Record | |
_siebelGoogleMappingMissingLogsService.CreateMissedMapping(new CreateSiebelGoogleMappingMissingLogDto | |
{ | |
Country = data.CountryName ?? ksaCountry.DetailName, | |
City = data.CityName, | |
Area = null, | |
CountryDetailId = ksaCountry.DetailId, | |
}); | |
#endregion | |
#region Return First Matched City In The Mapping Table | |
var city = await _siebelGoogleMappingRepository.Get(null).FirstOrDefaultAsync(d => | |
d.CityGoogleAr.ToLower() == data.CityName.ToLower() || | |
d.CityGoogleEn.ToLower() == data.CityName.ToLower()); | |
return new GetAddressDetailMappingResponse | |
{ | |
Country = ksaCountry, | |
City = city == null | |
? null | |
: new AddressDetailMappingViewModel | |
{ | |
DetailMasterCodeid = Constants.MasterCodesID.CITY, | |
DetailId = city.CityId, | |
DetailNameAR = city.CityAr, | |
DetailName = city.CityEn, | |
MappedNameAR = city.CityGoogleAr, | |
MappedNameEN = city.CityGoogleEn, | |
NameToSearch = city.CityGoogleEn.ToLower(), | |
Covered = true | |
} | |
}; | |
#endregion | |
} | |
#endregion | |
#region City/Area Compinate Exit | |
else | |
{ | |
#region If area name not exist, return all areas related to this city | |
if (string.IsNullOrWhiteSpace(data.AreaName)) | |
{ | |
var areas = await _siebelGoogleMappingRepository.Get(null) | |
.Where(mp => mp.CityId == mappedCityWithArea.CityId) | |
.ToListAsync(); | |
#region Log If No Result | |
if (areas.Count == 0) | |
{ | |
_siebelGoogleMappingMissingLogsService.CreateMissedMapping(new CreateSiebelGoogleMappingMissingLogDto | |
{ | |
Country = data.CountryName, | |
City = data.CityName, | |
Area = data.AreaName, | |
CountryDetailId = ksaCountry.DetailId, | |
}); | |
} | |
#endregion | |
return new GetAddressDetailMappingResponse | |
{ | |
Country = ksaCountry, | |
City = new AddressDetailMappingViewModel | |
{ | |
DetailMasterCodeid = Constants.MasterCodesID.CITY, | |
DetailId = mappedCityWithArea.CityId, | |
DetailNameAR = mappedCityWithArea.CityAr, | |
DetailName = mappedCityWithArea.CityEn, | |
MappedNameAR = mappedCityWithArea.CityGoogleAr, | |
MappedNameEN = mappedCityWithArea.CityGoogleEn, | |
NameToSearch = mappedCityWithArea.CityGoogleEn.ToLower(), | |
Covered = true | |
}, | |
Areas = areas.Select(mp => new AddressDetailMappingViewModel | |
{ | |
DetailMasterCodeid = Constants.MasterCodesID.AREA, | |
DetailId = mp.AreaId, | |
DetailNameAR = mp.AreaAr, | |
DetailName = mp.AreaEn, | |
MappedNameAR = mp.AreaGoogleAr, | |
MappedNameEN = mp.AreaGoogleEn, | |
Covered = true | |
}).ToList() | |
}; | |
} | |
#endregion | |
#region If area name exist, filter with. | |
else | |
{ | |
var mappedCitiesWithAreas = await _siebelGoogleMappingRepository.Get(null) | |
.Where(d => | |
(d.CityGoogleAr.ToLower() == data.AreaName.ToLower() || | |
d.CityGoogleEn.ToLower() == data.CityName.ToLower()) | |
&& | |
(d.AreaGoogleAr.ToLower() == data.AreaName.ToLower() || | |
d.AreaGoogleEn.ToLower() == data.AreaName.ToLower()) | |
).ToListAsync(); | |
#region Log If No Result | |
if (mappedCitiesWithAreas.Count == 0) | |
{ | |
_siebelGoogleMappingMissingLogsService.CreateMissedMapping(new CreateSiebelGoogleMappingMissingLogDto | |
{ | |
Country = data.CountryName, | |
City = data.CityName, | |
Area = data.AreaName, | |
CountryDetailId = ksaCountry.DetailId, | |
}); | |
} | |
#endregion | |
return new GetAddressDetailMappingResponse | |
{ | |
Country = ksaCountry, | |
City = new AddressDetailMappingViewModel | |
{ | |
DetailMasterCodeid = Constants.MasterCodesID.CITY, | |
DetailId = mappedCityWithArea.CityId, | |
DetailNameAR = mappedCityWithArea.CityAr, | |
DetailName = mappedCityWithArea.CityEn, | |
MappedNameAR = mappedCityWithArea.CityGoogleAr, | |
MappedNameEN = mappedCityWithArea.CityGoogleEn, | |
NameToSearch = mappedCityWithArea.CityGoogleEn.ToLower(), | |
Covered = true | |
}, | |
Areas = mappedCitiesWithAreas.Select(mp => new AddressDetailMappingViewModel | |
{ | |
DetailMasterCodeid = Constants.MasterCodesID.AREA, | |
DetailId = mp.AreaId, | |
DetailNameAR = mp.AreaAr, | |
DetailName = mp.AreaEn, | |
MappedNameAR = mp.AreaGoogleAr, | |
MappedNameEN = mp.AreaGoogleEn, | |
Covered = true | |
}).ToList() | |
}; | |
} | |
#endregion | |
} | |
#endregion | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
public async Task GetMappingDetails(GetAddressMappingData data)
{
var result = new GetAddressDetailMappingResponse()
{
Country = new AddressDetailMappingViewModel()
{
DetailId = Guid.Parse("33B45801-854A-42F8-B842-2D1BF42802FB"),
DetailMasterCodeid = Constants.MasterCodesID.COUNTRY,
DetailName = "Saudi Arabia",
DetailNameAR = "المملكة العربية السعودية"
}
};
if (string.IsNullOrEmpty(data.CityName))
{
return result;
}