Ejemplo n.º 1
0
        public int Add(QuizTaking model)
        {
            model.Id = GetNextId();
            Items.Add(model);

            return(model.Id);
        }
Ejemplo n.º 2
0
 public static QuizTakingCompleteViewModel MapFromDataModel(QuizTaking model)
 {
     return(new QuizTakingCompleteViewModel
     {
         QuizItemId = model.QuizItemId,
         ParticipantName = model.ParticipantName
     });
 }
        public int Add(QuizTaking model)
        {
            using (var context = new QuizAppEntities())
            {
                context.QuizTakings.Add(model);
                context.SaveChanges();

                return(model.Id);
            }
        }
Ejemplo n.º 4
0
 public static QuizTakingViewModel MapFromDataModel(QuizTaking model)
 {
     return(new QuizTakingViewModel
     {
         Id = model.Id,
         QuizItemId = model.QuizItemId,
         Created = model.Created,
         Ended = model.Ended,
         ParticipantName = model.ParticipantName,
         Score = model.Score
     });
 }
        public void Update(QuizTaking model)
        {
            using (var context = new QuizAppEntities())
            {
                var existingEntity = context.QuizTakings.FirstOrDefault(o => o.Id == model.Id);
                if (existingEntity == null)
                {
                    return;
                }

                context.Entry(existingEntity).CurrentValues.SetValues(model);
                context.SaveChanges();
            }
        }
Ejemplo n.º 6
0
        public ActionResult Start([Bind(Include = "QuizItemId,ParticipantName")] QuizTakingViewModel model)
        {
            if (ModelState.IsValid == false)
            {
                LoadRelationshipProperties(model);
                return(View(model));
            }

            var quizTaking = new QuizTaking
            {
                QuizItemId      = model.QuizItemId,
                Created         = DateTime.UtcNow,
                ParticipantName = model.ParticipantName
            };

            var id = _quizTakingRepository.Add(quizTaking);

            return(RedirectToAction("InProgress", new { id }));
        }
Ejemplo n.º 7
0
        public static void Seed()
        {
            var created = DateTime.UtcNow.AddDays(-1);
            var ended   = DateTime.UtcNow.AddDays(-1).AddMinutes(2);

            // Create a Pub Quiz
            var quizItem = new QuizItem
            {
                Created = created,
                Name    = "Pub Quiz"
            };

            var quizItemId = InMemoryQuizItemRepository.Instance.Add(quizItem);

            // Create Pub Quiz questions
            var quizItemQuestion1 = new QuizItemQuestion
            {
                Created                     = created,
                QuizItemId                  = quizItemId,
                Question                    = "What is the hightest mountain in Europe?",
                AnswerAlternative1          = "Mount Korab",
                IsAnswerAlternative1Correct = true,
                AnswerAlternative2          = "Kilimanjaro",
                AnswerAlternative3          = "Gaustadtoppen",
                AnswerAlternative4          = "Trysilfjellet"
            };
            var quizItemQuestion2 = new QuizItemQuestion
            {
                Created                     = created,
                QuizItemId                  = quizItemId,
                Question                    = "Which team won the Premier League in 2015/2016?",
                AnswerAlternative1          = "Liverpool",
                AnswerAlternative2          = "Manchester City",
                AnswerAlternative3          = "Leicester City",
                IsAnswerAlternative3Correct = true,
                AnswerAlternative4          = "Tottenham"
            };

            var quizItemQuestion1Id = InMemoryQuizItemQuestionRepository.Instance.Add(quizItemQuestion1);
            var quizItemQuestion2Id = InMemoryQuizItemQuestionRepository.Instance.Add(quizItemQuestion2);

            // Create a taken Pub Quiz
            var quizTaking = new QuizTaking
            {
                Created         = created,
                Ended           = ended,
                QuizItemId      = quizItemId,
                ParticipantName = "Ola Nordmann",
                Score           = 200
            };

            var quizTakingId = InMemoryQuizTakingRepository.Instance.Add(quizTaking);

            // Create answers for Pub Quiz question 1
            var quizItemQuestionAnswer1 = new QuizItemQuestionAnswer
            {
                QuizItemQuestionId  = quizItemQuestion1Id,
                QuizTakingId        = quizTakingId,
                UserSpecifiedAnswer = "Mount Korab"
            };

            InMemoryQuizItemQuestionAnswerRepository.Instance.Add(quizItemQuestionAnswer1);

            // Create answers for Pub Quiz question 2
            var quizItemQuestionAnswer2 = new QuizItemQuestionAnswer
            {
                QuizItemQuestionId  = quizItemQuestion2Id,
                QuizTakingId        = quizTakingId,
                UserSpecifiedAnswer = "Leicester City"
            };

            InMemoryQuizItemQuestionAnswerRepository.Instance.Add(quizItemQuestionAnswer2);
        }
