private QuestionAnwer GetInsatnciatedAnswerForQuestion(IEnumerable <Model.Questionnaire.QuestionAnwer> answers, Question qc, Func <int> questionIdSelector)
        {
            Model.Questionnaire.QuestionAnwer givenAnswer = answers.FirstOrDefault(a => a.QuestionId == questionIdSelector());
            PossibleAnswer templateAnswer = qc.PossivbleAnswers.FirstOrDefault(pa => givenAnswer != null && Math.Abs((pa.Value + 1) - (givenAnswer.Answer + 1)) < 0.01);

            QuestionAnwer instanciatedAnswer;

            if (templateAnswer != null)
            {
                Debug.Assert(givenAnswer != null, "givenAnswer != null");
                instanciatedAnswer = new QuestionAnwer
                {
                    Description = templateAnswer.Description,
                    Answer      = templateAnswer.Value
                                  //    Color = _questionnaireCalculationAlgorithm.GetSingleCategoryScoreColor(givenAnswer.Answer)
                };
            }
            else
            {
                instanciatedAnswer = new QuestionAnwer {
                    Description = "-"
                };
            }
            return(instanciatedAnswer);
        }
        public PossibleAnswer Update(PossibleAnswer answer)
        {
            this.possibleAnswers.Update(answer);
            this.possibleAnswers.SaveChanges();

            return answer;
        }
        public void Delete(int id)
        {
            PossibleAnswer possibleanswer = db.PossibleAnswers.Single(p => p.id == id);

            db.PossibleAnswers.DeleteObject(possibleanswer);
            db.SaveChanges();
        }
        //
        // GET: /PossibleAnswers/Edit/5

        public ActionResult Edit(int id)
        {
            PossibleAnswer possibleanswer = db.PossibleAnswers.Single(p => p.id == id);

            ViewBag.PollId = new SelectList(db.Polls, "id", "Title", possibleanswer.PollId);
            return(PartialView(possibleanswer));
        }
Esempio n. 5
0
        public override string GetAnswer()
        {
            List <int> millionPrimes = Primality.GetPrimeListWithMaxValue(1000000);

            PossibleAnswer bestAnswerSoFar = GetBestAnswerForStartSlot(millionPrimes, 0);

            int totalSlotsAvail = millionPrimes.Count;

            for (int i = 1; i < totalSlotsAvail; i++)
            {
                int relevantPrime = millionPrimes[i];
                int playspace     = 1000000 - bestAnswerSoFar.finalSum;
                if (relevantPrime * bestAnswerSoFar.numberOfPrimes * 2 > playspace)
                {
                    return(bestAnswerSoFar.ToString());
                }
                if (relevantPrime * bestAnswerSoFar.numberOfPrimes > 1000000)
                {
                    return(bestAnswerSoFar.ToString());
                }
                PossibleAnswer bestAnswerForSlot = GetBestAnswerForStartSlot(millionPrimes, i);
                if (bestAnswerForSlot.numberOfPrimes > bestAnswerSoFar.numberOfPrimes)
                {
                    bestAnswerSoFar = bestAnswerForSlot;
                }
            }

            return(millionPrimes.Count.ToString());
        }
        public PossibleAnswer Add(PossibleAnswer answer)
        {
            this.possibleAnswers.Add(answer);
            this.possibleAnswers.SaveChanges();

            return answer;
        }
        protected virtual QuestionAnwer GetSpesificQuestionAnswer(Question qc)
        {
            PossibleAnswer res = qc.PossivbleAnswers.FirstOrDefault(c => Math.Abs(c.Value - qc.QuestionAnwer.Answer) < 0.01);

            return(new QuestionAnwer
            {
                Answer = qc.QuestionAnwer.Answer,
                Description = res == null ? "-" : res.Description,
                //  Color = QuestionnaireCalculationAlgorithm.GetSingleCategoryScoreColor(qc.QuestionAnwer.Answer)
            });
        }
        private EditAnswerViewModel Map(PossibleAnswer entity)
        {
            var result = new EditAnswerViewModel
            {
                AnswerId = entity.Id,
                Text     = entity.Answer,
                Correct  = entity.Correct
            };

            return(result);
        }
