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

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(shoe);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ShoeExists(shoe.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(shoe));
        }
示例#2
0
        public async Task <IActionResult> Create([Bind("Id,Name,Price,Category")] SpecificShoeViewModel shoeViewModel)
        {
            if (ModelState.IsValid)
            {
                var categoryId = Int32.Parse(shoeViewModel.Category);

                var shoe = new SpecificShoe
                {
                    Name     = shoeViewModel.Name,
                    Price    = shoeViewModel.Price,
                    Category = _context.ShoeCategory.First(e => e.Id == categoryId)
                };

                _context.Add(shoe);
                await _context.SaveChangesAsync();

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