protected void SavePostTags(Post post, params string[] rawPostTags) { #region AddNewTags var allTags = postTagService.GetAllTags().ToList(); var tagsToInsert = rawPostTags.Except(allTags.Select(s => s.Name)); foreach (var newTagName in tagsToInsert) { postTagService.Save(newTagName); } #endregion AddNewTags #region AddOrRemoveTags var oldTags = postTagService.GetTagsByPostId(post.Id).ToList(); var newTags = rawPostTags; var tagsToRemove = oldTags.Select(s => s.Name).Except(newTags); foreach (var tagName in tagsToRemove) { postTagService.Delete(post.Id, tagName); } var tagsToAdd = newTags.Except(oldTags.Select(s => s.Name)); foreach (var tagName in tagsToAdd) { postTagService.Save(post.Id, tagName); } #endregion AddOrRemoveTags }
public HttpResponseMessage Delete(HttpRequestMessage request, int id) { return(CreateHttpRespone(request, () => { HttpResponseMessage respone = null; if (ModelState.IsValid) { request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState); } else { _TagService.Delete(id); _TagService.SaveChanges(); respone = request.CreateResponse(HttpStatusCode.OK); } return respone; })); }
public IActionResult DeletePostTag([FromBody] PostTag postTag) { _postTagService.Delete(postTag); return(new NoContentResult()); }