internal List <LocationRef> CreateLocationRef(IEnumerable <ApprenticeshipLocation> locations) { List <LocationRef> locationRefs = new List <LocationRef>(); var subRegionItemModels = new SelectRegionModel().RegionItems.SelectMany(x => x.SubRegion); foreach (var location in locations) { if (location.Regions != null) { foreach (var region in location.Regions) { locationRefs.Add(new LocationRef { ID = subRegionItemModels.Where(x => x.Id == region).Select(y => y.ApiLocationId.Value).FirstOrDefault(), DeliveryModes = ConvertToApprenticeshipDeliveryModes(location.DeliveryModes), Radius = 10 }); } } else { locationRefs.Add(new LocationRef { ID = location.TribalId ?? location.LocationId, DeliveryModes = ConvertToApprenticeshipDeliveryModes(location.DeliveryModes), Radius = location.Radius.HasValue ? location.Radius.Value : 0 }); } } return(locationRefs); }
private List <DasLocationRef> CreateLocationRef(int exportKey, Dictionary <string, ApprenticeshipLocation> locations) { var locationRefs = new List <DasLocationRef>(); var subRegionItemModels = new SelectRegionModel().RegionItems.SelectMany(x => x.SubRegion); foreach (var(key, currentLocation) in locations) { // Regions if (currentLocation.SubRegionIds != null && currentLocation.SubRegionIds.Count > 0) { foreach (var region in currentLocation.SubRegionIds) { var locationId = subRegionItemModels .Where(x => x.Id == region) .Select(y => $"{y.ApiLocationId.Value}") .FirstOrDefault(); if (string.IsNullOrWhiteSpace(locationId)) { continue; } var regionId = locationId.Substring(locationId.Length - 3, 3); var regionIndex = $"{exportKey}2{regionId}"; locationRefs.Add(new DasLocationRef { Id = int.Parse(regionIndex), DeliveryModes = ConvertToApprenticeshipDeliveryModes(currentLocation), Radius = currentLocation.Radius ?? 50 // TODO: Add to config }); } } else { var isNational = currentLocation.National != null && currentLocation.National.Value; var radius = isNational ? 500 // National : currentLocation.Radius ?? 30; locationRefs.Add(new DasLocationRef { Id = int.Parse(key), DeliveryModes = ConvertToApprenticeshipDeliveryModes(currentLocation), Radius = radius }); } } return(locationRefs); }