Exemplo n.º 1
0
        public ActionResult Create(ProductCreateViewModel createViewModel)
        {
            if (createViewModel == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            if (this.ModelState.IsValid)
            {
                using (var db = new YonkersContext())
                {
                    Producto pro = new Producto
                    {
                        categoriaID = createViewModel.CategoryId,
                        yonkerID    = 1,
                        nombrepro   = createViewModel.Name,
                        precio      = createViewModel.Precio,
                    };
                    db.Producto.Add(pro);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            return(this.View(createViewModel));
        }
Exemplo n.º 2
0
        public ActionResult Create()
        {
            ProductCreateViewModel p = new ProductCreateViewModel();

            using (YonkersContext db = new YonkersContext())
            {
                p.CategoryList = db.Categoria.ToList <Categoria>();
            }
            return(this.View(p));
        }