public List <NotificationDetails> GetNotificationsForUser(int userId) { List <DatabaseNotification> dbNotifications = _databaseQueryService.GetNotificationsForUser(userId); List <NotificationDetails> notifications = new List <NotificationDetails>(); List <int> alertIds = new List <int>(); foreach (DatabaseNotification dbNotification in dbNotifications) { notifications.Add(new NotificationDetails(dbNotification)); alertIds.Add(dbNotification.AlertId); } List <DatabaseAlert> dbAlerts = _databaseQueryService.GetAlertsById(alertIds); foreach (DatabaseAlert alert in dbAlerts) { notifications.FindAll(notification => notification.AlertId == alert.AlertId).ForEach(notification => notification.Alert = new AlertDetails(alert)); } return(notifications); }