Exemplo n.º 1
0
 private void PopulateProduct(ProductEditModel model, Product product)
 {
     if (model.SupplierId != null)
     {
         product.Supplier = supplierRepository.Get(model.SupplierId.Value);
     }
     if (model.CategoryId != null)
     {
         product.Category = categoryRepository.Get(model.CategoryId.Value);
     }
 }
Exemplo n.º 2
0
        public ActionResult Edit(ProductEditModel model)
        {
            if (ModelState.IsValid)
            {
                var product = model.AsProduct();
                PopulateProduct(model, product);

                repository.Update(product);

                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
Exemplo n.º 3
0
        public ActionResult Create([Bind(Exclude = "Id")] ProductEditModel model)
        {
            if (ModelState.IsValid)
            {
                var product = model.AsProduct();
                product.Id = repository.All().Last().Id + 1;
                PopulateProduct(model, product);

                repository.Add(product);

                return(RedirectToAction("Index"));
            }

            return(View(model));
        }