private static bool DeleteLecture(SettingAjaxParam ajaxParam) { using (var db = new ApplicationDbContext()) { try { var lecture = db.Lectures.Find(ajaxParam.Id); var sublectures = db.SubLectures.Where(x => x.LectureId == lecture.Id); if (sublectures.Any()) { var questions = db.Questions.Where(x => sublectures.Any(y => y.Id == x.SubLectureId)); if (questions.Any()) { db.Questions.RemoveRange(questions); } db.SubLectures.RemoveRange(db.SubLectures.Where(x => x.LectureId == lecture.Id)); } db.Lectures.Remove(lecture); db.SaveChanges(); } catch { return(false); } } return(true); }
private static SubLecture AddSubLecture(SettingAjaxParam ajaxParam) { var showOrder = 1; if (new ApplicationDbContext().SubLectures.Any()) { showOrder = new ApplicationDbContext().SubLectures.Max(x => x.ShowOrder) + 1; } var subLecture = new SubLecture { LectureId = ajaxParam.ParentId, SubLectureName = ajaxParam.Text, ShowOrder = showOrder, StartDateTime = DateTime.Now, EndDateTime = DateTime.Now, Role = HogwartsSettingUtility.GetSetting(HogwartsSettingUtility.NowDisplayRole) }; using (var db = new ApplicationDbContext()) { try { db.SubLectures.Add(subLecture); db.SaveChanges(); } catch { return(null); } } return(subLecture); }
private static bool DeleteQuestion(SettingAjaxParam ajaxParam) { using (var db = new ApplicationDbContext()) { try { var question = db.Questions.Find(ajaxParam.Id); db.Questions.Remove(question); db.SaveChanges(); } catch { return(false); } } return(true); }
private static bool EditSubLecture(SettingAjaxParam ajaxParam) { using (var db = new ApplicationDbContext()) { try { var subLecture = db.SubLectures.Find(ajaxParam.Id); subLecture.SubLectureName = ajaxParam.Text; db.Entry(subLecture).State = EntityState.Modified; db.SaveChanges(); } catch { return(false); } } return(true); }
public static JsonResult DeleteTreeObject(SettingAjaxParam ajaxParam) { var ajaxResult = new AjaxResult(); if (ajaxParam.NodeCategoryCD == 1) { ajaxResult.ResultData = new { Data = DeleteLecture(ajaxParam), NodeCategoryCD = 1, ajaxParam.Id }; } else if (ajaxParam.NodeCategoryCD == 2) { ajaxResult.ResultData = new { Data = DeleteSubLecture(ajaxParam), NodeCategoryCD = 2, ajaxParam.Id }; } else if (ajaxParam.NodeCategoryCD == 3) { ajaxResult.ResultData = new { Data = DeleteQuestion(ajaxParam), NodeCategoryCD = 3, ajaxParam.Id }; } else { ajaxResult.Message = "追加失敗。とりあえずF5更新やな"; ajaxResult.ResultData = null; } if (ajaxResult.ResultData != null) { ajaxResult.Result = true; } return(ajaxResult.GetJsonRsult()); }
private static bool EditQuestion(SettingAjaxParam ajaxParam) { using (var db = new ApplicationDbContext()) { try { var question = db.Questions.Find(ajaxParam.Id); question.QuestionName = ajaxParam.Text; question.Difficulty = ajaxParam.Difficulty; question.EstimateTime = ajaxParam.EstimateTime; db.Entry(question).State = EntityState.Modified; db.SaveChanges(); } catch { return(false); } } return(true); }
private static Question AddQuestion(SettingAjaxParam ajaxParam) { var questionNO = 1; if (new ApplicationDbContext().Questions.Any()) { questionNO = new ApplicationDbContext().Questions.Max(x => x.QuestionNO) + 1; } var showOrder = 0; if (new ApplicationDbContext().Questions.Any()) { showOrder = new ApplicationDbContext().Questions.Max(x => x.ShowOrder) + 1; } var question = new Question { SubLectureId = ajaxParam.ParentId, QuestionNO = questionNO, QuestionName = ajaxParam.Text, ShowOrder = showOrder, Difficulty = 1, EstimateTime = 5, Role = HogwartsSettingUtility.GetSetting(HogwartsSettingUtility.NowDisplayRole) }; using (var db = new ApplicationDbContext()) { try { db.Questions.Add(question); db.SaveChanges(); } catch { return(null); } } return(question); }