Esempio n. 1
0
        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);
                }
            }
        }
Esempio n. 2
0
        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);
            }
        }
Esempio n. 3
0
        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);
        }