public static AnswerViewModel ToMvcAnswers(this AnswersDTO answers) { return(new AnswerViewModel() { Id = answers.Id, //Question = ToMvcQuestion(answers.Question), QuestionId = answers.QuestionId, Text = answers.Text }); }
public static Answers ToAnswers(this AnswersDTO answers) { return(new Answers() { Id = answers.Id, //Question = ToQuestion(answers.Question), QuestionId = answers.QuestionId, Text = answers.Text }); }
public async Task Update(AnswersDTO item) { var answer = await db.Answers.FindAsync(item.Id); if (answer != null) { answer.Answer = item.Answer; db.Entry(answer).State = Microsoft.EntityFrameworkCore.EntityState.Modified; await db.SaveChangesAsync(); } }
public async Task Add(AnswersDTO item) { var answer = new Answers { Id = item.Id, Answer = item.Answer }; db.Answers.Add(answer); await db.SaveChangesAsync(); }
public async Task <AnswersDTO> EditAnswers(int Id, AnswersDTO user) { var answer = await _context.Answers.Where(x => x.Id == Id).FirstOrDefaultAsync(); answer.UserId = user.UserId; answer.OptionId = user.OptionId; await _context.SaveChangesAsync(); return(new AnswersDTO(answer)); }
public async Task <bool> CreateAnswers(AnswersDTO answers) { var answer = new Answers { UserId = answers.UserId, OptionId = answers.OptionId }; _context.Answers.Add(answer); await _context.SaveChangesAsync(); return(true); }
/// <summary> /// This method is used to get the next question for the frontend. /// </summary> /// <param name="input">Answers by the users that contain which symptoms they have and which they don't have.</param> /// <returns>Object, which is either a string or a disease. /// A Disease is returned if only 1 Disease if left after evaluating input.</returns> public object GetNextQuestion(AnswersDTO input) { IEnumerable <DiseaseDTO> diseases = _diseasesService.AllWithSymptoms(); if (diseases.Count() == 0 || diseases == null || input.positive == null || input.negative == null) { return(null); } /* First .Where statement checks if a given disease contains all of the inputs that the user * has said that he/she has. * Second .Where statement checks if a given disease doesnt contain any of the input.negative that * the user has said that he/she doesnt have * Intersect gets the common parts of two lists. If there are any then that Disease will be dismissed! * Then we order it by Sympotms count. We want the lower count diseases to be infront for faster searching */ IEnumerable <DiseaseDTO> InputEvaluated = diseases .Where(x => ContainsAllItems(x.symptoms, input.positive)) .Where(x => !x.symptoms.Intersect(input.negative).Any()) .OrderBy(x => x.symptoms.Count()); // This returns an anonymous object back, which is used by front-end to detect final answer. if (InputEvaluated.Count() == 1) { return(new { InputEvaluated.FirstOrDefault().name }); } // Here we take the first and second diseases symptoms, find the differences and output them // This is done so that with each question at-least one disease would be eliminated (not always though) IEnumerable <string> symptomList = InputEvaluated .ElementAt(1) .symptoms .Except(InputEvaluated.FirstOrDefault().symptoms); // Return the next question. This is checked against what has already been asked to make sure we dont ask same question twice. foreach (var item in symptomList) { if (!input.positive.Contains(item) && !input.negative.Contains(item)) { return(item); } } return(null); }
public async Task <IActionResult> AddOrUpdate(AnswersDTO item) { if (ModelState.IsValid) { if (item.Id > 0) { await _repo.Update(item); } else { await _repo.Add(item); } return(PartialView("_Answers", await _repo.GetList())); } return(Content("Wypełnij wymagane pole")); }
public IActionResult GetNextQuestion([FromBody] AnswersDTO input) { return(Ok(_symptomService.GetNextQuestion(input))); }
public async Task <IActionResult> EditAnswer([FromRoute] int id, [FromBody] AnswersDTO request) { var response = await _service.EditAnswers(id, request); return(Ok(response)); }
public async Task <IActionResult> CreateAnswers([FromBody] AnswersDTO request) { var response = await _service.CreateAnswers(request); return(Ok(response)); }
public void CreateNewAnswer(AnswersDTO newAnswer) { Database.Answers.Create(newAnswer.ToAnswers()); Database.Save(); }