public ActionResult AddCategory(string catName) { DocsLinqDataContext doc_db = new DocsLinqDataContext(); catName = Request.Form["catName"].Trim(); int parentID = Convert.ToInt32(Request.Form["parentID"].Trim()); string comments = Request.Form["comments"].Trim(); // Initiate our error message collection List<string> error_messages = new List<string>(); // Make sure the category name is not blank. if (catName.Length == 0) { error_messages.Add("Category name is required."); } if (error_messages.Count == 0) { // Create new category object docCategory newCat = new docCategory { catName = catName, parentID = parentID, comments = comments }; doc_db.docCategories.InsertOnSubmit(newCat); try { // Attempt to save the category doc_db.SubmitChanges(); return RedirectToAction("Index"); } catch (Exception e) { error_messages.Add(e.Message); } } ViewBag.catName = catName; ViewBag.parentID = parentID; ViewBag.comments = comments; ViewBag.error_messages = error_messages; // Get all categories List<docCategory> categories = (from c in doc_db.docCategories orderby c.catName select c).ToList<docCategory>(); ViewBag.categories = categories; return View(); }
public ActionResult EditCategory(string cat_id) { DocsLinqDataContext doc_db = new DocsLinqDataContext(); int catID = Convert.ToInt32(cat_id); // Get all categories List<docCategory> categories = (from cats in doc_db.docCategories orderby cats.catName select cats).ToList<docCategory>(); ViewBag.categories = categories; // Get the category to be updated docCategory cat = new docCategory(); cat = (from c in doc_db.docCategories where c.catID.Equals(catID) select c).FirstOrDefault<docCategory>(); ViewBag.cat = cat; return View(); }
public ActionResult EditCategory(string cat_id, string catName) { DocsLinqDataContext doc_db = new DocsLinqDataContext(); int catID = Convert.ToInt32(cat_id); catName = Request.Form["catName"].Trim(); int parentID = Convert.ToInt32(Request.Form["parentID"].Trim()); string comments = Request.Form["comments"]; // Initiate error messages list List<string> error_messages = new List<string>(); // validate category info if (catName.Length == 0) { error_messages.Add("Category name is required."); } // Get the category to be updated docCategory cat = new docCategory(); cat = (from c in doc_db.docCategories where c.catID.Equals(catID) select c).FirstOrDefault<docCategory>(); if (error_messages.Count == 0) { // Attempt to save category cat.catName = catName; cat.parentID = parentID; cat.comments = comments; try { doc_db.SubmitChanges(); return RedirectToAction("Index"); } catch (Exception e) { error_messages.Add(e.Message); } } // Get all categories List<docCategory> categories = (from cats in doc_db.docCategories orderby cats.catName select cats).ToList<docCategory>(); ViewBag.categories = categories; ViewBag.cat = cat; ViewBag.error_messages = error_messages; return View(); }
/// <summary> /// Gets the category. /// </summary> /// <param name="catID">The cat ID.</param> /// <returns></returns> /// <remarks></remarks> public static docCategory GetCategory(int catID = 0) { docCategory cat = new docCategory(); DocsLinqDataContext doc_db = new DocsLinqDataContext(); if (catID > 0) { cat = (from c in doc_db.docCategories where c.catID.Equals(catID) select c).Single<docCategory>(); } return cat; }