public ActionResult AddQuestion(int?id) { int maxOrder = 0; if (cx.Questions.Where(x => x.Section.Id == id).Count() != 0) { maxOrder = cx.Questions. Where(x => x.Section.Id == id). Max(x => x.OrderNumber); } var newQuestion = new Question() { OrderNumber = maxOrder + 1, Section = cx.Sections.Find(id), Quiz = cx.Sections.Find(id).Quiz }; cx.Questions.Add(newQuestion); cx.SaveChanges(); var model = new RedactorContainerView() { Question = newQuestion, Section = newQuestion.Section, Quiz = newQuestion.Quiz }; return(PartialView("RedactorContainer", model)); }
public ActionResult QRedactor_Ajax(string value, int?id) { if (id == null) { return(HttpNotFound()); } //---------finding question by order number----- var questionNumber = Int32.Parse(value); var question = cx.Questions. Where(x => x.Section.Id == id). Single(y => y.OrderNumber == questionNumber); //------ var model = new RedactorContainerView() { Question = question, Quiz = question.Quiz, Section = question.Section }; return(PartialView("RedactorContainer", model)); }
public ActionResult ChangeQuestion(RedactorContainerView view) { var question = cx.Questions.Find(view.Question.Id); question.Obligation = view.Question.Obligation; if (view.Question.OrderNumber != question.OrderNumber) { var questions = cx.Questions. Where(x => x.Section.Id == view.Section.Id). OrderBy(y => y.OrderNumber).ToList(); if (view.Question.OrderNumber > questions.Count) { view.Question.OrderNumber = questions.Count; } questions.RemoveAt(question.OrderNumber - 1); questions.Insert(view.Question.OrderNumber - 1, question); int index = 1; foreach (var item in questions) { item.OrderNumber = index; ++index; } } question.Difficulty = view.Question.Difficulty; question.TimeLimit = view.Question.TimeLimit; if (question.Type != null) { ViewBag.Change = true; } if (view.Question.Type != question.Type) { question.Type = view.Question.Type; question.XmlValue = null; question.TypeName = null; } cx.SaveChanges(); RedactorView model = null; if (view.Question.Type != null) { model = RedactorView.GetView((QuestionType)view.Question.Type); model.Question = question; model.Quiz = cx.Quizzes.Find(view.Quiz.Id); model.Section = cx.Sections.Find(view.Section.Id); if (question.XmlValue != null) { model.Model = XmlBase.Deserialize(question.XmlObject, question.TypeName); } } return(PartialView("Redactor", model)); }