Beispiel #1
0
        public async Task <int> Post([FromBody] CreateAdvertDto advertDto)
        {
            var userId = User.GetUserId();

            advertDto.UserId = userId;

            return(await _advertService.AddAsync(advertDto));
        }
Beispiel #2
0
        public async Task <IActionResult> Create(CreateAdvertDto advert)
        {
            ViewBag.ReCaptchaKey = GetCaptchaKey();

            if (ModelState.IsValid)
            {
                if (!ReCaptchaPassed(
                        Request.Form["g-recaptcha-response"], // that's how you get it from the Request object
                        _configuration.GetSection("GoogleReCaptcha:secret").Value
                        ))
                {
                    ModelState.AddModelError(string.Empty, "You failed the CAPTCHA, stupid robot. Go play some 1x1 on SFs instead.");
                    return(View(advert));
                }
                RemoveEmptyImages(advert);
                int createdAdvertId = await _advertService.AddAsync(advert);

                return(RedirectToAction("Get", new { id = createdAdvertId }));
            }

            return(View(advert));
        }