public async Task <ActionResult <Location> > Get([FromQuery] string query) { if (string.IsNullOrEmpty(query)) { return(null); } var location = this.locationsService.GetLocation(query); if (location == null) { location = await httpService.GetLocation(query); locationsService.AddLocation(location); } return(location); }
/* This method was written by Bob van Beek (610685) */ /// <summary> /// Asynchronous method which patches a Location record for current Delivery in the context. /// </summary> /// <param name="delivery"></param> /// <param name="location"></param> /// <returns></returns> public async Task <Delivery> PatchDeliveryLocation(Delivery delivery, Location location) { try { _logger.Information($"A request has been made to patch the location of Delivery {delivery.Id} in the context."); bool exists = await _locationsService.DoesLocationExist(location.Latitude, location.Longitude, location.IsWarehouse); if (!exists) { await _locationsService.AddLocation(location.Id, location.Latitude, location.Longitude, location.Address, location.PostalCode, location.Place, location.IsWarehouse); } delivery.CurrentId = location.Id; delivery = await UpdateDelivery(delivery); return(delivery ?? throw new ArgumentNullException("Dependency failure: Delivery is null.")); } catch (Exception e) // Error handling { _logger.Error($"IDeliveriesService says: {e.Message} Exception occured on line {new StackTrace(e, true).GetFrame(0).GetFileLineNumber()}."); return(null); } }
public async Task <IActionResult> AddLocation(LocationToAddDto location) { return(Ok(await _locationsService.AddLocation(location))); }