Beispiel #1
0
        public static void addCat(int certID, string title, string text, string image_path, bool inActive)
        {
            try {
                B2BDataContext db = new B2BDataContext();

                B2BCategory newCat = new B2BCategory();
                newCat.certID = certID;
                newCat.title = title;
                newCat.text = text;
                newCat.image_path = image_path;
                newCat.date_added = DateTime.Now;
                newCat.date_modified = DateTime.Now;
                newCat.inactive = inActive;
                db.B2BCategories.InsertOnSubmit(newCat);
                db.SubmitChanges();
            } catch (Exception e) {
                throw new Exception("Could not add category: " + e.Message);
            }
        }
Beispiel #2
0
        public ActionResult EditCat(int id, string title, string text, string logo, string inactive)
        {
            ViewBag.error = "";
            if (id > 0) {
                Boolean inActive = false;
                inActive = (inactive == "on") ? true : false;

                // retrieve the cat with the id
                try {
                    B2BDataContext db = new B2BDataContext();
                    B2BCategory cat = new B2BCategory();
                    cat = db.B2BCategories.Where(x => x.id == id).FirstOrDefault<B2BCategory>();
                    cat.title = title;
                    cat.text = text;
                    cat.image_path = logo;
                    cat.inactive = inActive;
                    db.SubmitChanges();

                    ViewBag.cat = cat;
                    ViewBag.msg = "The category changes have been made.";
                } catch (Exception e) {
                    ViewBag.error = e.Message;
                }
            } else {
                return RedirectToAction("Index");
            }
            return View();
        }
Beispiel #3
0
 public static B2BCategory getCategory(int catID)
 {
     try {
         B2BDataContext db = new B2BDataContext();
         B2BCategory cat = new B2BCategory();
         cat = db.B2BCategories.Where(x => x.id == catID).Select(x => x).FirstOrDefault<B2BCategory>();
         return cat;
     } catch (Exception e) {
         throw new Exception("Could not load category: " + e.Message);
     }
 }
Beispiel #4
0
 public static string DeleteCat(int id)
 {
     try {
         B2BDataContext db = new B2BDataContext();
         B2BCategory cat = new B2BCategory();
         cat = db.B2BCategories.Where(x => x.id == id).FirstOrDefault<B2BCategory>();
         db.B2BCategories.DeleteOnSubmit(cat);
         db.SubmitChanges();
         return "";
     } catch (Exception) {
         return "Error while deleting";
     }
 }