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

            advertDto.UserId = userId;

            return(await _advertService.AddAsync(advertDto));
        }
예제 #2
0
        public async Task <int> AddAsync(CreateAdvertDto dto)
        {
            var postResponse = await $"{_apiOptions.Url}/api/adverts"
                               .WithOAuthBearerToken(await GetAccessTokenAsync())
                               .PostJsonAsync(dto);

            return(await postResponse.Content.ReadAsAsync <int>());
        }
예제 #3
0
        public async Task <int> AddAsync(CreateAdvertDto dto)
        {
            Validate(dto);

            var advert = _mapper.Map <Advert>(dto);

            _unitOfWork.AdvertRepository.Create(advert);

            await _unitOfWork.SaveChangesAsync();

            return(advert.Id);
        }
예제 #4
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));
        }
예제 #5
0
 private static void RemoveEmptyImages(CreateAdvertDto advert)
 {
     advert.AdvertImages = advert.AdvertImages
                           .Where(image => !string.IsNullOrEmpty(image.Base64))
                           .ToArray();
 }