예제 #1
0
        public async Task SetHighlighted(int pid)
        {
            Product p = await _context.Products.FindAsync(pid);

            p.Highlighted = !p.Highlighted;
            await _context.SaveChangesAsync();
        }
예제 #2
0
        public async Task <bool> DecreaseProductStockAsync(int id, int quant)
        {
            var q = await _ctx.Inventory.Where(p => p.ProductId == id).FirstOrDefaultAsync();

            if (q == null || (q.Quantity - quant < 0))
            {
                return(false);
            }
            q.Quantity -= quant;
            await _ctx.SaveChangesAsync();

            return(true);
        }
예제 #3
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            Product = await _context.Products.FindAsync(id);

            if (Product != null)
            {
                _context.Products.Remove(Product);
                await _context.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }