Exemplo n.º 1
0
        // GET: Product/Create
        public ActionResult Create()
        {
            ProductEditViewModel model = new ProductEditViewModel();
            model.Categories = bm.GetAllCategories();

            return View(model);
        }
Exemplo n.º 2
0
        // GET: Product/Edit/5
        public ActionResult Edit(int id)
        {
            ProductEditViewModel model = new ProductEditViewModel();
            model.Product = bm.GetProductById(id);
            model.Categories = bm.GetAllCategories();

            return View(model);
        }
Exemplo n.º 3
0
        public ActionResult Create(ProductEditViewModel model)
        {
            try
            {
                model.Categories = bm.GetAllCategories();

                if (model == null || !ModelState.IsValid)
                {
                    return View(model);
                }

                model.Product.Category = bm.GetCategoryById(model.Product.CategoryId);
                bm.AddProduct(model.Product);

                return RedirectToAction("Index");
            }
            catch (Exception e)
            {
                return View(model);
            }
        }