public async Task <ActionResult> Create(SubCommentCreateRequestModel model) { var loggedUser = this.User.GetId(); var result = await this.subCommentsService.CreateAsync(model, loggedUser); if (!result.Success) { return(BadRequest(result.Errors)); } return(Created(nameof(Create), result.Result)); }
public async Task <ResultModel <string> > CreateAsync(SubCommentCreateRequestModel model, string userId) { if (model.RootCommentId == null || string.IsNullOrWhiteSpace(model.RootCommentId)) { return(new ResultModel <string> { Errors = { SubCommentErrors.NotFoundOrDeletedSubComment } }); } if (userId == null || string.IsNullOrWhiteSpace(userId)) { return(new ResultModel <string> { Errors = { UserErrors.InvalidUserId } }); } var isBanned = await this.usersService.IsBanned(userId); if (isBanned) { return(new ResultModel <string> { Errors = { CommentErrors.BannedUserCreateComment } }); } var subComment = new SubComment { Content = model.Content, UserId = userId, RootCommentId = model.RootCommentId }; await this.dbContext.AddAsync(subComment); await this.dbContext.SaveChangesAsync(); return(new ResultModel <string> { Result = subComment.Id, Success = true, }); }