public async Task <IActionResult> PostBeerStyle([FromBody] BeerStyleDto beerStylesDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var result = await _beerStyleService.AddAsync(beerStylesDto);

            return(CreatedAtRoute(new { controller = "beerstyles" }, result));
        }
        public async Task UpdateAsync(BeerStyleDto beerStyleDto)
        {
            var beerStyle = Mapper.Map <BeerStyleDto, BeerStyle>(beerStyleDto);
            await _beerStyleRepository.UpdateAsync(beerStyle);

            var result = await _beerStyleRepository.GetSingleAsync(beerStyleDto.Id, "SubStyles", "SuperStyle");

            var mappedResult = Mapper.Map <BeerStyle, BeerStyleDto>(result);
            await _beerStyleElasticsearch.UpdateAsync(mappedResult);
        }
        public async Task PostBeerStyleReturns201CreatedWithObject()
        {
            var beerStyle = new BeerStyleDto()
            {
                Name = "Lager"
            };
            var response = await _controller.PostBeerStyle(beerStyle) as CreatedAtRouteNegotiatedContentResult <BeerStyleCompleteDto>;

            Assert.IsInstanceOf <CreatedAtRouteNegotiatedContentResult <BeerStyleCompleteDto> >(response);
            Assert.True(response.Content.BeerStyles.Any());
        }
示例#4
0
        public async Task UpdateAsync(BeerStyleDto beerStyleDto)
        {
            var beerStyle = AutoMapper.Mapper.Map <BeerStyleDto, BeerStyle>(beerStyleDto);
            await _beerStyleRepository.UpdateAsync(beerStyle);

            var result = await _beerStyleRepository.GetSingleAsync(beerStyleDto.Id);

            var mappedResult = AutoMapper.Mapper.Map <BeerStyle, BeerStyleDto>(result);
            await _beerStyleElasticsearch.UpdateAsync(mappedResult);

            await IndexHopAsync(beerStyle);
        }
        public async Task <BeerStyleDto> AddAsync(BeerStyleDto otherDto)
        {
            var beerStyle = Mapper.Map <BeerStyleDto, BeerStyle>(otherDto);
            await _beerStyleRepository.AddAsync(beerStyle);

            var result = await _beerStyleRepository.GetSingleAsync(beerStyle.BeerStyleId, "SubStyles", "SuperStyle");

            var mappedResult = Mapper.Map <BeerStyle, BeerStyleDto>(result);
            await _beerStyleElasticsearch.UpdateAsync(mappedResult);

            return(mappedResult);
        }
        public async Task <IActionResult> PutBeerStyle(int id, [FromBody] BeerStyleDto beerstyle)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (id != beerstyle.Id)
            {
                return(BadRequest());
            }
            await _beerStyleService.UpdateAsync(beerstyle);

            return(new StatusCodeResult((int)HttpStatusCode.NoContent));
        }
示例#7
0
        public async Task <BeerStyleDto> AddAsync(BeerStyleDto beerStyleDto)
        {
            var beerStyle = AutoMapper.Mapper.Map <BeerStyleDto, BeerStyle>(beerStyleDto);
            await _beerStyleRepository.AddAsync(beerStyle);

            var result = await _beerStyleRepository.GetSingleAsync(beerStyle.BeerStyleId);

            var mappedResult = AutoMapper.Mapper.Map <BeerStyle, BeerStyleDto>(result);

            _logger.LogInformation(mappedResult.Name);
            await _beerStyleElasticsearch.UpdateAsync(mappedResult);

            await IndexHopAsync(beerStyle);

            return(mappedResult);
        }
        public async Task UpdateAsync(BeerStyleDto beerStyleDto)
        {
            await _client.MapAsync <BeerStyleDto>(d => d.Properties(p => p.String(s => s.Name(n => n.Name).Analyzer("autocomplete"))));

            var index = await _client.IndexAsync <BeerStyleDto>(beerStyleDto);
        }