コード例 #1
0
        public ActionResult Edit(Product p, string command)
        {
            if (p == null || string.IsNullOrEmpty(command))
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            if (p == null || string.IsNullOrEmpty(command))
            {
                return HttpNotFound();
            }

            if (command.Equals("Update"))
            {
                Debug.WriteLine("c " + command);
                if (ModelState.IsValid)
                {
                    p.updateProduct(p);
                }
                else
                {
                    return View(p);
                }
            }
            else
            {
                Debug.WriteLine("c " + command);
                p.deleteProduct(p.productId);
            }
            return RedirectToAction("Details");

        }
コード例 #2
0
 // GET: /Product/Edit
 public ActionResult Edit(int productId)
 {
     Debug.WriteLine("in controller " + productId);
     if (productId < 0)
     {
         return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
     }
     if (productId < 0)
     {
         Debug.WriteLine("not found");
         return HttpNotFound();
     }
     Product p = new Product(productId);
     return View(p);
 }
コード例 #3
0
 public ActionResult Add(Product p)
 {
     Debug.WriteLine("ins " + p.SelectedCat);
     if (ModelState.IsValid)
     {
         Debug.WriteLine("id = ");
         p.insertProduct(p);
     }
     else
     {
         Debug.WriteLine("id != ");
         return View(p);
     }
     return RedirectToAction("Details");
 }
コード例 #4
0
        public ActionResult Edit(Product p, string command)
        {
            Debug.WriteLine("ins " + p.SelectedCat);
            Debug.WriteLine("id " + p.productId);

            if (command.Equals("Update"))
            {
                Debug.WriteLine("c " + command);
                if (ModelState.IsValid)
                {
                    p.updateProduct(p);
                }
                else
                {
                    return View(p);
                }
            }
            else
            {
                Debug.WriteLine("c " + command);
                p.deleteProduct(p.productId);
            }
            return RedirectToAction("Details");
        }
コード例 #5
0
        public ActionResult Add(Product p)
        {
            if (p == null )
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            if (p == null )
            {
                return HttpNotFound();
            }

            Debug.WriteLine("ins " + p.SelectedCat);
            if (ModelState.IsValid)
            {
                Debug.WriteLine("id = ");
                p.insertProduct(p);
            }
            else
            {
                Debug.WriteLine("id != ");
                return View(p);
            }
            return RedirectToAction("Details");
        }
コード例 #6
0
        public void updateProduct(Product p)
        {
            using (MySqlConnection con = new MySqlConnection(con_str))
            {
                con.Open();
                using (MySqlCommand cmd = new MySqlCommand("updateProduct", con))
                {
                    cmd.CommandType = CommandType.StoredProcedure;

                    //params for insert into category
                   // cmd.Parameters.AddWithValue("_categoryName", p.categoryName);
                    //cmd.Parameters.AddWithValue("@_catDescription", p.categoryDescrip);
                    //cmd.Parameters.AddWithValue("@_categoryInUse", p.catInUse);
                    cmd.Parameters.AddWithValue("@_catId", p.SelectedCat);

                    //params for insert into product
                    cmd.Parameters.AddWithValue("@_barcode", p.barcode);
                    cmd.Parameters.AddWithValue("@_productName", p.productName);
                    cmd.Parameters.AddWithValue("@_prodDescription", p.productDesc);
                    cmd.Parameters.AddWithValue("@_unitPrice", p.unitPrice);
                    cmd.Parameters.AddWithValue("@_mrrp", p.mrrp);
                    cmd.Parameters.AddWithValue("@_unitsInStock", p.unitsInStock);
                    cmd.Parameters.AddWithValue("@_unitWeight", p.unitWeight);
                    cmd.Parameters.AddWithValue("@_quantityPerUnit", p.qPerUnit);
                    cmd.Parameters.AddWithValue("@_picUrl", p.picUrl);
                    cmd.Parameters.AddWithValue("@_featured", p.featured);
                    cmd.Parameters.AddWithValue("@_staffPic", p.staffPick);
                    cmd.Parameters.AddWithValue("@_prodId", p.productId);

                    cmd.ExecuteNonQuery();

                    con.Close();
                }
            }
        }