示例#1
0
        public async Task <ActionResult <CompleteAdDTO> > JudgeAd([FromBody] AdminApproveDTO adminApproveDTO)
        {
            string username        = adminApproveDTO.AdminUsername;
            string authTokenString = adminApproveDTO.AuthToken;

            Models.Account adminClaimant = await _adService.GetUser(username, authTokenString);

            if (adminClaimant == null)
            {
                return(StatusCode(StatusCodes.Status401Unauthorized));
            }
            if (!adminClaimant.IsAdmin)
            {
                return(StatusCode(StatusCodes.Status401Unauthorized));
            }
            Ad adToFind = await _adService.GetAdAsAdmin(adminClaimant, adminApproveDTO.AdId);

            if (adToFind == null)
            {
                return(StatusCode(StatusCodes.Status401Unauthorized));
            }
            if (adminApproveDTO.AdDecision == "approve")
            {
                adToFind.AdminApprovalState = AdminApprovalState.Approved;
            }
            else if (adminApproveDTO.AdDecision == "reject")
            {
                adToFind.AdminApprovalState = AdminApprovalState.Rejected;
            }
            else
            {
                return(StatusCode(StatusCodes.Status400BadRequest));
            }
            await _smallPostersContext.SaveChangesAsync();

            return(StatusCode(StatusCodes.Status200OK));
        }