public async Task <IActionResult> InitialCreate(CancellationToken ct) { IList <Country> countries = null; IList <Region> regions = null; IList <City> cities = null; try { countries = JsonConvert.DeserializeObject <IList <Country> >(Properties.Resources.Countries); regions = JsonConvert.DeserializeObject <IList <Region> >(Properties.Resources.Regions); cities = JsonConvert.DeserializeObject <IList <City> >(Properties.Resources.Cities); var test = cities.Where(x => x.Id == 1); } catch (Exception ex) { return(Internal(JsonConvert.SerializeObject(ex))); } try { var obj = new SetValuesObject() { Country = null, Region = null, City = null, UnitOfWork = new SetValuesObject.Status { Commited = new List <object>() } }; var storage = new { Countries = await CountryRepository.QueryAsync(x => x, UserContext, ct : ct), Regions = await RegionRepository.QueryAsync(x => x, UserContext, ct : ct), Cities = await CityRepository.QueryAsync(x => x, UserContext, ct : ct) }; if (storage.Countries.Count() != countries.Count) { if (storage.Countries.Count() > 0) { await CountryRepository.DeleteAllAsync(string.Join(",", storage.Countries.Select(x => x.Id.ToString())), UserContext, ct); } await CountryRepository.AddAllAsync(countries, UserContext, ct); obj.Country = new SetValuesObject.RepoObj { Added = true, Cleaned = storage.Countries.Count() > 0, Count = countries.Count }; await CommitStatus <Country>(obj, ct); } else { obj.Country = new SetValuesObject.RepoObj { Added = false }; } if (storage.Regions.Count() != regions.Count) { if (storage.Regions.Count() > 0) { await RegionRepository.DeleteAllAsync(string.Join(",", storage.Regions.Select(x => x.Id.ToString())), UserContext, ct); } await RegionRepository.AddAllAsync(regions, UserContext, ct); obj.Region = new SetValuesObject.RepoObj { Added = true, Cleaned = storage.Regions.Count() > 0, Count = regions.Count }; await CommitStatus <Region>(obj, ct); } else { obj.Region = new SetValuesObject.RepoObj { Added = false }; } if (storage.Cities.Count() != cities.Count) { if (storage.Cities.Count() > 0) { await CityRepository.DeleteAllAsync(string.Join(",", storage.Cities.Select(x => x.Id.ToString())), UserContext, ct); } var test = cities.Where(x => x.Id == 1).ToArray(); await CityRepository.AddAllAsync(cities, UserContext, ct); obj.Region = new SetValuesObject.RepoObj { Added = true, Cleaned = storage.Cities.Count() > 0, Count = cities.Count }; await CommitStatus <City>(obj, ct); } else { obj.Region = new SetValuesObject.RepoObj { Added = false }; } if (obj.UnitOfWork.Commited.Select(x => (bool)((dynamic)x).Ok).Where(x => x == false).Count() == 0) { return(CreatedAtAction(nameof(InitialCreate), JsonConvert.SerializeObject(obj))); } else { return(Internal(JsonConvert.SerializeObject(obj))); } } catch (Exception ex) { return(Internal(JsonConvert.SerializeObject(ex))); } }