Beispiel #1
0
 private static MultipleChoiceQuestionAnswer Copy(MultipleChoiceQuestionAnswer answer)
 {
     return(new MultipleChoiceQuestionAnswer
     {
         Value = answer.Value,
         Text = answer.Text,
     });
 }
Beispiel #2
0
        public async Task <MultipleChoiceQuestionAnswer> Edit([FromRoute] string id, [FromBody] MultipleChoiceQuestionAnswer answerposted)
        {
            var currentUserName = User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
            var user            = _apiContext.Inspectors.FirstOrDefault(elem => elem.UserAccount.UserName == currentUserName);
            var answer          = await _apiContext.MultipleChoiceQuestionAnswers.FindAsync(answerposted.Id);

            answer.ChosenOption = await _apiContext.MultipleChoiceQuestionOptions.FindAsync(answerposted.ChosenOption.Id);

            answer.Inspector = user;
            answer.Question  = await _apiContext.MultipleChoiceQuestions.FindAsync(id);

            await _apiContext.SaveChangesAsync();

            return(answerposted);
        }
Beispiel #3
0
        public async Task <MultipleChoiceQuestionAnswer> Create([FromRoute] string id, [FromBody] MultipleChoiceQuestionAnswer answer)
        {
            var currentUserName = User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
            var user            = _apiContext.Inspectors.FirstOrDefault(elem => elem.UserAccount.UserName == currentUserName);

            answer.Id        = Guid.NewGuid().ToString("N");
            answer.Inspector = user;
            answer.Question  = await _apiContext.MultipleChoiceQuestions.FindAsync(id);

            var option = answer.ChosenOption.Id;

            answer.ChosenOption = null;
            _apiContext.MultipleChoiceQuestionAnswers.Add(answer);
            answer.ChosenOption = await _apiContext.MultipleChoiceQuestionOptions.FindAsync(option);

            await _apiContext.SaveChangesAsync();

            return(answer);
        }