private List <CourtDistrict> SetParentIdToDistricts(Dictionary <string, CourtRegion> regionsSaved, IEnumerable <IChangeableData> regionsRaw) { List <CourtDistrict> districtsWithParentId = new List <CourtDistrict>(); foreach (var itemRaw in regionsRaw) { CourtRegion region = null; if (itemRaw.Childs != null && regionsSaved.TryGetValue(itemRaw.Name, out region)) { var districtsRaw = itemRaw.Childs.Select(x => { CourtDistrict district = (CourtDistrict)x; district.RegionId = region.Id; return(district); }); districtsWithParentId.AddRange(districtsRaw); } } return(districtsWithParentId); }
private List <CourtLocation> SetParentIdToLocations(Dictionary <string, CourtDistrict> districtsSaved, IEnumerable <IChangeableData> districtsRaw) { List <CourtLocation> locationsToSave = new List <CourtLocation>(); foreach (var itemRaw in districtsRaw) { CourtDistrict district = null; if (itemRaw.Childs != null && districtsSaved.TryGetValue(itemRaw.Name, out district)) { var locations = itemRaw.Childs.Select(x => { CourtLocation location = (CourtLocation)x; location.DistrictId = district.Id; return(location); }); locationsToSave.AddRange(locations); } } return(locationsToSave); }