Example #1
0
 public static void CreateAnswer(testitprojectEntities ctx, Question q, AnswerVM ans)
 {
     ctx.Answers.Add(new Answer()
     {
         answerDescription = ans.answerDescription,
         isCorrect         = ans.isCorrect,
         Question          = q
     });
     ctx.SaveChanges();
 }
Example #2
0
        public IActionResult Answers(int id)
        {
            AnswerVM userExam = new AnswerVM();
            Exam     exam     = _examContext.Exams.Include(q => q.QuestionOne).Include(q => q.QuestiontWO).Include(q => q.QuestionThree).Include(q => q.QuestionFour).FirstOrDefault(x => x.ID == id && x.IsDeleted == false);

            userExam.AnswerOne   = exam.QuestionOne.RightAnswer;
            userExam.AnswerTwo   = exam.QuestiontWO.RightAnswer;
            userExam.AnswerThree = exam.QuestionThree.RightAnswer;
            userExam.AnswerFour  = exam.QuestionFour.RightAnswer;

            return(Json(userExam));
        }
        public AnswerVM AnswerData(int variantCount)
        {
            AnswerVM answerVM = new AnswerVM();

            Console.WriteLine("Enter answer Name");
            answerVM.Name = answerVM.Variant[variantCount] + ". " + Console.ReadLine();
            Console.WriteLine("Is it true answer?\n Y/N");
            string isTrue = Console.ReadLine().ToUpper();

            answerVM.IsTrue = (isTrue == "Y");

            return(answerVM);
        }
 public IHttpActionResult Put(int?id, [FromBody] AnswerVM answerVM)
 {
     if (id == null || answerVM == null || !answerVM.isWalid())
     {
         return(BadRequest());
     }
     try
     {
         _answerService.Change(id.GetValueOrDefault(), (Mapper.Map <AnswerDTO>(answerVM)));
     }
     catch (BILException myExc)
     {
         return(InternalServerError(myExc));
     }
     return(Ok());
 }
 public ActionResult Edit(int?id)
 {
     try
     {
         AnswerDTO answerDTO = AnswerService.Get(id);
         AnswerVM  answerVM  = Mapper.Map <AnswerVM>(answerDTO);
         return(View(answerVM));
     }
     catch (ArgumentNullException)
     {
         return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
     }
     catch (NotFoundException)
     {
         return(HttpNotFound());
     }
 }
Example #6
0
 public ActionResult <AnswersPost> CreateAnswer([FromBody] AnswerVM entry)
 {
     if (context.QuestionPosts.Any(a => a.Id == entry.QuestionPostId))
     {
         var nAnswer = new AnswersPost
         {
             AnswerContent  = entry.AnswerContent,
             QuestionPostId = entry.QuestionPostId
         };
         context.AnswerPosts.Add(nAnswer);
         context.SaveChanges();
         return(nAnswer);
     }
     else
     {
         return(BadRequest());
     }
 }
Example #7
0
        // Post: Answer
        public AnswerVM Post(AnswerVM model)
        {
            AnswerDTO dto = new AnswerDTO();

            using (ApplicationDbContext db = new ApplicationDbContext())
            {
                dto.Answar     = model.Answar;
                dto.QuestionId = model.QuestionId;
                string userId = ((System.Security.Claims.ClaimsIdentity)User.Identity).
                                FindFirst("UserId").Value;
                ApplicationUser currentUser = (new ApplicationDbContext()).Users.FirstOrDefault(x => x.Id == userId);
                dto.userId = currentUser.Id;

                db.Answers.Add(dto);
                db.SaveChanges();
            }
            return(new AnswerVM(dto));
        }
        public string GetAnswer(int Id)
        {
            Answer   results       = new Answer();
            AnswerVM returnResults = new AnswerVM();
            string   json;

            using (ApplicationDbContext data = new ApplicationDbContext())
            {
                results = data.Answers.FirstOrDefault(X => X.id == Id);
            }

            returnResults.Name        = results.Name;
            returnResults.Description = results.Description;
            returnResults.Correct     = results.Correct;

            json = JsonConvert.SerializeObject(returnResults);

            return(json);
        }
        public ActionResult DetailsQuestion(DetailsQuestionVM vm)
        {
            if (ModelState.IsValid)
            {
                AnswerVM answerToAdd = new AnswerVM();
                answerToAdd.isCorrect  = vm.newAnswer.isCorrect;
                answerToAdd.questionID = vm.question.questionID;
                answerToAdd.value      = vm.newAnswer.value;


                questionService.AddAnswer(answerToAdd);

                //vm.newAnswer.value = "";
                //vm.newAnswer.isCorrect = false;

                return(RedirectToAction("DetailsQuestion", vm.question.questionID));
            }

            return(RedirectToAction("DetailsQuestion", vm.question.questionID));
        }
        public ActionResult DeleteAnswer(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            AnswerVM answer = questionService.GetAnswer(id);

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

            questionService.DeleteAnswer(answer.answerID);

            var question = questionService.GetQuestion(answer.questionID);

            return(RedirectToAction("DetailsQuestion", new { id = question.questionID }));
        }
 public ActionResult Create([Bind(Include = "Name")] AnswerVM answerVM)
 {
     try
     {
         if (ModelState.IsValid)
         {
             AnswerDTO answerDTO = Mapper.Map <AnswerDTO>(answerVM);
             AnswerService.Add(answerDTO);
             return(RedirectToAction("Index"));
         }
         return(View());
     }
     catch (UniqueConstraintException ex)
     {
         return(Json(new
         {
             hasError = true,
             data = ex.Message
         }, JsonRequestBehavior.AllowGet));
     }
 }
Example #12
0
        public IActionResult Delete(int id)
        {
            AnswerVM answer = _answerService.GetById(id);

            return(View(answer));
        }
Example #13
0
        public AnswerVM MapAnswerToViewModel(Answer answer)
        {
            AnswerVM answerVM = _mapper.Map <AnswerVM>(answer);

            return(answerVM);
        }
Example #14
0
        public Answer MapAnswerToModel(AnswerVM answerVM)
        {
            Answer answer = _mapper.Map <Answer>(answerVM);

            return(answer);
        }
Example #15
0
 public void AddAnswer(AnswerVM answerVM)
 {
     _adminRepository.AddAnswer(MapAnswerToModel(answerVM));
 }
Example #16
0
        /// <summary>
        /// 编辑
        /// </summary>
        /// <param name="vm"></param>
        /// <returns></returns>
        public ActionResult Edit(AnswerVM vm)
        {
            vm.Answer = _AnswerService.GetById(vm.Id) ?? new Answer();

            return(View(vm));
        }