public ActionResult Create([Bind(Include = "SupplierID,CompanyName,Address,Phone")] Supplier supplier)
        {
            if (ModelState.IsValid)
            {
                db.Suppliers.Add(supplier);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(supplier));
        }
        public ActionResult Create([Bind(Include = "UserName,Password,Role")] Account account)
        {
            if (ModelState.IsValid)
            {
                db.Accounts.Add(account);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(account));
        }
Beispiel #3
0
        public ActionResult Create([Bind(Include = "CategoryID,CategoryName,Description")] Category category)
        {
            if (ModelState.IsValid)
            {
                db.Categories.Add(category);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(category));
        }
Beispiel #4
0
        public ActionResult Create([Bind(Include = "CustomerID,Password,ContactName,Address,Phone")] Customer customer)
        {
            if (ModelState.IsValid)
            {
                db.Customers.Add(customer);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(customer));
        }
        public ActionResult Create([Bind(Include = "OrderID,ProductID,UnitPrice,Quantity")] Order_Detail order_Detail)
        {
            if (ModelState.IsValid)
            {
                db.Order_Details.Add(order_Detail);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.OrderID   = new SelectList(db.Orders, "OrderID", "CustomerID", order_Detail.OrderID);
            ViewBag.ProductID = new SelectList(db.Products, "ProductID", "ProductName", order_Detail.ProductID);
            return(View(order_Detail));
        }
        public ActionResult Create([Bind(Include = "ProductID,ProductName,SupplierID,CategoryID,Quantity,UnitPrice,ProductImage,Description")] Product product)
        {
            if (ModelState.IsValid)
            {
                db.Products.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CategoryID = new SelectList(db.Categories, "CategoryID", "CategoryName", product.CategoryID);
            ViewBag.SupplierID = new SelectList(db.Suppliers, "SupplierID", "CompanyName", product.SupplierID);
            return(View(product));
        }
Beispiel #7
0
        public ActionResult Create(ProductViewModel model)
        {
            if (ModelState.IsValid)
            {//kiểm tra Model có hợp lệ?
                Product p = new Product();
                p.ProductID        = model.ProductID;
                p.ProductName      = model.ProductName;
                ViewBag.CategoryID = new SelectList(db.Categories, "CategoryID", "CategoryName", p.CategoryID);
                ViewBag.SupplierID = new SelectList(db.Suppliers, "SupplierID", "CompanyName", p.SupplierID);
                p.Quantity         = (Int32)model.Quantity;
                p.UnitPrice        = model.UnitPrice;
                var uploadDir = "~/Images/";

                var imageUrl = System.IO.Path.GetFileName(model.ProductImage.FileName);

                var imagePath = Path.Combine(Server.MapPath(uploadDir), imageUrl);

                model.ProductImage.SaveAs(imagePath);

                p.ProductImage = imageUrl;

                p.Description = model.Description;
                db.Products.Add(p);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }
            ModelState.AddModelError("", "Error input!");
            ViewBag.CategoryID = new SelectList(db.Categories, "CategoryID", "CategoryName");

            ViewBag.SupplierID = new SelectList(db.Suppliers, "SupplierID", "CompanyName");
            return(View(model));
        }