/// <summary> /// Asynchronous method that updates a Notifications records status and returned whether it succeeded or not /// </summary> /// <param name="id"></param> /// <param name="accepted"></param> /// <returns>true of false</returns> public async Task <bool> UpdateNotificationStatusById(Guid id, bool accepted) { try { _logger.Information($"A request has been made to update the status of Notification with id {id} in the context."); Notification n = await _notificationsRepo.UpdateNotificationStatusById(id, accepted); if (n != null && !accepted) { Delivery d = await _deliveriesService.GetDelivery(n.DeliveryId); bool result = await CreateNotification(d.Id, d.Vehicle, d.DueDate, new LatLng(d.Warehouse.Latitude, d.Warehouse.Longitude), new LatLng(d.Customer.Latitude, d.Customer.Longitude)); return(result ? result : throw new Exception($"Dependency failure: Could not create a new Notification record for Delivery {d.Id} in the context."));; } return(n != null ? true : throw new Exception($"Dependency failure: The repository returned null.")); } catch (Exception e) // Error handling { _logger.Error($"INotificationsService says: {e.Message} Exception occured on line " + $"{new StackTrace(e, true).GetFrame(0).GetFileLineNumber()}."); return(false); } }
public async Task <HttpResponseMessage> GetDelivery( [HttpTrigger(AuthorizationLevel.Function, "get", Route = "Deliveries/{id}")] HttpRequest req, string id) { string token = req.Headers["Authorization"].ToString().Replace("Bearer ", ""); if (_authorizationsService.IsTokenValid(token, true)) { Delivery d = await _deliveriesService.GetDelivery(Guid.Parse(id)); return(d != null ? new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent(JsonConvert.SerializeObject(d, new JsonSerializerSettings() { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }), Encoding.UTF8, "application/json") } : new HttpResponseMessage(HttpStatusCode.NoContent)); } // Authorized access only return(new HttpResponseMessage(HttpStatusCode.Unauthorized)); }