Пример #1
0
        public ActionResult Edit(int id)
        {
            var product = db.Products.Find(id);

            var productViewModel = new ProductVIewModel();

            productViewModel.Id    = product.Id;
            productViewModel.Name  = product.Name;
            productViewModel.Price = product.Price;
            return(Json(productViewModel, JsonRequestBehavior.AllowGet));
        }
Пример #2
0
        public ActionResult Edit(ProductVIewModel product)
        {
            Products newproduct = db.Products.Find(product.Id);

            if (newproduct != null)
            {
                newproduct.Id    = product.Id;
                newproduct.Name  = product.Name;
                newproduct.Price = product.Price;
                db.SaveChanges();
            }
            ;

            return(Json("success save"));
        }
Пример #3
0
        public ActionResult Create(ProductVIewModel product)
        {
            int id = createId();
            // if (ModelState.IsValid)
            // {

            var newproduct = new Products
            {
                Id    = id,
                Name  = product.Name,
                Price = product.Price
            };

            db.Products.Add(newproduct);
            db.SaveChanges();
            return(Json("success save", JsonRequestBehavior.AllowGet));
            // }
            //return Json("the model " +
            //  "is not right");
        }