Esempio n. 1
0
        public async Task <ActionResult <CheckoutItem> > PostCheckoutItem(CheckoutItem item)
        {
            _context.CheckoutItems.Add(item);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetCheckoutItem), new { id = item.Id }, item));
        }
Esempio n. 2
0
        public async Task RemoveAsync(Guid cartId)
        {
            var items = context.Cart.Where(w => w.CartId == cartId);

            context.Cart.RemoveRange(items);

            await context.SaveChangesAsync();
        }
        public async Task RemoveAsync(Guid cartId)
        {
            // TODO: add soft delete logic here for beta

            // in mem db, for prototype sufficient
            var items = context.Cart.Where(w => w.CartId == cartId);

            context.Cart.RemoveRange(items);
            await context.SaveChangesAsync();
        }
        public async Task <ActionResult> Post([FromBody] Payment paymentRequest)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if ((await _context.Payments.FindAsync(paymentRequest.Id)) != null)
            {
                return(Conflict());
            }

            _context.Payments.Add(paymentRequest);
            await _context.SaveChangesAsync();

            return(CreatedAtRoute(nameof(Get), new { id = paymentRequest.Id }));
        }
        public async Task AddItemsToBasket(Guid customerId, AddItemsRequest request)
        {
            var basket = await GetCustomerBasket(customerId);

            if (basket == null)
            {
                basket = await CreateBasketForCustomer(customerId);
            }

            var item = basket.Items?.FirstOrDefault(x => x.ProductId == request.ProductId);

            if (item != null)
            {
                item.Quantity += request.Quantity;

                await _checkoutContext.SaveChangesAsync();
            }
            else
            {
                var products = await _productService.GetProducts();

                if (products.Any(x => x.Id == request.ProductId))
                {
                    item = new Item
                    {
                        UpdatedAt = DateTime.Now,
                        BasketId  = basket.Id,
                        ProductId = request.ProductId,
                        Quantity  = request.Quantity
                    };

                    await _checkoutContext.Items.AddAsync(item);

                    await _checkoutContext.SaveChangesAsync();
                }
                else
                {
                    throw new Exception("The specified product does not exist");
                }
            }
        }
        public async Task AddCustomer(Customer customer)
        {
            await _checkoutContext.Customers.AddAsync(customer);

            await _checkoutContext.SaveChangesAsync();
        }