Exemplo n.º 1
0
        private async Task<bool> StoreAsync(AnswerModel answer)
        {
            this.db.TestAnswers.Add(answer);

            await this.db.SaveChangesAsync();
            var selectedOption = await this.db.TestOptions.FirstOrDefaultAsync(o => o.Id == answer.OptionId
                && o.QuestionId == answer.QuestionId);

            return selectedOption.IsCorrect;
        }
Exemplo n.º 2
0
        public async Task<IHttpActionResult> Post(AnswerModel answer)
        {
            if (!ModelState.IsValid)
            {
                return this.BadRequest(this.ModelState);
            }

            answer.UserId = User.Identity.Name;

            var isCorrect = await this.StoreAsync(answer);
            return this.Ok<bool>(isCorrect);
        }