// GET: Posts/Show/5 public async Task <ActionResult> GetTag([FromRoute] int id) { var tag = await _tagsService.FindAsync(id); if (tag == null) { return(NotFound()); } return(Ok(_mapper.Map <TagResponse>(tag))); }
private async Task <List <RecipeTag> > CreateRecipeTags(Recipe recipe, IList <Tag> tags) { var existingTags = recipe.Tags .Where(rt => tags.Select(t => t.Name.ToLower()).Contains(rt.Tag.Name.ToLower())); var newTags = tags .Where(rt => !existingTags.Select(t => t.Tag.Name.ToLower()).Contains(rt.Name.ToLower())); var recipeTags = new List <RecipeTag>(existingTags); foreach (var tag in newTags) { var newTag = await tagsService.FindAsync(tag.Name) ?? tag; recipeTags.Add(RecipeTag.Create(newTag, recipe.RecipeId)); } return(recipeTags); }