private async Task <ApprenticeshipFavouritesBasket> GetBasket(RemoveBasketCommand request) { if (request.BasketId.HasValue) { return(await _basketStore.GetAsync(request.BasketId.Value)); } return(null); }
private async Task<ApprenticeshipFavouritesBasket> GetBasket(AddOrRemoveFavouriteInBasketCommand request) { if (request.BasketId.HasValue) { return await _basketStore.GetAsync(request.BasketId.Value); } return null; }
public async Task <string> Handle(SaveApprenticeshipFavouriteBasketCommand request, CancellationToken cancellationToken) { _logger.LogInformation("Handling SaveApprenticeshipFavouriteCommand for basket: {basketId}", request.BasketId); var basketContentTask = _basketStore.GetAsync(request.BasketId); var employerAccountId = request.ChosenHashedAccountId ?? await GetEmployerAccountId(request.UserId); var favouritesTask = _readRepository.GetApprenticeshipFavourites(employerAccountId); await Task.WhenAll(basketContentTask, favouritesTask); var favourites = favouritesTask.Result ?? new Domain.ReadModel.ApprenticeshipFavourites(); var basketContent = basketContentTask.Result; var writeModel = favourites.MapToWriteModel(); if (basketContent == null || !basketContent.Any()) { return(employerAccountId); } bool changesMade = false; foreach (var item in basketContent) { changesMade |= writeModel.Update(item.ApprenticeshipId, item.Providers); } if (changesMade) { await _writeRepository.SaveApprenticeshipFavourites(employerAccountId, writeModel); _logger.LogDebug("Updated basket: {basketId}", request.BasketId); } else { _logger.LogDebug("No changes required for basket: {basketId}", request.BasketId); } _logger.LogDebug("Post save clean up. Deleting basket: {basketId}", request.BasketId); await _basketStore.RemoveAsync(request.BasketId); return(employerAccountId); }
public async Task <ApprenticeshipFavouritesBasketRead> Handle(GetBasketQuery request, CancellationToken cancellationToken) { _logger.LogInformation("Getting basket for {basketId}", request.BasketId); var basket = await _basketStore.GetAsync(request.BasketId); ApprenticeshipFavouritesBasketRead basketRead = null; if (basket != null && basket.Any()) { basketRead = new ApprenticeshipFavouritesBasketRead(basket); Parallel.ForEach(basketRead, (basketItem) => { EnrichApprenticeshipInfo(basketItem); }); } return(basketRead ?? new ApprenticeshipFavouritesBasketRead()); }