Esempio n. 9
0
        public static DAL.DAO.PossibleAnswer MapEntityToDal(PossibleAnswer arg)
        {
            var returned = new DAL.DAO.PossibleAnswer()
            {
                Text      = arg.Text,
                Id        = arg.Id,
                IsCorrect = arg.IsCorrect
            };

            return(returned);
        }
Esempio n. 10
0
        public static PossibleAnswer MapDalToEntity(DAL.DAO.PossibleAnswer arg)
        {
            var returned = new PossibleAnswer()
            {
                Text      = arg.Text,
                Id        = arg.Id,
                IsCorrect = arg.IsCorrect
            };

            return(returned);
        }
        public ActionResult DeleteConfirmed(int id)
        {
            PossibleAnswer pos_ans = db.PossibleAnswers.Find(id);
            int            TestID  = pos_ans.Question.Test.Id_testu;

            db.PossibleAnswers.Remove(pos_ans);
            db.SaveChanges();

            TempData["msg"]    = "Usunięto możliwą odpowiedź do pytania w teście poprawnie!";
            TempData["option"] = "success";
            return(RedirectToAction("Details", "Tests", new { id = TestID }));
        }
        public ActionResult Create(PossibleAnswer possibleanswer)
        {
            if (ModelState.IsValid)
            {
                db.PossibleAnswers.AddObject(possibleanswer);
                db.SaveChanges();
                return(PartialView("GridData", new PossibleAnswer[] { possibleanswer }));
            }

            ViewBag.PollId = new SelectList(db.Polls, "id", "Title", possibleanswer.PollId);
            return(PartialView("Edit", possibleanswer));
        }
        // GET: PossibleAnswers/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            PossibleAnswer pos_ans = db.PossibleAnswers.Find(id);

            if (pos_ans == null)
            {
                return(HttpNotFound());
            }

            if (pos_ans.Question.Test.Status == "Open")
            {
                TempData["msg"]    = "Nie można edytowac możliwej odpowiedzi do pytania w teście, który jest otwarty do wypełniania!";
                TempData["option"] = "warning";
                return(RedirectToAction("Details", "Tests", new { id = pos_ans.Question.Test.Id_testu }));
            }

            EditPossibleAnswerViewModels answer = new EditPossibleAnswerViewModels();

            answer.PosAnsID  = pos_ans.Id_posans;
            answer.Content   = pos_ans.Content;
            answer.isCorrect = pos_ans.isCorrect;
            answer.TestID    = pos_ans.Question.Test.Id_testu;

            var temp = pos_ans.Question.PossibleAnswers.Where(p => p.isCorrect == "True")
                       .Count();

            if (pos_ans.isCorrect == "False" && temp != 0)
            {
                ViewBag.Options = new List <SelectListItem> {
                    new SelectListItem {
                        Text = "Incorrect", Value = "False"
                    }
                };
            }
            else
            {
                ViewBag.Options = new List <SelectListItem> {
                    new SelectListItem {
                        Text = "Incorrect", Value = "False"
                    },
                    new SelectListItem {
                        Text = "Correct", Value = "True", Selected = true
                    }
                };
            }

            return(PartialView("_Edit", answer));
        }
        private QuestionAnwer GetSpesificQuestionAnswer(Question qc)
        {
            PossibleAnswer res =
                qc.PossivbleAnswers.FirstOrDefault(c => Math.Abs(c.Value - qc.QuestionAnwer.Answer) < 0.01);

            return(new QuestionAnwer
            {
                Answer = qc.QuestionAnwer.Answer,
                Description = res == null ? "-" : res.Description,
                Color = GetSingleCategoryScoreColor(qc.QuestionAnwer.Answer)
            });
        }
