public ActionResult Edit(Category category) { if (ModelState.IsValid) //checking model is valid or not { categorymodels.Edit(category); List<Category> model = new List<Category>(); model = categorymodels.SelectAll(); return View("List", model); } return View(category); }
public ActionResult Add(Category category) { if (ModelState.IsValid) //checking model is valid or not { bool result = categorymodels.Add(category); if (result) { List<Category> model = new List<Category>(); model = categorymodels.SelectAll(); return View("List", model); } } return View(category); }
public bool Edit(Category category) { SqlConnection con = null; bool result = false; try { con = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString()); SqlCommand cmd = new SqlCommand(); cmd.CommandText = "Update Category set name_category='" + category.C_Name + "' + description_category='" + category.C_desc + "'; cmd.Connection = con; cmd.CommandType = CommandType.Text; con.Open(); cmd.ExecuteNonQuery(); return result = true; } catch (Exception ex) { return result = false; } finally { con.Close(); } }
public bool Add(Category category) { SqlConnection con = null; bool result = false; try { con = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ToString()); SqlCommand cmd = new SqlCommand(); cmd.CommandText = "Insert into Category(name_Category,description_Category) values ('" + category.C_Name + category.C_desc+"')"; cmd.Connection = con; cmd.CommandType = CommandType.Text; con.Open(); cmd.ExecuteNonQuery(); return result = true; } catch (Exception ex) { return result = false; } finally { con.Close(); } }
public ActionResult Edit(int Id = 0) { Category category = new Category(); category = categorymodels.SelectById(Id); return View("Edit", category); }
public ActionResult Add() { Category model = new Category(); return View(model); }