public async Task SendDeleteMessage(DataAccess.Entities.Cart cart) { var subscribers = _context.Subscribers.ToList(); var serializedData = JsonSerializer.Serialize(cart); using (var client = _clientFactory.CreateClient()) { foreach (var subscriber in subscribers) { var message = new HttpRequestMessage(HttpMethod.Post, subscriber.SubscribeUrl) { Content = new StringContent(serializedData) }; await client.SendAsync(message); } } }
private async Task AddItemToExistingCart(AddProductToCartDto item, DataAccess.Entities.Cart cart) { var cartItem = cart.CartItems.FirstOrDefault(c => c.ProductId == item.ProductId); if (cartItem != null) { cartItem.Quantity++; _context.CartItems.Update(cartItem); } else { cartItem = new CartItem() { CartId = cart.Id, ProductId = item.ProductId, ForBonusPoints = item.ForBonusPoints, Quantity = 1 }; await _context.CartItems.AddAsync(cartItem); } }
private async Task <DataAccess.Entities.Cart> CreateNewCart(AddProductToCartDto item) { var cart = new DataAccess.Entities.Cart() { CartId = item.CartId }; var result = await _context.Carts.AddAsync(cart); await _context.SaveChangesAsync(); var cartItem = new CartItem() { CartId = result.Entity.Id, ProductId = item.ProductId, ForBonusPoints = item.ForBonusPoints, Quantity = 1 }; await _context.CartItems.AddAsync(cartItem); return(cart); }