public async Task <IActionResult> Create([Bind("Id,Name")] Category category)
        {
            if (ModelState.IsValid)
            {
                _context.Add(category);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("Id,Name,Country")] Artist artist)
        {
            if (ModelState.IsValid)
            {
                _context.Add(artist);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(artist));
        }
        public async Task <IActionResult> Create([Bind("Id,Name,CartId")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                _context.Add(customer);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CartId"] = new SelectList(_context.Cart, "Id", "Id", customer.CartId);
            return(View(customer));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Create([Bind("Id,Date,Address,TotalPrice,CartId")] Order order)
        {
            if (ModelState.IsValid)
            {
                _context.Add(order);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CartId"] = new SelectList(_context.Cart, "Id", "Id", order.CartId);
            return(View(order));
        }
        public async Task <IActionResult> Create([Bind("Id,Quantity,CartId,ProductId")] CartItem cartItem)
        {
            if (ModelState.IsValid)
            {
                _context.Add(cartItem);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CartId"]    = new SelectList(_context.Cart, "Id", "Id", cartItem.CartId);
            ViewData["ProductId"] = new SelectList(_context.Set <Product>(), "Id", "Name", cartItem.ProductId);
            return(View(cartItem));
        }
        // GET: Products/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var product = await _context.Product
                          .Include(p => p.Artist)
                          .Include(p => p.Category)
                          .FirstOrDefaultAsync(m => m.Id == id);

            if (product == null)
            {
                return(NotFound());
            }
            else
            {
                try
                {
                    // increase click when enter details and update database
                    product.Click = product.Click + 1;
                    _context.Update(product);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ProductExists(product.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
            }

            return(View(product));
        }
        // Mock purchase function, removes quantities from stock only without mock pay or anything
        public IActionResult Purchase()
        {
            List <Item> cart = SessionHelper.GetObjectFromJson <List <Item> >(HttpContext.Session, "cart");

            for (int i = 0; i < cart.Count; i++)
            {
                var product = cart[i].Product;
                product.Quantity = product.Quantity - cart[i].Quantity;
                // Remove product from database if no stock left
                if (product.Quantity <= 0)
                {
                    _context.Product.Remove(product);
                }
                // Update with new stock
                else
                {
                    _context.Product.Update(product);
                }
            }
            _context.SaveChangesAsync();
            cart = new List <Item>();
            SessionHelper.SetObjectAsJson(HttpContext.Session, "cart", cart);
            return(Redirect("~/Products"));
        }