public RedactorView SaveXmlQuestion(RedactorView view) { var question = cx.Questions.Find(view.Question.Id); question.Text = view.Question.Text; question.Value = view.Question.Value; question.TypeName = view.Model.GetType().Name; question.XmlObject = XmlBase.SerializeAbstract(view.Model); cx.SaveChanges(); view.Question = question; view.Quiz = question.Quiz; view.Section = question.Section; return(view); }
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)); }