private List <QuizQuestionDto> MapJsonToQuizQuestions(JToken jArray) { List <QuizQuestionDto> questionDtoList = new List <QuizQuestionDto>(); foreach (var token in jArray) { var questionDto = new QuizQuestionDto(); var categoryString = token.Value <string>("category"); var typeString = token.Value <string>("type"); var difficultyString = token.Value <string>("difficulty"); var wrongAnswers = (token["incorrect_answers"] as JArray).ToObject <List <string> >(); questionDto.Question = HttpUtility.HtmlDecode(token.Value <string>("question")); questionDto.CorrectAnswer = HttpUtility.HtmlDecode(token.Value <string>("correct_answer")); questionDto.IncorrectAnswers = wrongAnswers.Select(str => HttpUtility.HtmlDecode(str)).ToList(); questionDto.Category = EnumExtensionMethods.GetEnumValueFromDescription <Categories>(categoryString); questionDto.Type = EnumExtensionMethods.GetEnumValueFromDescription <QuestionTypes>(typeString); questionDto.Difficulty = EnumExtensionMethods.GetEnumValueFromDescription <Difficulties>(difficultyString); questionDtoList.Add(questionDto); } return(questionDtoList); }
public async Task<IHttpActionResult> PostQuestion() { var entity = new QuizQuestion(); Db.QuizQuestions.Add(entity); await Db.SaveChangesAsync(); var dto = new QuizQuestionDto { Id = entity.Id }; return CreatedAtRoute("DefaultApi", new { id = dto.Id }, dto); }
public async Task <IHttpActionResult> PostQuestion() { var entity = new QuizQuestion(); Db.QuizQuestions.Add(entity); await Db.SaveChangesAsync(); var dto = new QuizQuestionDto { Id = entity.Id }; return(CreatedAtRoute("DefaultApi", new { id = dto.Id }, dto)); }