Beispiel #1
0
 public FirstRoundQuestionViewModel(DateTime time, IntellectualQuestion question, int[] cost)
 {
     Answers  = question.Answers.Select(x => new { x.Id, x.Value });
     Category = question.QuestionsCategory.Name;
     Question = question.Value;
     Cost     = cost[question.Index];
     Time     = time;
 }
Beispiel #2
0
 public IntellectualQuestionViewModel(IntellectualQuestion model)
 {
     if (model != null)
     {
         Id      = model.Id;
         Value   = model.Value;
         Index   = model.Index;
         Answers = model.Answers.Select(x => new IntellectualAnswerViewModel(x)).ToList();
     }
 }
Beispiel #3
0
        public async Task <ServiceResult> EditFirstRound(int gameId, FirstRoundEditViewModel model)
        {
            var game = await GetGameByPlayerRoles(gameId, PlayerRole.Creator);

            if (!game.IsSuccess)
            {
                return(Error(game.ErrorMessage));
            }
            FirstRound firstRound = game.Data.FirstRound;

            if (firstRound == null)
            {
                firstRound           = new FirstRound();
                game.Data.FirstRound = firstRound;
            }

            //if (firstRound.QuestionCosts != null)
            //    context.IntellectualQuestionCosts.RemoveRange(firstRound.QuestionCosts);
            if (firstRound.QuestionsCategories != null)
            {
                context.QuestionsCategorys.RemoveRange(firstRound.QuestionsCategories);
            }
            await context.SaveChangesAsync();

            //firstRound.QuestionCosts = model.QuestionCosts.Select(x =>
            //{
            //    var cost = new IntellectualQuestionCost { Index = index, Value = x };
            //    index++;
            //    return cost;
            //}).ToList();

            firstRound.QuestionsCategories = model.QuestionsCategories.Select(x =>
            {
                var questionIndex = 0;
                var category      = new QuestionsCategory
                {
                    Name      = x.Name,
                    Questions = x.Questions.Select(u =>
                    {
                        var answerIndex = 0;
                        var question    = new IntellectualQuestion
                        {
                            Index   = questionIndex,
                            Value   = u.Value,
                            Answers = u.Answers.Select(t =>
                            {
                                var answer = new IntellectualAnswer {
                                    Value = t, Index = answerIndex
                                };
                                answerIndex++;
                                return(answer);
                            }).ToList()
                        };
                        questionIndex++;
                        return(question);
                    }).ToList()
                };

                return(category);
            }).ToList();

            await context.SaveChangesAsync();

            return(Success());
        }