public static QuestionLookup GetQuestionById(int id) { QuestionLookup question = new QuestionLookup(); using (var db = new Context()) { question = db.Questions.Include(q => q.Category).SingleOrDefault(x => x.QuestionId == id); } return(question); }
public static void UpdateQuestion(QuestionLookup question) { using (var db = new Context()) { QuestionLookup questionRef = db.Questions.Find(question.QuestionId); if (questionRef != null) { questionRef.QuestionName = question.QuestionName; db.SaveChanges(); } } }
public static void DeleteQuestion(QuestionLookup question) { using (var db = new Context()) { QuestionLookup questionRef = db.Questions.Find(question.QuestionId); if (questionRef != null) { db.Questions.Remove(questionRef); db.SaveChanges(); } } }
public static void AddQuestion(string questionName, int categoryId) { QuestionLookup question = new QuestionLookup { QuestionName = questionName, CategoryId = categoryId }; using (var db = new Context()) { db.Questions.Add(question); db.SaveChanges(); } }