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); }
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 <bool> UpdateNotification(string username, NotificationDto notificationDto) { if (notificationDto.Type == "BreweryMember") { var changed = await _userRepository.ConfirmBreweryMemberAsync(username, notificationDto); if (!changed) { return(false); } await ReIndexUserElasticSearch(username); var brewery = await _breweryRepository.GetSingleAsync(notificationDto.Id, _breweryInclude); if (brewery == null) { return(false); } var breweryDto = Mapper.Map <Brewery, BreweryDto>(brewery); await _breweryElasticsearch.UpdateAsync(breweryDto); return(true); } if (notificationDto.Type == "UserBeer") { var changed = await _userRepository.ConfirmUserBeerAsync(username, notificationDto); if (!changed) { return(false); } await ReIndexUserElasticSearch(username); var beer = await _beerRepository.GetSingleAsync(notificationDto.Id, _beerInclude); if (beer == null) { return(false); } var beerDto = Mapper.Map <Beer, BeerDto>(beer); await _beerElasticsearch.UpdateAsync(beerDto); return(true); } return(false); }