public async Task Handle(Entities.Item.Events.ItemAdded e, IMessageHandlerContext ctx) { var basket = await ctx.UoW().Get <Models.BasketIndex>(e.BasketId) .ConfigureAwait(false); var product = await ctx.UoW() .Get <Catalog.Product.Models.CatalogProductIndex>(e.ProductId).ConfigureAwait(false); basket.TotalItems++; basket.TotalQuantity++; basket.SubTotal += product.Price; await ctx.UoW().Update(e.BasketId, basket).ConfigureAwait(false); }
public async Task Handle(Entities.Item.Events.ItemAdded e, IMessageHandlerContext ctx) { var basket = await ctx.UoW().Get <Models.Basket>(e.BasketId) .ConfigureAwait(false); var product = await ctx.UoW() .Get <Catalog.Product.Models.CatalogProduct>(e.ProductId).ConfigureAwait(false); basket.Items = basket.Items.TryAdd(new Entities.Item.Models.BasketItem { Id = ItemIdGenerator(e.BasketId, e.ProductId), ProductId = e.ProductId, BasketId = e.BasketId, ProductName = product.Name, ProductDescription = product.Description, ProductPictureContents = product.PictureContents, ProductPictureContentType = product.PictureContentType, ProductPrice = product.Price, Quantity = 1 }, x => x.Id); await ctx.UoW().Update(e.BasketId, basket).ConfigureAwait(false); }