public async Task <IActionResult> PutSupplier(int id, Supplier supplier)
        {
            if (id != supplier.SupplierId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task <IActionResult> PutCategory(int id, Category category)
        {
            if (id != category.CategoryId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
        public async Task <IActionResult> PutProduct(int id, Product product)
        {
            if (id != product.ProductId)
            {
                return(BadRequest());
            }

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

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

            return(NoContent());
        }
Example #4
0
        public async Task DeleteProduct(int id)
        {
            Product product = _context.Product.FirstOrDefault(i => i.ID == id);

            _context.Product.Remove(product);
            await _context.SaveChangesAsync();
        }
        public async Task <IActionResult> Create([Bind("ID,Nombre,FechaApertura")] Tienda tienda)
        {
            if (ModelState.IsValid)
            {
                _context.Add(tienda);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(tienda));
        }
Example #6
0
        public async Task <IActionResult> Create([Bind("Id,Name")] Color color)
        {
            if (ModelState.IsValid)
            {
                _context.Add(color);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(color));
        }
        public async Task <IActionResult> Create([Bind("Id,Code,Name,Description,ImageUri,ColorId,CategoryId,GenderId")] Product product)
        {
            if (ModelState.IsValid)
            {
                _context.Add(product);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryId"] = new SelectList(_context.Categories, "Id", "Id", product.CategoryId);
            ViewData["ColorId"]    = new SelectList(_context.Colors, "Id", "Id", product.ColorId);
            ViewData["GenderId"]   = new SelectList(_context.Genders, "Id", "Id", product.GenderId);
            return(View(product));
        }
        /// <summary>
        /// this will create a new order for the user
        /// </summary>
        /// <param name="user">user that is creating the order</param>
        /// <param name="grandTotal">the total price</param>
        /// <returns>the order obj</returns>
        public async Task <Order> CreateOrder(ApplicationUser user, double grandTotal)
        {
            Order order = new Order
            {
                FirstName  = user.FirstName,
                LastName   = user.LastName,
                UserID     = user.Id,
                GrandTotal = grandTotal,
                OrderDate  = DateTime.Today
            };
            await _shop.Orders.AddAsync(order);

            await _shop.SaveChangesAsync();

            return(order);
        }
        public async Task AddBasketItem(int productID, string username)
        {
            try
            {
                Basket basket = await _context.Basket
                                .FirstOrDefaultAsync(x => x.UserName == username);

                Product product = await _context.Product
                                  .FirstOrDefaultAsync(x => x.ID == productID);

                if (BasketExists(productID, username))
                {
                    BasketItems item = await _context.BasketItems.FirstOrDefaultAsync(x => x.ID == productID);

                    item.Quantity++;
                    item.LineItemAmount += product.Price;
                }
                else
                {
                    BasketItems basketItem = new BasketItems()
                    {
                        BasketID       = basket.ID,
                        ProductID      = product.ID,
                        Product        = product,
                        Quantity       = 1,
                        LineItemAmount = product.Price
                    };
                    _context.BasketItems.Add(basketItem);
                }
                await _context.SaveChangesAsync();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }