protected void UpdateRegions(SaveExOzRegionCommand command) { List <string> apiRegionNames = command.RegionList.Select(w => w.Name).Distinct().ToList(); var FilCities = _cityRepository.GetByNames(apiRegionNames); var exOzRegions = _exOzRegionRepository.GetByNames(apiRegionNames); foreach (var item in command.RegionList) { ExOzRegion existingExOzRegion = exOzRegions.Where(w => w.RegionId == item.Id).FirstOrDefault(); City existingFilCity = FilCities.Where(w => w.Name == item.Name).FirstOrDefault(); ExOzState exOzState = _exOzStateRepository.GetByUrlSegment(item.StateUrlSegment); State FilState = _stateRepository.GetByName(exOzState.Name); City FilCityInserted = new City(); if (existingFilCity == null) { var newFilCity = new City { Name = item.Name, StateId = FilState.Id, IsEnabled = true, }; FilCityInserted = _cityRepository.Save(newFilCity); } else { FilCityInserted = existingFilCity; } if (existingExOzRegion == null) { var newExOzRegion = new ExOzRegion { RegionId = item.Id, Name = item.Name, UrlSegment = item.UrlSegment, StateId = exOzState.Id, CityId = FilCityInserted.Id, IsEnabled = true, Offset = item.Offset, TimeStamp = item.Timestamp, OperatorCount = item.Operators.Count, CategoryCount = item.Categories.Count, }; ExOzRegion exOzRegionInserted = _exOzRegionRepository.Save(newExOzRegion); } else { existingExOzRegion.IsEnabled = true; ExOzRegion exOzRegionInserted = _exOzRegionRepository.Save(existingExOzRegion); } } }
public ExOzState GetDetail(string urlSegment) { return(_exOzStateRepository.GetByUrlSegment(urlSegment)); }