public async Task <IActionResult> Edit(int id, [Bind("Id,Name")] ShoeCategory shoeCategory)
        {
            if (id != shoeCategory.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(shoeCategory);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ShoeCategoryExists(shoeCategory.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(shoeCategory));
        }
        public async Task <IActionResult> Create([Bind("Id,Name")] ShoeCategory shoeCategory)
        {
            if (ModelState.IsValid)
            {
                _context.Add(shoeCategory);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(shoeCategory));
        }
Example #3
0
        public IActionResult Add(AddCategoryViewModel addCategoryViewModel)
        {
            if (ModelState.IsValid)
            {
                ShoeCategory newCategory = new ShoeCategory
                {
                    Name = addCategoryViewModel.Name
                };

                context.Categories.Add(newCategory);
                context.SaveChanges();

                return(Redirect("/Category"));
            }

            return(View(addCategoryViewModel));
        }
Example #4
0
        public IActionResult Add(AddShoeViewModel addShoeViewModel)
        {
            if (ModelState.IsValid)
            {
                ShoeCategory catg = context.Categories.Single(s => s.ID == addShoeViewModel.CategoryID);
                // Add the new cheese to my existing cheeses
                Shoe Shoe = new Shoe
                {
                    Name        = addShoeViewModel.Name,
                    Description = addShoeViewModel.Description,
                    Category    = catg
                };

                context.Shoes.Add(Shoe);
                context.SaveChanges();

                return(Redirect("/Shoe"));
            }

            return(View(addShoeViewModel));
        }