public async Task UpdatePost(NormalPostUpdateModel input) { var normalPost = this.postRepository.All().FirstOrDefault(x => x.Id == input.NormalPostId); if (normalPost.Caption != input.Caption) { normalPost.Caption = input.Caption; } var tags = await this.tagsService.GetTagsForPost(input.Tags); var postTags = this.postTagsRepository.All().Where(x => x.PostId == input.NormalPostId); foreach (var tag in postTags) { this.postTagsRepository.Delete(tag); } await this.postTagsRepository.SaveChangesAsync(); foreach (var tag in tags) { var postTag = new PostTag { PostId = normalPost.Id, TagId = tag.Id, }; normalPost.Tags.Add(postTag); } await this.postRepository.SaveChangesAsync(); }
public async Task <IActionResult> UpdatePost(NormalPostUpdateModel input) { if (!this.ModelState.IsValid) { input.TagsDropDown = this.tagsService.GetAllTagsAsKeyValuePair(); return(this.View(input)); } await this.postsService.UpdatePost(input); return(this.Redirect("/NormalPosts/NormalPostsNewest")); }