/// <summary> /// Updates the system's location with the given updated location. /// </summary> /// <param name="updatedLocation">The updated location.</param> public async Task UpdateAsync(UpdatedLocation updatedLocation) { var locationToUpdated = await Context.Locations.FindAsync(updatedLocation.LocationId); throwIfLocationNotFound(locationToUpdated.LocationId, locationToUpdated, "Location"); Location city = null; Location country = null; Location division = null; Location region = null; if (updatedLocation.CityId.HasValue) { city = await CreateGetLocationByIdQuery(updatedLocation.CityId).FirstOrDefaultAsync(); throwIfLocationNotFound(updatedLocation.CityId.Value, city, "City"); } if (updatedLocation.DivisionId.HasValue) { division = await CreateGetLocationByIdQuery(updatedLocation.DivisionId).FirstOrDefaultAsync(); throwIfLocationNotFound(updatedLocation.DivisionId.Value, division, "Division"); } if (updatedLocation.CountryId.HasValue) { country = await CreateGetLocationByIdQuery(updatedLocation.CountryId).FirstOrDefaultAsync(); throwIfLocationNotFound(updatedLocation.CountryId.Value, country, "Country"); } if (updatedLocation.RegionId.HasValue) { region = await CreateGetLocationByIdQuery(updatedLocation.RegionId).FirstOrDefaultAsync(); throwIfLocationNotFound(updatedLocation.RegionId.Value, region, "Region"); } var existingLocations = CreateGetLikeLocationsQuery(updatedLocation).Where(x => x.LocationId != updatedLocation.LocationId).ToList(); throwIfLocationsAlreadyExist(updatedLocation, existingLocations); var locationType = await Context.LocationTypes.FindAsync(updatedLocation.LocationTypeId); throwIfLocationTypeDoesNotExist(updatedLocation.LocationTypeId, locationType); DoUpdate(updatedLocation, locationToUpdated, region, country, division, city, locationType); }
private void DoUpdate( UpdatedLocation updatedLocation, Location locationToUpdate, Location region, Location country, Location division, Location city, LocationType locationType) { var validationEntity = GetLocationValidationEntity( region: region, location: updatedLocation, country: country, division: division, city: city ); locationValidator.ValidateUpdate(validationEntity); if (division == null && city != null && city.Division != null) { division = city.Division; } if (country == null && division != null && division.Country != null) { country = division.Country; } if (region == null && country != null && country.Region != null) { region = country.Region; } locationToUpdate.City = city; locationToUpdate.Country = country; locationToUpdate.Division = division; locationToUpdate.Region = region; locationToUpdate.Latitude = updatedLocation.Latitude; locationToUpdate.Longitude = updatedLocation.Longitude; locationToUpdate.LocationName = updatedLocation.LocationName; locationToUpdate.LocationType = locationType; updatedLocation.Audit.SetHistory(locationToUpdate); }
/// <summary> /// /// </summary> /// <param name="updatedLocation"></param> /// <returns></returns> public Task UpdateAsync(UpdatedLocation updatedLocation) { Contract.Requires(updatedLocation != null, "The updated location must not be null."); return(Task.FromResult <object>(null)); }
/// <summary> /// /// </summary> /// <param name="updatedLocation"></param> public void Update(UpdatedLocation updatedLocation) { Contract.Requires(updatedLocation != null, "The updated location must not be null."); }