Esempio n. 15
0
        public void AddAnswerToQuestion(Guid questionId, PossibleAnswer answer)
        {
            var question = GetQuestion(questionId);

            if (question != null)
            {
                if (answer.Id == null)
                {
                    answer.Id = Guid.NewGuid();
                }
                question.PossibleAnswers.Add(answer);
            }
        }
        public ActionResult Edit(PossibleAnswer possibleanswer)
        {
            if (ModelState.IsValid)
            {
                db.PossibleAnswers.Attach(possibleanswer);
                db.ObjectStateManager.ChangeObjectState(possibleanswer, EntityState.Modified);
                db.SaveChanges();
                return(PartialView("GridData", new PossibleAnswer[] { possibleanswer }));
            }

            ViewBag.PollId = new SelectList(db.Polls, "id", "Title", possibleanswer.PollId);
            return(PartialView(possibleanswer));
        }
        public ActionResult Edit(EditPossibleAnswerViewModels answer)
        {
            if (ModelState.IsValid)
            {
                PossibleAnswer pos_ans = db.PossibleAnswers.Find(answer.PosAnsID);
                pos_ans.Content   = answer.Content;
                pos_ans.isCorrect = answer.isCorrect;

                db.Entry(pos_ans).State = EntityState.Modified;
                db.SaveChanges();

                TempData["msg"]    = "Edytowano możliwą odpowiedź do pytania w teście poprawnie!";
                TempData["option"] = "success";
                return(RedirectToAction("Details", "Tests", new { id = answer.TestID }));
            }
            return(PartialView("_Edit", answer));
        }
        public ActionResult Create(CreatePossibleAnswerViewModels pos_ans)
        {
            if (ModelState.IsValid)
            {
                Question question        = db.Questions.Single(p => p.Id_question == pos_ans.QuestionID);
                var      possible_answer = new PossibleAnswer();
                possible_answer.Content   = pos_ans.Content;
                possible_answer.isCorrect = pos_ans.isCorrect;
                possible_answer.Question  = question;

                db.PossibleAnswers.Add(possible_answer);
                db.SaveChanges();

                TempData["msg"]    = "Utworzono możliwą odpowiedź do pytania w teście poprawnie!";
                TempData["option"] = "success";
                return(RedirectToAction("Details", "Tests", new { id = pos_ans.TestID }));
            }

            return(PartialView("_Create"));
        }
Esempio n. 19
0
        private PossibleAnswer GetBestAnswerForStartSlot(List <int> millionPrimes, int slot)
        {
            PossibleAnswer bestAnswerSoFar = new PossibleAnswer(0, 0, 0);

            int totalSlotsAvail = millionPrimes.Count;
            int startPrime      = millionPrimes[slot];
            int runningSum      = 0;
            int currentPrimeNum;
            int currentSlot = slot;

            while (currentSlot < totalSlotsAvail && runningSum < 1000000)
            {
                currentPrimeNum = millionPrimes[currentSlot];
                runningSum     += currentPrimeNum;
                if (millionPrimes.Contains(runningSum))
                {
                    bestAnswerSoFar = new PossibleAnswer(startPrime, currentSlot - slot + 1, runningSum);
                }
                currentSlot++;
            }
            return(bestAnswerSoFar);
        }
        // GET: PossibleAnswers/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            PossibleAnswer pos_ans = db.PossibleAnswers.Find(id);

            if (pos_ans == null)
            {
                return(HttpNotFound());
            }

            if (pos_ans.Question.Test.Status == "Open")
            {
                TempData["msg"]    = "Nie można usunąć możliwej odpowiedzi do pytania w teście, który jest otwarty do wypełniania!";
                TempData["option"] = "warning";
                return(RedirectToAction("Details", "Tests", new { id = pos_ans.Question.Test.Id_testu }));
            }

            return(PartialView("_Delete", pos_ans));
        }
Esempio n. 21
0
 public void DeleteAnswer(PossibleAnswer answer)
 {
     _context.PossibleAnswers.Remove(answer);
 }
        //
        // GET: /Default5/RowData/5

        public ActionResult RowData(int id)
        {
            PossibleAnswer possibleanswer = db.PossibleAnswers.Single(p => p.id == id);

            return(PartialView("GridData", new PossibleAnswer[] { possibleanswer }));
        }