Exemple #1
0
        public async Task <IActionResult> AddToCart(int id)
        {
            var exisingFood = await _context.PurchaseOrder.FirstOrDefaultAsync(m => m.FoodId == id);

            if (exisingFood != null)
            {
                exisingFood.Quantity++;
            }
            else
            {
                PurchaseOrder purchaseOrder = new PurchaseOrder()
                {
                    Customer = "anagha",
                    Quantity = 1,
                    FoodId   = id,

                    DateCreated = DateTime.UtcNow
                };

                _context.Add(purchaseOrder);
            }

            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> Create([Bind("Id,Name,Description")] Category category)
        {
            if (ModelState.IsValid)
            {
                category.CreatedDate = DateTime.UtcNow;
                _context.Add(category);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(category));
        }
Exemple #3
0
        public async Task <IActionResult> Create([Bind("Id,Name,Description,Price,Quantity,CategoryId,Ingredients")] Food food)
        {
            if (ModelState.IsValid)
            {
                _context.Add(food);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["CategoryId"] = new SelectList(_context.Category, "Id", "Id", food.CategoryId);
            return(View(food));
        }