// GET: /Category/Edit
 public ActionResult Edit(int categoryId)
 {
     Debug.WriteLine("in controller " + categoryId);
     if (categoryId < 0)
     {
         //Debug.WriteLine("null");
         return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
     }
     if (categoryId < 0)
     {
         Debug.WriteLine("not found");
         return HttpNotFound();
     }
     Category c = new Category(categoryId);
     return View(c);
 }
        public ActionResult Add(Category c)
        {

            if (c == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            if (c == null)
            {
                return HttpNotFound();
            }

            if (ModelState.IsValid)
            {
                Debug.WriteLine("id = ");
                c.insertCategory(c);
            }
            else
            {
                Debug.WriteLine("id != ");
                return View(c);
            }
            return RedirectToAction("Details");
        }
Example #3
0
        public void insertCategory(Category c)
        {
            using (MySqlConnection con = new MySqlConnection(con_str))
            {
                con.Open();
                using (MySqlCommand cmd = new MySqlCommand("insertNewCategory", con))
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    //params for insert into category
                    cmd.Parameters.AddWithValue("@_catName", c.categoryName);
                    cmd.Parameters.AddWithValue("@_catDescription", c.categoryDescrip);
                    cmd.Parameters.AddWithValue("@_catInUse", c.catInUse);
                    cmd.Parameters.AddWithValue("@_picUrl", c.picURL);
                    
                    cmd.ExecuteNonQuery();

                    con.Close();
                }
            }
        }