The task is to determine the region by comparing three sources of information taking into account the coefficients of their importance.
//GetRegionIdByKeywordAsync returns region id by string name, if the region could not be determined, 0 will return
//The received identifiers can completely or partially coincide, or be absolutely different
int regionIdByIp = await GetRegionIdByKeywordAsync(regionByIpStr);
int regionIdByPhone = await GetRegionIdByKeywordAsync(regionByPhoneStr);
int regionIdByInput = await GetRegionIdByKeywordAsync(regionByInputStr);
var weights = new List<KeyValuePair<int, int>>
{
//Each source of information has its own importance coefficient, determined manually
new KeyValuePair<int, int>(regionIdByIp, 5),
new KeyValuePair<int, int>(regionIdByPhone, 3),
new KeyValuePair<int, int>(regionIdByInput, 4)
};
//The final decision is determined by the search for a region that has the highest score in the total
int regionId = weights.Where(x => x.Key != default(int)).GroupBy(kvp => kvp.Key).OrderByDescending(x => x.Sum(y => y.Value)).Select(x => x.Key).FirstOrDefault();
Do you see any improvement / issue?