Пример #1
0
        private async void AddAnswer(int QuestionId)
        {
            var answer = await SweetAlertMessage.InputDialog(type : "textarea", PlaceholderText : "Type your survey answer here....");

            if (!string.IsNullOrEmpty(answer))
            {
                var percentage = await SweetAlertMessage.RiskWeight();

                var confirm = await SweetAlertMessage.ConfirmDialogAsync(Text : "Add this answe to the question.");

                if (confirm != null)
                {
                    var _answer = await AnswerRepository.AddAnswer(new Answer
                    {
                        QuestionId = QuestionId,
                        IsActive   = true,
                        Percentage = double.Parse(percentage),
                        UserAnswer = answer,
                        AnswerType = AnswerType.No
                    });

                    if (_answer != null)
                    {
                        var _updatedQuestion = Survey.Questions.FirstOrDefault(p => p.QuestionId == QuestionId);
                        _updatedQuestion.Answers.Add(_answer);
                        StateHasChanged();
                        await SweetAlertMessage.SuccessMessage();
                    }
                    else
                    {
                        await SweetAlertMessage.ErrorMessage();
                    }
                }
            }
        }
Пример #2
0
        public IActionResult CreateAnswer([FromBody] AnswerViewModel answerVm)
        {
            Answer answer = new Answer
            {
                Text = answerVm.Text
            };

            Answer newAnswer = answerRepository.AddAnswer(answer);

            if (newAnswer == null)
            {
                return(BadRequest("Answer couldn't be created"));
            }
            AnswerViewModel newAnswerVm = entityToVmMapper.Map(answer);

            return(Ok(newAnswerVm));
        }
Пример #3
0
        public ActionResult AddAnswer(CreateAnswerRequest createRequest)
        {
            var newAnswer = _answerRepository.AddAnswer(createRequest.AnswerText, createRequest.StudentId, createRequest.QuestionId, createRequest.QuestionText, createRequest.AnswerDate);

            return(Created($"/api/student/{newAnswer.Id}", newAnswer));
        }
Пример #4
0
 public void AddAnswer(Answer answer)
 {
     _answerRepository.AddAnswer(answer);
     LocalAppData.Instance.Answers.Add(answer);
 }