public async Task <int> Post([FromBody] CreateAdvertDto advertDto) { var userId = User.GetUserId(); advertDto.UserId = userId; return(await _advertService.AddAsync(advertDto)); }
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>()); }
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); }
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)); }
private static void RemoveEmptyImages(CreateAdvertDto advert) { advert.AdvertImages = advert.AdvertImages .Where(image => !string.IsNullOrEmpty(image.Base64)) .ToArray(); }