Exemple #1
0
        public ActionResult EditTest(int id, string title, string text, double minPassPercent, string inactive)
        {
            ViewBag.error = "";
            if (id > 0) {
                Boolean inActive = false;
                inActive = (inactive == "on") ? true : false;

                // retrieve the test with the id
                try {
                    B2BDataContext db = new B2BDataContext();
                    B2BTest test = new B2BTest();
                    test = db.B2BTests.Where(x => x.id == id).FirstOrDefault<B2BTest>();
                    test.title = title;
                    test.text = text;
                    test.min_pass_percent = minPassPercent;
                    test.inactive = inActive;
                    db.SubmitChanges();

                    ViewBag.test = test;
                    ViewBag.msg = "The test changes have been made.";
                } catch (Exception e) {
                    ViewBag.error = e.Message;
                }
            } else {
                return RedirectToAction("Index");
            }
            return View();
        }
Exemple #2
0
 public static string DeleteTest(int id)
 {
     try {
         B2BDataContext db = new B2BDataContext();
         B2BTest test = new B2BTest();
         test = db.B2BTests.Where(x => x.id == id).FirstOrDefault<B2BTest>();
         db.B2BTests.DeleteOnSubmit(test);
         db.SubmitChanges();
         return "";
     } catch (Exception) {
         return "Error while deleting";
     }
 }
Exemple #3
0
 public static B2BTest getTest(int testID)
 {
     try {
         B2BDataContext db = new B2BDataContext();
         B2BTest test = new B2BTest();
         test = db.B2BTests.Where(x => x.id == testID).Select(x => x).FirstOrDefault<B2BTest>();
         return test;
     } catch (Exception e) {
         throw new Exception("Could not load the test: " + e.Message);
     }
 }
Exemple #4
0
        public static void addTest(int lessonID, string title, string text, double min_pass_percentage, bool inActive)
        {
            try {
                B2BDataContext db = new B2BDataContext();
                B2BLesson lesson = db.B2BLessons.Where(x => x.id == lessonID).FirstOrDefault<B2BLesson>();
                B2BTest newTest = new B2BTest();
                newTest.lessonID = lessonID;
                newTest.catID = lesson.catID;
                newTest.title = title;
                newTest.text = text;
                newTest.min_pass_percent = min_pass_percentage;
                newTest.date_added = DateTime.Now;
                newTest.date_modified = DateTime.Now;
                newTest.isRandomOrder = false;
                newTest.inactive = inActive;

                db.B2BTests.InsertOnSubmit(newTest);
                db.SubmitChanges();
            } catch (Exception e) {
                throw new Exception("Could not add test: " + e.Message);
            }
        }