/// <summary> /// Asynchronous method that updates all the expired records in the Notifications context. /// </summary> /// <returns>true or false</returns> public async Task <bool> UpdateExpiredNotifications() { try { _logger.Information($"A request has been made to update the expired Notification records in the context."); List <Notification> expired = await _notificationsRepo.GetAllExpiredNotifications(); bool result = _notificationsRepo.UpdateExpiredNotifications(expired); // Check if notifications were updated to expired. If so, create new Notification record if (result) { bool success; foreach (Notification n in expired) { Delivery d = await _deliveriesService.GetDelivery(n.DeliveryId); success = await CreateNotification(d.Id, d.Vehicle, d.DueDate, new LatLng(d.Warehouse.Latitude, d.Warehouse.Longitude), new LatLng(d.Customer.Latitude, d.Customer.Longitude)); if (!success) { throw new Exception($"Dependency failure: Could not create a new Notification record for Delivery {d.Id} in the context."); } } return(result); } else { throw new Exception($"Dependency failure: The repository returned false."); } } catch (Exception e) // Error handling { _logger.Error($"INotificationsRepository says: {e.Message} Exception occured on line " + $"{new StackTrace(e, true).GetFrame(0).GetFileLineNumber()}."); return(false); } }