public async Task <ResultModel <string> > UpdateAsync(UpdateSubCommentRequestModel model, string subCommentId, string userId)
        {
            var subComment = await this.dbContext
                             .SubComments
                             .Where(sc => sc.Id == subCommentId && !sc.IsDeleted)
                             .FirstOrDefaultAsync();

            if (subComment == null)
            {
                return(new ResultModel <string>
                {
                    Errors = { SubCommentErrors.NotFoundOrDeletedSubComment }
                });
            }
            if (userId != subComment.UserId)
            {
                return(new ResultModel <string>
                {
                    Errors = { UserErrors.UserHaveNoPermissionToUpdate }
                });
            }

            subComment.Content    = model.Content;
            subComment.ModifiedOn = DateTime.UtcNow;

            this.dbContext.Update(subComment);
            await this.dbContext.SaveChangesAsync();

            return(new ResultModel <string>
            {
                Result = subComment.Content,
                Success = true,
            });
        }
Пример #2
0
        public async Task <ActionResult> Update(UpdateSubCommentRequestModel model, string subCommentId)
        {
            var loggedUser = this.User.GetId();
            var result     = await this.subCommentsService.UpdateAsync(model, subCommentId, loggedUser);

            if (!result.Success)
            {
                return(BadRequest(result.Errors));
            }

            return(Ok(result.Result));
        }