Ejemplo n.º 1
0
        public ActionResult Create([Bind(Include = "Id,Name,Description")] Category category)
        {
            if (ModelState.IsValid)
            {
                db.Categories.Add(category);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(category));
        }
Ejemplo n.º 2
0
        public ActionResult Create([Bind(Include = "Id,Name,Description,ShortDesc,Price,Discount,DiscountPrice,ImageUrl,Warranty,Available,New,Model,Colour,Delivery,CategoryId")] Product product, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                if (file != null)
                {
                    string path = Path.Combine(Server.MapPath("~/ProductImages"), Path.GetFileName(file.FileName));
                    file.SaveAs(path);
                    product.ImageUrl = "~/ProductImages/" + Path.GetFileName(file.FileName);
                }
                db.Products.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CategoryId = new SelectList(db.Categories, "Id", "Name", product.CategoryId);
            return(View(product));
        }