Exemplo n.º 1
0
        public async Task <int> DeleteComment(CommentEntityInputModel inputModel)
        {
            var currentComment = this.commentsRepository.All()
                                 .Where(c => c.Id == inputModel.Id && c.IsDeleted == false)
                                 .FirstOrDefault();

            if (currentComment == null)
            {
                return(default(int));
            }

            currentComment.IsDeleted = true;

            var replies = this.commentsRepository.All()
                          .Where(c => c.Id == currentComment.Id && c.IsDeleted == false)
                          .SelectMany(p => p.Replies);

            if (replies.Any())
            {
                foreach (var reply in replies)
                {
                    reply.IsDeleted = true;
                }
            }

            var statusCode = await this.commentsRepository.SaveChangesAsync();

            return(statusCode);
        }
Exemplo n.º 2
0
        public async Task <IActionResult> OnGetAsync(int commentId)
        {
            this.Data = await this.commentsService
                        .GetCommentByIdAsync <CommentEntityInputModel>(commentId);

            if (this.Data == null)
            {
                return(this.NotFound());
            }

            return(this.Page());
        }
Exemplo n.º 3
0
        public async Task <int> EditComment(CommentEntityInputModel inputModel)
        {
            var currentComment = this.commentsRepository.All()
                                 .Where(c => c.Id == inputModel.Id)
                                 .FirstOrDefault();

            if (currentComment == null)
            {
                return(default(int));
            }

            if (currentComment.Description != inputModel.Description)
            {
                currentComment.Description = inputModel.Description;
            }

            var statusCode = await this.commentsRepository.SaveChangesAsync();

            return(statusCode);
        }