public async Task <IActionResult> UpdateTags([FromRoute] Guid deckId, [Required][TagValidation][FromBody] string[] newTags) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var deck = await deckRepo.FindAsync(deckId); if (deck is null) { return(NotFound()); } var currentTags = deck.Tags.Select(tagDbo => tagDbo.Tag); if (currentTags.SequenceEqual(newTags)) { return(NoContent()); } var tagsToAddition = newTags.Except(currentTags); var tagsToDeletion = currentTags.Except(newTags); if (tagsToAddition.Any()) { if (!await deckRepo.AddTags(deckId, tagsToAddition.ToArray())) { throw new AggregateException(); } } if (tagsToDeletion.Any()) { if (!await deckRepo.RemoveTags(deckId, tagsToDeletion.ToArray())) { throw new AggregateException(); } } return(NoContent()); }