Ejemplo n.º 8
0
        protected override void Seed(QuizAppEntities context)
        {
            var created = DateTime.UtcNow.AddDays(-1);
            var ended   = DateTime.UtcNow.AddDays(-1).AddMinutes(2);

            // Create a Pub Quiz
            var quizItem = new QuizItem
            {
                Created = created,
                Name    = "Pub Quiz"
            };

            context.QuizItems.AddOrUpdate(o => new { o.Name }, quizItem);

            // Create Pub Quiz questions
            var quizItemQuestion1 = new QuizItemQuestion
            {
                Created                     = created,
                QuizItemId                  = quizItem.Id,
                QuizItem                    = quizItem,
                Question                    = "What is the hightest mountain in Europe?",
                AnswerAlternative1          = "Mount Korab",
                IsAnswerAlternative1Correct = true,
                AnswerAlternative2          = "Kilimanjaro",
                AnswerAlternative3          = "Gaustadtoppen",
                AnswerAlternative4          = "Trysilfjellet"
            };
            var quizItemQuestion2 = new QuizItemQuestion
            {
                Created                     = created,
                QuizItemId                  = quizItem.Id,
                QuizItem                    = quizItem,
                Question                    = "Which team won the Premier League in 2015/2016?",
                AnswerAlternative1          = "Liverpool",
                AnswerAlternative2          = "Manchester City",
                AnswerAlternative3          = "Leicester City",
                IsAnswerAlternative3Correct = true,
                AnswerAlternative4          = "Tottenham"
            };

            context.QuizItemQuestions.AddOrUpdate(o => new { o.Question }, quizItemQuestion1);
            context.QuizItemQuestions.AddOrUpdate(o => new { o.Question }, quizItemQuestion2);

            // Create a taken Pub Quiz
            var quizTaking = new QuizTaking
            {
                Created         = created,
                Ended           = ended,
                QuizItemId      = quizItem.Id,
                QuizItem        = quizItem,
                ParticipantName = "Ola Nordmann",
                Score           = 200
            };

            context.QuizTakings.AddOrUpdate(o => new { o.ParticipantName }, quizTaking);

            // Create answers for Pub Quiz question 1
            var quizItemQuestionAnswer1 = new QuizItemQuestionAnswer
            {
                QuizItemQuestionId  = quizItemQuestion1.Id,
                QuizItemQuestion    = quizItemQuestion1,
                QuizTakingId        = quizTaking.Id,
                QuizTaking          = quizTaking,
                UserSpecifiedAnswer = "Mount Korab"
            };

            context.QuizItemQuestionAnswers.AddOrUpdate(o => new { o.UserSpecifiedAnswer }, quizItemQuestionAnswer1);

            // Create answers for Pub Quiz question 2
            var quizItemQuestionAnswer2 = new QuizItemQuestionAnswer
            {
                QuizItemQuestionId  = quizItemQuestion2.Id,
                QuizItemQuestion    = quizItemQuestion2,
                QuizTakingId        = quizTaking.Id,
                QuizTaking          = quizTaking,
                UserSpecifiedAnswer = "Leicester City"
            };

            context.QuizItemQuestionAnswers.AddOrUpdate(o => new { o.UserSpecifiedAnswer }, quizItemQuestionAnswer2);
        }
Ejemplo n.º 9
0
        public void Update(QuizTaking model)
        {
            Delete(model.Id);

            Items.Add(model);
        }