コード例 #1
0
        public async Task <ResultModel <bool> > ReportUserAsync(CreateUserReportRequestModel model, string reporterId)
        {
            var isBanned = await this.usersService.IsBanned(reporterId);

            if (isBanned)
            {
                return(new ResultModel <bool>
                {
                    Errors = { StoryReportErrors.BannedUserReports }
                });
            }

            var userReport = new UserReport
            {
                Title      = model.Title,
                Content    = model.Content,
                IsRead     = false,
                ReportedId = model.ReportedId,
                ReporterId = reporterId,
            };

            await this.dbContext.UserReports.AddAsync(userReport);

            await this.dbContext.SaveChangesAsync();

            return(new ResultModel <bool>
            {
                Result = true,
                Success = true,
            });
        }
コード例 #2
0
        public async Task <ActionResult> Create(CreateUserReportRequestModel model)
        {
            var loggedUser = this.User.GetId();
            var result     = await this.userReportsService.ReportUserAsync(model, loggedUser);

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

            return(Created(nameof(Create), result.Result));
        }