public async Task <List <NotificationDTO> > GetNotifications(string userid) { List <Repository.Models.Notification> repoNotifications = await _repo.GetNotifications(userid); if (repoNotifications == null) { return(null); } var userIdList = repoNotifications.Select(n => n.CreatorId).Where(u => u != null).ToList(); var users = await _repo.GetReportedUsers(userIdList); List <NotificationDTO> newNotifications = new List <NotificationDTO>(); List <Task <NotificationDTO> > tasks = new List <Task <NotificationDTO> >(); foreach (var repoN in repoNotifications) { tasks.Add(Task.Run(() => Mapper.RepoNotifToNotifDTO(repoN))); } var results = await Task.WhenAll(tasks); foreach (var item in results) { if (item.CreatorId != null) { item.CreatorUsername = users.Where(u => u.UserId == item.CreatorId).FirstOrDefault().Username; } newNotifications.Add(item); } return(newNotifications); }