public async Task <IActionResult> OnGetAsync(int postId) { this.InputModel = await this.postsService .GetPostByIdAsync <PostEntityDetailsInputModel>(postId); return(this.Page()); }
public async Task <IActionResult> OnGetAsync(int postId) { this.Data = await this.postsService .GetPostByIdAsync <PostEntityDetailsInputModel>(postId); if (this.Data == null) { return(this.NotFound()); } return(this.Page()); }
public async Task <int> DeletePost(PostEntityDetailsInputModel inputModel) { var currentPost = this.postsRepository.All() .Where(p => p.Id == inputModel.Id).FirstOrDefault(); if (currentPost == null) { return(default(int)); } currentPost.IsDeleted = true; var comments = this.postsRepository.All() .Where(p => p.Id == currentPost.Id) .SelectMany(p => p.Comments); if (comments.Any()) { foreach (var comment in comments) { comment.IsDeleted = true; } } var replies = this.postsRepository.All() .Where(p => p.Id == currentPost.Id) .SelectMany(p => p.Comments.SelectMany(c => c.Replies)); if (replies.Any()) { foreach (var reply in replies) { reply.IsDeleted = true; } } var statusCode = await this.postsRepository.SaveChangesAsync(); return(statusCode); }
public async Task <int> EditPost(PostEntityDetailsInputModel inputModel) { var currentPost = this.postsRepository.All().Where(p => p.Id == inputModel.Id).FirstOrDefault(); if (currentPost == null) { return(default(int)); } if (currentPost.Title != inputModel.Title) { currentPost.Title = inputModel.Title; } if (currentPost.Description != inputModel.Description) { currentPost.Description = inputModel.Description; } var statusCode = await this.postsRepository.SaveChangesAsync(); return(statusCode); }