public EditQuestionClosedAnswerVm GetEditQuestionVm(int id) { var question = this.Context.Questions.Find(id); QuestionClosedAnswer questionLikeQuestionClosedAnswer = (QuestionClosedAnswer)question; EditQuestionClosedAnswerVm result = this.MapModelToEditQuestionClosedAnswerVm(questionLikeQuestionClosedAnswer); return(result); }
private QuestionClosedAnswerTestVm MapQuestionClosedAnsToVm(QuestionClosedAnswer questionAsQuestionClosedAnswer, List <ClosedAnswerVm> answers) { return(new QuestionClosedAnswerTestVm() { Text = questionAsQuestionClosedAnswer.Text, NumberInTest = questionAsQuestionClosedAnswer.NumberInTest, Points = questionAsQuestionClosedAnswer.Points, AnswerVms = answers, Id = questionAsQuestionClosedAnswer.Id }); }
private QuestionClosedAnswerVm MapModelToQuestionClosedAnswer(QuestionClosedAnswer model) { var answers = this.Context.ClosedAnswers.Entities.Where(a => a.Question == model); //modelAsQClosedAnswer.Answers.AddRange(this.Context.ClosedAnswers.Entities.Where(a => a.Question.Id == model.Id)); var mappedAnswers = this.MapClosedAnswersToView(model.Answers.ToList()); QuestionClosedAnswerVm mappedAddQuestion = new QuestionClosedAnswerVm() { Id = model.Id, Text = model.Text, Points = model.Points, NumberInTest = model.NumberInTest, Subject = model.Subject, Grade = model.Grade, Author = model.Author, AnswerVms = mappedAnswers }; return(mappedAddQuestion); }
private EditQuestionClosedAnswerVm MapModelToEditQuestionClosedAnswerVm(QuestionClosedAnswer model) { var questionAsQuestionClosedAnswer = (QuestionClosedAnswer)model; IEnumerable <ClosedAnswer> answersEntity = this.Context.ClosedAnswers.Entities.Where(a => a.Question == model); questionAsQuestionClosedAnswer.Answers.AddRange(answersEntity); var mappedAnswers = this.MapClosedAnswersToView(questionAsQuestionClosedAnswer.Answers.ToList()); EditQuestionClosedAnswerVm mappedEditQuestion = new EditQuestionClosedAnswerVm() { Text = model.Text, Points = model.Points, NumberInTest = model.NumberInTest, Subject = model.Subject, Grade = model.Grade, Author = model.Author, AnswerVms = mappedAnswers }; return(mappedEditQuestion); }
public void AddQuestionClosedAnswer(AddQuestionClosedAnswerBm bind, string userId) { List <ClosedAnswer> answers = new List <ClosedAnswer>(); answers.AddRange(new List <ClosedAnswer>() { new ClosedAnswer(bind.Answer1Text, bind.Answer1IsTrue), new ClosedAnswer(bind.Answer2Text, bind.Answer2IsTrue), new ClosedAnswer(bind.Answer3Text, bind.Answer3IsTrue), new ClosedAnswer(bind.Answer4Text, bind.Answer4IsTrue), }); if (answers.Count(x => x.IsTrue) > 1) { throw new ArgumentOutOfRangeException("True answer must be only one!"); } User user = this.Context.Users.Entities.FirstOrDefault(c => c.Id == userId); QuestionClosedAnswer question = new QuestionClosedAnswer(bind.Text, bind.Points, bind.Grade, bind.Subject, bind.NumberInTest, user, answers); this.Context.ClosedAnswers.AddRange(answers); this.Context.Questions.Add(question); this.Context.SaveChanges(); }