Esempio n. 1
0
        public ActionResult Create()
        {
            ViewBag.Suppliers_list    = suppliersService.SuppliersList();
            ViewBag.Categories_list   = categoriesService.CategoriesList();
            ViewBag.Discontinued_list = Source.Source.DiscontinuedList();

            //Create
            ProductsFormModel product_create = new ProductsFormModel();

            product_create.Discontinued = "False";

            ViewBag.Header = "新增";

            return(View("CreateEdit", product_create));
        }
Esempio n. 2
0
        //物件 Formmodel 轉 物件 Model
        public Products FormmodelToModel(ProductsFormModel products)
        {
            Products model_products = new Products();

            model_products.ProductID       = int.Parse(products.ProductID);
            model_products.ProductName     = products.ProductName;
            model_products.SupplierID      = int.Parse(products.SupplierID);
            model_products.CategoryID      = int.Parse(products.CategoryID);
            model_products.QuantityPerUnit = products.QuantityPerUnit;
            model_products.UnitPrice       = products.UnitPrice;
            model_products.UnitsInStock    = products.UnitsInStock;
            model_products.UnitsOnOrder    = products.UnitsOnOrder;
            model_products.ReorderLevel    = products.ReorderLevel;
            model_products.Discontinued    = Convert.ToBoolean(products.Discontinued);

            return(model_products);
        }
Esempio n. 3
0
        //物件 Model 轉 物件 Formmodel
        public ProductsFormModel ModelToFormmodel(Products model_products)
        {
            ProductsFormModel products = new ProductsFormModel();

            products.ProductID       = model_products.ProductID.ToString();
            products.ProductName     = model_products.ProductName;
            products.SupplierID      = model_products.SupplierID.ToString();
            products.CategoryID      = model_products.CategoryID.ToString();
            products.QuantityPerUnit = model_products.QuantityPerUnit;
            products.UnitPrice       = model_products.UnitPrice;
            products.UnitsInStock    = model_products.UnitsInStock;
            products.UnitsOnOrder    = model_products.UnitsOnOrder;
            products.ReorderLevel    = model_products.ReorderLevel;
            products.Discontinued    = model_products.Discontinued.ToString();

            return(products);
        }
Esempio n. 4
0
        public ActionResult Edit(string productid)
        {
            ViewBag.Suppliers_list    = suppliersService.SuppliersList();
            ViewBag.Categories_list   = categoriesService.CategoriesList();
            ViewBag.Discontinued_list = Source.Source.DiscontinuedList();

            Models.Products products = productsService.SelectByID(productid);

            if (products == null)
            {
                return(HttpNotFound());
            }
            else
            {
                ProductsFormModel products_edit = ModelToFormmodel(products);

                ViewBag.Header = "修改";
                return(View("CreateEdit", products_edit));
            }
        }
Esempio n. 5
0
        public ActionResult CreateEdit([Bind(Include = "ProductID,ProductName,SupplierID,CategoryID,QuantityPerUnit," +
                                                       "UnitPrice,UnitsInStock,UnitsOnOrder,ReorderLevel,Discontinued")]
                                       ProductsFormModel products)
        {
            if (ModelState.IsValid)
            {
                if (products.ProductID == null)
                {
                    products.ProductID = productsService.newProductID();
                }

                Models.Products existing       = productsService.SelectByID(products.ProductID);
                Models.Products model_products = FormmodelToModel(products);

                if (existing == null)
                {
                    productsService.Create(model_products);
                    productsService.Save();

                    return(Content(@"<script>
                                      alert('新增成功,該產品編號為 [ " + model_products.ProductID.ToString() + @" ],返回查詢頁面');
                                      window.location = '/Products/Index';
                             </script>"));
                }
                else
                {
                    productsService.Edit(model_products);
                    productsService.Save();
                    return(Content(@"<script>
                                      alert('產品編號 [ " + products.ProductID + @" ] 修改成功,返回查詢頁面');
                                      window.location = '/Products/Index';
                             </script>"));
                }
            }
            return(View(products));
        }