public static void addAnswer(int questionID, string text, bool isCorrect, bool inActive) { try { B2BDataContext db = new B2BDataContext(); B2BAnswer newAnswer = new B2BAnswer(); newAnswer.questionID = questionID; newAnswer.text = text; newAnswer.isCorrect = isCorrect; newAnswer.date_added = DateTime.Now; newAnswer.date_modified = DateTime.Now; newAnswer.inactive = inActive; db.B2BAnswers.InsertOnSubmit(newAnswer); db.SubmitChanges(); } catch (Exception e) { throw new Exception("Could not add Answer: " + e.Message); } }
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); } }
//////////////////////== Create ==//////////////////////////// public static void addCert(string title, string text, int reqNum, string image_path, bool inActive) { try { B2BDataContext db = new B2BDataContext(); B2BCertificate newCertificate = new B2BCertificate(); newCertificate.title = title; newCertificate.text = text; newCertificate.requirementNum = reqNum; newCertificate.image_path = image_path; newCertificate.date_added = DateTime.Now; newCertificate.date_modified = DateTime.Now; newCertificate.inactive = inActive; db.B2BCertificates.InsertOnSubmit(newCertificate); db.SubmitChanges(); } catch (Exception e) { throw new Exception("Could not add certificate: " + e.Message); } }
public ActionResult EditCert(int id, string title, string text, int reqNum, string logo, string inactive) { ViewBag.error = ""; if (id > 0) { Boolean inActive = false; inActive = (inactive == "on") ? true : false; // retrieve the cert with the id try { B2BDataContext db = new B2BDataContext(); B2BCertificate cert = new B2BCertificate(); cert = db.B2BCertificates.Where(x => x.id == id).FirstOrDefault<B2BCertificate>(); cert.title = title; cert.text = text; cert.requirementNum = reqNum; cert.image_path = logo; cert.inactive = inActive; db.SubmitChanges(); ViewBag.cert = cert; ViewBag.msg = "The certificate changes have been made."; } catch (Exception e) { ViewBag.error = e.Message; } } else { return RedirectToAction("Index"); } return View(); }
public ActionResult EditAnswer(int id, string text, string isCorrect, string inactive) { ViewBag.error = ""; Boolean inActive = false; inActive = (inactive == "on") ? true : false; bool isCorrectAnswer = false; if (isCorrect == "on") { isCorrectAnswer = true; } else { isCorrectAnswer = false; } if (id > 0) { // retrieve the answer with the id try { B2BDataContext db = new B2BDataContext(); B2BAnswer answer = new B2BAnswer(); answer = db.B2BAnswers.Where(x => x.id == id).FirstOrDefault<B2BAnswer>(); answer.text = text; answer.isCorrect = isCorrectAnswer; answer.inactive = inActive; db.SubmitChanges(); ViewBag.answer = answer; ViewBag.msg = "The answer has been changed."; } catch (Exception e) { ViewBag.error = e.Message; } } else { return RedirectToAction("Index"); } return View(); }
public static void addLesson(int catID, string title, string text, string pdf, bool inActive) { try { B2BDataContext db = new B2BDataContext(); B2BLesson newLesson = new B2BLesson(); newLesson.catID = catID; newLesson.title = title; newLesson.Text = text; newLesson.date_added = DateTime.Now; newLesson.date_modified = DateTime.Now; newLesson.inactive = inActive; db.B2BLessons.InsertOnSubmit(newLesson); db.SubmitChanges(); B2BResource newPDF = new B2BResource(); newPDF.file_path = pdf; newPDF.date_added = DateTime.Now; newPDF.sort = 1; newPDF.lessonID = newLesson.id; newPDF.title = title + " PDF"; newPDF.image_path = "https://www.curtmfg.com/assets/f70444af-54b2-4242-8eca-13dacd6e715c.png"; db.B2BResources.InsertOnSubmit(newPDF); db.SubmitChanges(); } catch (Exception e) { throw new Exception("Could not add Lesson: " + e.Message); } }
///////////////////== AJAX == //////////////////////////////////// public static string SetPlaqueStatus(int certID, int userID) { try { B2BDataContext db = new B2BDataContext(); B2BCompletedCert compCert = new B2BCompletedCert(); B2BUser b2bUser = getB2BUser(userID); compCert = db.B2BCompletedCerts.Where(x => x.certID == certID && x.B2BUserID == b2bUser.id).FirstOrDefault<B2BCompletedCert>(); if (compCert.hasPlaque == false) { compCert.hasPlaque = true; } else { compCert.hasPlaque = false; } db.SubmitChanges(); return ""; } catch (Exception e) { return "Error setting plaque status"; } }
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(); }
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"; } }
public static string DeleteQuestion(int id) { try { B2BDataContext db = new B2BDataContext(); B2BQuestion question = new B2BQuestion(); question = db.B2BQuestions.Where(x => x.id == id).FirstOrDefault<B2BQuestion>(); db.B2BQuestions.DeleteOnSubmit(question); db.SubmitChanges(); return ""; } catch (Exception) { return "Error while deleting"; } }
///////////////////////== Delete ==///////////////////////// public static string DeleteCert(int id) { try { B2BDataContext db = new B2BDataContext(); B2BCertificate cert = new B2BCertificate(); cert = db.B2BCertificates.Where(x => x.id == id).FirstOrDefault<B2BCertificate>(); db.B2BCertificates.DeleteOnSubmit(cert); db.SubmitChanges(); return ""; } catch (Exception e) { return "Error while deleting" + e.Message; } }
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"; } }
public static string DeleteAnswer(int id) { try { B2BDataContext db = new B2BDataContext(); B2BAnswer answer = new B2BAnswer(); answer = db.B2BAnswers.Where(x => x.id == id).FirstOrDefault<B2BAnswer>(); db.B2BAnswers.DeleteOnSubmit(answer); db.SubmitChanges(); return ""; } catch (Exception) { return "Error while deleting"; } }
public static void addVideo(int lessonID, string title, string mp4, string ogg, string webm, bool inActive) { try { // New Video B2BDataContext db = new B2BDataContext(); B2BVideo newVideo = new B2BVideo(); newVideo.title = title; newVideo.date_added = DateTime.Now; newVideo.sort = 1; newVideo.lessonID = lessonID; newVideo.inactive = inActive; db.B2BVideos.InsertOnSubmit(newVideo); db.SubmitChanges(); // New Video Sources int videoID = newVideo.id; foreach (B2BVideoType videoType in getVideoTypes()) { string type = videoType.type; B2BVideoSource newVideoSource = new B2BVideoSource(); newVideoSource.videoID = videoID; if (type == "mp4") { newVideoSource.filePath = mp4; newVideoSource.typeID = videoType.id; } else if (type == "ogg") { newVideoSource.filePath = ogg; newVideoSource.typeID = videoType.id; } else if (type == "webm") { newVideoSource.filePath = webm; newVideoSource.typeID = videoType.id; } else { continue; } db.B2BVideoSources.InsertOnSubmit(newVideoSource); db.SubmitChanges(); }// end foreach videoType } catch (Exception e) { throw new Exception("Could not add video: " + e.Message); } }
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); } }
public ActionResult EditLesson(int id, string title, string text, string pdf, string inactive) { ViewBag.error = ""; if (id > 0) { Boolean inActive = false; inActive = (inactive == "on") ? true : false; // retrieve the lesson with the id try { B2BDataContext db = new B2BDataContext(); B2BLesson lesson = new B2BLesson(); lesson = db.B2BLessons.Where(x => x.id == id).FirstOrDefault<B2BLesson>(); lesson.title = title; lesson.Text = text; lesson.inactive = inActive; db.SubmitChanges(); B2BVideo videoObj = new B2BVideo(); videoObj = db.B2BVideos.Where(x => x.lessonID == lesson.id).FirstOrDefault<B2BVideo>(); db.SubmitChanges(); B2BResource pdfObj = new B2BResource(); pdfObj = db.B2BResources.Where(x => x.lessonID.Equals(lesson.id)).FirstOrDefault<B2BResource>(); pdfObj.file_path = pdf; db.SubmitChanges(); ViewBag.lesson = lesson; ViewBag.video = videoObj; ViewBag.pdf = pdfObj; ViewBag.msg = "The Lesson changes have been made."; } catch (Exception e) { ViewBag.error = e.Message; } } else { return RedirectToAction("Index"); } return View(); }
public ActionResult EditQuestion(int id, string text, string inactive) { ViewBag.error = ""; if (id > 0) { Boolean inActive = false; inActive = (inactive == "on") ? true : false; // retrieve the question with the id try { B2BDataContext db = new B2BDataContext(); B2BQuestion question = new B2BQuestion(); question = db.B2BQuestions.Where(x => x.id == id).FirstOrDefault<B2BQuestion>(); question.text = text; question.inactive = inActive; db.SubmitChanges(); ViewBag.question = question; ViewBag.msg = "The question has been changed."; } catch (Exception e) { ViewBag.error = e.Message; } } else { return RedirectToAction("Index"); } return View(); }
public static string DeleteVideo(int id) { try { B2BDataContext db = new B2BDataContext(); B2BVideo video = new B2BVideo(); video = db.B2BVideos.Where(x => x.id == id).FirstOrDefault<B2BVideo>(); db.B2BVideos.DeleteOnSubmit(video); db.SubmitChanges(); return ""; } catch (Exception) { return "Error while deleting"; } }
public ActionResult EditVideo(int id, string title, string mp4, string ogg, string webm, string inactive) { ViewBag.error = ""; Boolean inActive = false; inActive = (inactive == "on") ? true : false; bool isCorrectAnswer = false; if (id > 0 && title != "") { // retrieve the video with the id try { B2BDataContext db = new B2BDataContext(); B2BVideo video = db.B2BVideos.Where(x => x.id == id).FirstOrDefault<B2BVideo>(); video.title = title; video.inactive = inActive; db.SubmitChanges(); if (mp4.Length > 0) { B2BVideoSource mp4videoSrc = new B2BVideoSource(); mp4videoSrc = video.B2BVideoSources.Where(x => x.VideoTypes.type == "mp4").Select(x => x).FirstOrDefault<B2BVideoSource>(); if (mp4videoSrc != null) { mp4videoSrc.filePath = mp4; db.SubmitChanges(); } else { B2BVideoSource newMp4Source = new B2BVideoSource(); newMp4Source.filePath = mp4; newMp4Source.videoID = id; B2BVideoType videoType = B2B.getVideoTypes().Where(x => x.type == "mp4").FirstOrDefault(); newMp4Source.typeID = videoType.id; db.B2BVideoSources.InsertOnSubmit(newMp4Source); db.SubmitChanges(); } } if (ogg.Length > 0) { B2BVideoSource oggvideoSrc = new B2BVideoSource(); oggvideoSrc = video.B2BVideoSources.Where(x => x.VideoTypes.type == "ogg").Select(x => x).FirstOrDefault<B2BVideoSource>(); if (oggvideoSrc != null) { oggvideoSrc.filePath = ogg; db.SubmitChanges(); } else { B2BVideoSource newoggSource = new B2BVideoSource(); newoggSource.filePath = ogg; newoggSource.videoID = id; B2BVideoType videoType = B2B.getVideoTypes().Where(x => x.type == "ogg").FirstOrDefault(); newoggSource.typeID = videoType.id; db.B2BVideoSources.InsertOnSubmit(newoggSource); db.SubmitChanges(); } } if (webm.Length > 0) { B2BVideoSource webmvideoSrc = new B2BVideoSource(); webmvideoSrc = video.B2BVideoSources.Where(x => x.VideoTypes.type == "webm").Select(x => x).FirstOrDefault<B2BVideoSource>(); if (webmvideoSrc != null) { webmvideoSrc.filePath = webm; db.SubmitChanges(); } else { B2BVideoSource newwebmSource = new B2BVideoSource(); newwebmSource.filePath = webm; newwebmSource.videoID = id; B2BVideoType videoType = B2B.getVideoTypes().Where(x => x.type == "webm").FirstOrDefault(); newwebmSource.typeID = videoType.id; db.B2BVideoSources.InsertOnSubmit(newwebmSource); db.SubmitChanges(); } } ViewBag.msg = "The video has been changed."; ViewBag.video = video; ViewBag.lesson = B2B.getLesson(video.lessonID); B2BVideoSource videoSrc = new B2BVideoSource(); videoSrc = video.B2BVideoSources.Where(x => x.VideoTypes.type == "mp4").Select(x => x).FirstOrDefault<B2BVideoSource>(); ViewBag.mp4 = videoSrc.filePath; videoSrc = video.B2BVideoSources.Where(x => x.VideoTypes.type == "ogg").Select(x => x).FirstOrDefault<B2BVideoSource>(); ViewBag.ogg = videoSrc.filePath; videoSrc = video.B2BVideoSources.Where(x => x.VideoTypes.type == "webm").Select(x => x).FirstOrDefault<B2BVideoSource>(); ViewBag.webm = videoSrc.filePath; } catch (Exception e) { ViewBag.error = e.Message; } } else { return RedirectToAction("Index"); } return View(); }
public static void addQuestion(int testID, string text, bool inActive) { try { B2BDataContext db = new B2BDataContext(); B2BQuestion newQuestion = new B2BQuestion(); newQuestion.testID = testID; newQuestion.text = text; newQuestion.date_added = DateTime.Now; newQuestion.date_modified = DateTime.Now; newQuestion.sort = 1; newQuestion.inactive = inActive; db.B2BQuestions.InsertOnSubmit(newQuestion); db.SubmitChanges(); } catch (Exception e) { throw new Exception("Could not add Question: " + e.Message); } }