Created
March 24, 2022 15:56
-
-
Save mortezadalil/d9c48acc45e1c4a354fea955dbbc6bc7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[HttpPost("UpdateBasketItems")] | |
public async Task<Basket.Api.Models.Basket?> UpdateBasketItems(Basket.Api.Models.Basket basket) | |
{ | |
using var channel = GrpcChannel.ForAddress(_configuration.GetValue<string>("DiscountGrpcServerUrl")); | |
var client = new Price.PriceClient(channel); | |
foreach (var item in basket.BasketItems) | |
{ | |
var reply = await client.GetPriceAsync(new PriceRequest() { Id = item.ProductId }); | |
if (!string.IsNullOrEmpty(reply.ErrorMessage)) | |
{ | |
throw new Exception("Price Undefined"); | |
} | |
item.Price = reply.CurrentAmount; | |
} | |
await _rediscache.SetStringAsync(basket.UserName, JsonSerializer.Serialize(basket)); | |
return JsonSerializer.Deserialize<Basket.Api.Models.Basket>(await _rediscache.GetStringAsync(basket.UserName)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment