public void RunLocations() { var dataLocations = _locationRepository.RetreiveLocations(); var shopifyLocations = _productApi .RetrieveLocations() .DeserializeFromJson <LocationList>(); foreach (var shopifyLoc in shopifyLocations.locations) { var dataLocation = dataLocations.FindByShopifyId(shopifyLoc); using (var transaction = _locationRepository.BeginTransaction()) { if (dataLocation == null) { var newDataLocation = new ShopifyLocation { ShopifyLocationId = shopifyLoc.id, ShopifyLocationName = shopifyLoc.name, ShopifyActive = shopifyLoc.active, DateCreated = DateTime.UtcNow, LastUpdated = DateTime.UtcNow, }; _locationRepository.InsertLocation(newDataLocation); } else { dataLocation.LastUpdated = DateTime.UtcNow; dataLocation.ShopifyLocationName = shopifyLoc.name; dataLocation.ShopifyActive = shopifyLoc.active; } _locationRepository.SaveChanges(); _shopifyJsonService.Upsert(ShopifyJsonType.Location, shopifyLoc.id, shopifyLoc.SerializeToJson()); transaction.Commit(); } } }