/// <summary>
        /// Creates completed questionnaire from user answers.
        /// </summary>
        public void AddCompletedQuestionnaire(Guid questionnaireId, IEnumerable <Guid> answers)
        {
            var questionnaire          = _qRepository.FindById(questionnaireId);
            var completedQuestionnaire = new CompletedQuestionnaire()
            {
                Questionnaire = questionnaire
            };

            foreach (var question in questionnaire.Questions)
            {
                foreach (var answer in question.Answers)
                {
                    if (answers.Contains(answer.Id))
                    {
                        completedQuestionnaire.SelectedAnswers.Add(new SelectedAnswer()
                        {
                            Question = question, Answer = answer
                        });
                        ((ICollection <Guid>)answers).Remove(answer.Id);
                    }
                }
            }
            _cqRepository.Add(completedQuestionnaire);
            _cqRepository.Commit();
        }
        public ActionResult DeleteConfirmed(int id)
        {
            CompletedQuestionnaire completedquestionnaire = db.CompletedQuetionnaires.Find(id);

            db.CompletedQuetionnaires.Remove(completedquestionnaire);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        //
        // GET: /CompleteTest/Delete/5

        public ActionResult Delete(int id = 0)
        {
            CompletedQuestionnaire completedquestionnaire = db.CompletedQuetionnaires.Find(id);

            if (completedquestionnaire == null)
            {
                return(HttpNotFound());
            }
            return(View(completedquestionnaire));
        }
 public ActionResult Edit(CompletedQuestionnaire completedquestionnaire)
 {
     if (ModelState.IsValid)
     {
         db.Entry(completedquestionnaire).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(completedquestionnaire));
 }
        public ActionResult Create(CompletedQuestionnaire completedquestionnaire)
        {
            if (ModelState.IsValid)
            {
                db.CompletedQuetionnaires.Add(completedquestionnaire);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(completedquestionnaire));
        }