public async Task <IActionResult> PutBasketCard([FromRoute] string id, [FromBody] BasketCard basketCard)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != basketCard.BasketCardId)
            {
                return(BadRequest());
            }

            _context.Entry(basketCard).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!BasketCardExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("Milliliter,IsFrozen,ProductID,Name,Price,Description,Stockpiled")] Dessert dessert)
        {
            if (ModelState.IsValid)
            {
                _context.Add(dessert);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(dessert));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("Milliliter,IsCarbonated,ProductID,Name,Price,Description,Stockpiled")] Beverage beverage)
        {
            if (ModelState.IsValid)
            {
                _context.Add(beverage);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(beverage));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> Create([Bind("Weight,SaltWeight,ProductID,Name,Price,Description,Stockpiled")] Side side)
        {
            if (ModelState.IsValid)
            {
                _context.Add(side);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(side));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Create([Bind("BasketCardId,CreatedOn,IsActive,ShippingAmount")] BasketCard basketCard)
        {
            if (ModelState.IsValid)
            {
                _context.Add(basketCard);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(basketCard));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Create([Bind("Id,Discount,Comments,DateCreated,DateModified,IsValidate,CustomerId,CreatedBy,UpdatedBy,UpdatedDate,CreatedDate")] Order order)
        {
            if (ModelState.IsValid)
            {
                _context.Add(order);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CustomerId"] = new SelectList(_context.Customers, "PersonId", "Discriminator", order.CustomerId);
            return(View(order));
        }
Ejemplo n.º 7
0
        public async Task AddToCart(long userId, long productId, int quantity)
        {
            var basketCard = context.BasketCards.FirstOrDefault(x => x.Customer.PersonId == userId && x.IsActive);

            if (basketCard == null)
            {
                basketCard = new BasketCard
                {
                    Customer = context.Customers.FirstOrDefault(p => p.PersonId == userId)
                };

                context.BasketCards.Add(basketCard);
            }
            var basketCardItem = basketCard.BasketCardItems.FirstOrDefault(x => x.Product.ProductID == productId);

            if (basketCardItem == null)
            {
                basketCardItem = new BasketCardItem
                {
                    BasketCard = basketCard,
                    Product    = context.Products.FirstOrDefault(p => p.ProductID == productId),
                    Quantity   = quantity
                };

                basketCard.BasketCardItems.Add(basketCardItem);
            }
            else
            {
                basketCardItem.Quantity = quantity;
            }

            await context.SaveChangesAsync();
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> PutOrder([FromRoute] int id, [FromBody] Order order)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != order.Id)
            {
                return(BadRequest());
            }
            if (order.IsValidate == true)
            {
                return(BadRequest());
            }


            _context.Entry(order).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!OrderExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }