private async Task CheckListNames(SocialMediaListsDetails currentDetails, SocialMediaListsDetails updatedDetails) { var tasks = new List <Task>(); foreach (var updatedListDetails in updatedDetails.Lists) { var listDetails = currentDetails.Lists.Find(l => l.Id == updatedListDetails.Id); // If it doesn't exist in old details, create new list doc if (listDetails == null) { var newList = _mapper.Map <SocialList>(updatedListDetails); newList.MediaPosts = new List <MediaPost>(); tasks.Add(_repo.CreateAsync(newList)); } else if (listDetails.Name != updatedListDetails.Name) { // Update list doc with name change var list = _repo.Get(listDetails.Id); list.Name = updatedListDetails.Name; tasks.Add(_repo.UpdateAsync(list.Id, list)); } } await Task.WhenAll(tasks); }