コード例 #1
0
        public ActionResult Edit(int id, Product product)
        {
            try
            {
                var db    = new CRUDExample();
                var model = (from p in db.Product
                             where p.Id == id
                             select p).FirstOrDefault();
                if (model != null)
                {
                    model.Name = product.Name;

                    db.SaveChanges();
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                // Set our navigation again, or it will be lost - these values disappear
                // on each request and need to be restored if we go back to the same view.
                var node1 = SiteMaps.Current.FindSiteMapNodeFromKey("Product_Edit");
                if (node1 != null)
                {
                    // Set the id of the Edit node
                    node1.RouteValues["id"] = id;
                    var parent = node1.ParentNode;
                    if (parent != null)
                    {
                        // Set the id of the Details node
                        parent.RouteValues["id"] = id;

                        // Set the title and description of the Details node based on postback data
                        parent.Title       = product.Name;
                        parent.Description = product.Name;
                    }

                    // Set a custom attribute - we can set this to any object
                    node1.Attributes["CustomKey"] = "SomeCustomValue";
                }
                return(View());
            }
        }
コード例 #2
0
        public ActionResult Create(Product product)
        {
            try
            {
                var db    = new CRUDExample();
                var model = new Entity.Product();
                if (model != null)
                {
                    model.Name = product.Name;

                    db.Product.Add(model);
                    db.SaveChanges();
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
コード例 #3
0
        public ActionResult Delete(int productId, Product product)
        {
            try
            {
                var db    = new CRUDExample();
                var model = (from p in db.Product
                             where p.Id == productId
                             select p).FirstOrDefault();
                if (model != null)
                {
                    db.Product.Remove(model);
                    db.SaveChanges();
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
        public ActionResult Edit(int id, Product product)
        {
            try
            {
                var db    = new CRUDExample();
                var model = (from p in db.Product
                             where p.Id == id
                             select p).FirstOrDefault();
                if (model != null)
                {
                    model.Name = product.Name;

                    db.SaveChanges();
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
        public ActionResult Delete(int productOptionId, int productId, ProductOption productOption)
        {
            try
            {
                var db    = new CRUDExample();
                var model = (from po in db.ProductOption
                             where po.Id == productOptionId
                             select po).FirstOrDefault();
                if (model != null)
                {
                    db.ProductOption.Remove(model);
                    db.SaveChanges();
                }

                return(RedirectToAction("Details", "Product", new { productId = productId }));
            }
            catch
            {
                // Set the Product Node's Title
                SetNodeTitle(GetProductName(productId), 3);
                return(View());
            }
        }
コード例 #6
0
        public ActionResult Delete(int id, Product product)
        {
            try
            {
                var db    = new CRUDExample();
                var model = (from p in db.Product
                             where p.Id == id
                             select p).FirstOrDefault();
                if (model != null)
                {
                    db.Product.Remove(model);
                    db.SaveChanges();
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                // Set our navigation again, or it will be lost - these values disappear
                // on each request and need to be restored if we go back to the same view.
                var node1 = SiteMaps.Current.FindSiteMapNodeFromKey("Product_Delete");
                if (node1 != null)
                {
                    // Set the id of the Edit node
                    node1.RouteValues["id"] = id;
                    var parent = node1.ParentNode;
                    if (parent != null)
                    {
                        // Set the id of the Details node
                        parent.RouteValues["id"] = id;
                    }
                }

                return(View());
            }
        }
        public ActionResult Create(int productId, ProductOption productOption)
        {
            try
            {
                var db    = new CRUDExample();
                var model = new ProductOption();
                if (model != null)
                {
                    model.ProductId = productId;
                    model.Name      = productOption.Name;

                    db.ProductOption.Add(model);
                    db.SaveChanges();
                }

                return(RedirectToAction("Details", "Product", new { productId = productId }));
            }
            catch
            {
                // Set the Product Node's Title
                SetNodeTitle(GetProductName(productId), 2);
                return(View());
            }
        }