Skip to content

Instantly share code, notes, and snippets.

@mortezadalil
Created March 24, 2022 15:56
Show Gist options
  • Save mortezadalil/d9c48acc45e1c4a354fea955dbbc6bc7 to your computer and use it in GitHub Desktop.
Save mortezadalil/d9c48acc45e1c4a354fea955dbbc6bc7 to your computer and use it in GitHub Desktop.
[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