public async Task <IActionResult> Get() { await _bannerepository.RemoveAllBannersAsync(); var name = await _bannerepository.CreateIndexAsync(); await _bannerepository.AddAsync(new Banner() { Id = Guid.NewGuid(), Html = "<div>Hello1</div>", Created = DateTime.UtcNow }); await _bannerepository.AddAsync(new Banner() { Id = Guid.NewGuid(), Html = "<div>Hello2</div>", Created = DateTime.UtcNow }); await _bannerepository.AddAsync(new Banner() { Id = Guid.NewGuid(), Html = "<div>Hello3</div>", Created = DateTime.UtcNow }); await _bannerepository.AddAsync(new Banner() { Id = Guid.NewGuid(), Html = "<div>Hello4</div>", Created = DateTime.UtcNow }); return(Ok("Banners removed and created.")); }
public async Task <IActionResult> PostAsync([FromBody] BannerCreateDto bannerCreateModel) { try { var doc = new HtmlDocument(); doc.LoadHtml(bannerCreateModel.Html); if (doc.ParseErrors.Any()) { return(BadRequest(doc.ParseErrors)); } var banner = new Banner { Html = bannerCreateModel.Html, Created = DateTime.UtcNow, Id = Guid.NewGuid() }; var resultBanner = await _bannerRepository.AddAsync(banner); _logger.LogInformation(_eventId, $"Succesfully created resource id: {resultBanner.Id}"); var bannerDto = _mapper.Map <Banner, BannerDto>(resultBanner); //Get url location from another source Request.HttpContext.Response.Headers.Add("Location", $"http://localhost:50211/api/v1/banners/{bannerDto.Id}"); return(Ok(bannerDto)); } catch (Exception e) { _logger.LogCritical(_eventId, e, $"ErrorCode: {_customerErrorCode}"); return(StatusCode(500, $"Error code: {_customerErrorCode}")); } }