示例#1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Price,Weight,Cost")] Foodstuffs foodstuffs)
        {
            if (id != foodstuffs.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(foodstuffs);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!FoodstuffsExists(foodstuffs.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }

                return(RedirectToAction(nameof(Index)));
            }

            return(View(foodstuffs));
        }
示例#2
0
        public async Task <IActionResult> Create([Bind("Id,Name,Price,Weight,Cost")] Foodstuffs foodstuffs)
        {
            if (ModelState.IsValid)
            {
                _context.Add(foodstuffs);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }

            return(View(foodstuffs));
        }