public async Task <BeerDto> AddAsync(BeerDto beerDto) { var beer = Mapper.Map <BeerDto, Beer>(beerDto); if (beerDto.Recipe != null) { BeerCalculations(beer); } beer.BeerStyle = null; beer.CreatedDate = DateTime.Now; beer.UpdatedDate = DateTime.Now; await _beerRepository.AddAsync(beer); var result = await _beerRepository.GetSingleAsync(beer.BeerId, _include); var mappedResult = Mapper.Map <Beer, BeerDto>(result); await _beerElasticsearch.UpdateAsync(mappedResult); // elasticsearch relation managing if (mappedResult.ForkOfId != null) { await ReIndexSingleElasticSearchAsync((int)mappedResult.ForkOfId); } if (mappedResult.Brewers.Any()) { await _userService.ReIndexBeerRelationElasticSearch(beerDto); } if (mappedResult.Breweries.Any()) { await _breweryService.ReIndexBeerRelationElasticSearch(beerDto); } return(mappedResult); }
public async Task <BeerDto> AddAsync(BeerDto beerDto) { var beer = AutoMapper.Mapper.Map <BeerDto, Beer>(beerDto); if (beerDto.Recipe != null && beerDto.Recipe.Steps != null) { BeerCalculations(beer); } await _beerRepository.AddAsync(beer); var result = await _beerRepository.GetSingleAsync(beer.BeerId); var mappedResult = AutoMapper.Mapper.Map <Beer, BeerDto>(result); await _beerElasticsearch.UpdateAsync(mappedResult); // elasticsearch relation managing if (mappedResult.ForkOfId != null) { await ReIndexSingleElasticSearchAsync((int)mappedResult.ForkOfId); } if (mappedResult.Brewers.Any()) { //await _userService.ReIndexBeerRelationElasticSearch(beerDto); if (mappedResult.Breweries.Any()) { await _breweryService.ReIndexBeerRelationElasticSearch(beerDto); } } return(mappedResult); }