Beispiel #1
0
        public IHttpActionResult PutQuiz(Guid id, Quiz quiz)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != quiz.Id)
            {
                return(BadRequest());
            }

            db.Entry(quiz).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!QuizExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public PartialViewResult SendTag(Guid id, string tagName)
        {
            var question = db.Questions.SingleOrDefault(x => x.Id == id);

            if (question != null)
            {
                // Gibt es den Tag schon bei dieser Frage?
                var tagExists = question.Tags.Any(x => x.Name.ToLower().Equals(tagName.ToLower()));

                if (!tagExists)
                {
                    // gibt es den Tag generell schon?
                    var tag = db.QuestionTags.FirstOrDefault(x => x.Name.ToLower().Equals(tagName.ToLower()));

                    if (tag == null)
                    {
                        tag      = new QuestionTag();
                        tag.Name = tagName;
                        db.QuestionTags.Add(tag);
                        db.SaveChanges();
                    }

                    question.Tags.Add(tag);
                    // braucht es nur einmal, oder? testen
                    db.SaveChanges();
                }
            }

            return(PartialView("_TagList", question));
        }
Beispiel #3
0
        public ActionResult Create([Bind(Include = "Id,Name,Description")] Data.Quiz quiz)
        {
            if (ModelState.IsValid)
            {
                quiz.Id = Guid.NewGuid();
                db.Quizzes.Add(quiz);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(quiz));
        }
Beispiel #4
0
        public ActionResult Create([Bind(Include = "Id,Name,Description")] TrainingPlan trainingPlan)
        {
            if (ModelState.IsValid)
            {
                trainingPlan.Id = Guid.NewGuid();
                db.TrainingPlans.Add(trainingPlan);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(trainingPlan));
        }
Beispiel #5
0
        public ActionResult Create([Bind(Include = "Id,Userid,TimeStamp")] TrainingGroupSubscription trainingGroupSubscription)
        {
            if (ModelState.IsValid)
            {
                trainingGroupSubscription.Id = Guid.NewGuid();
                db.TrainingGroupSubscriptions.Add(trainingGroupSubscription);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(trainingGroupSubscription));
        }
        public ActionResult Create([Bind(Include = "Id,ShortName,Name,Reihenfolge")] QuestionCategory questionCategory)
        {
            if (ModelState.IsValid)
            {
                questionCategory.Id = Guid.NewGuid();
                db.Categories.Add(questionCategory);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(questionCategory));
        }
Beispiel #7
0
        public ActionResult Create(Question question)
        {
            if (ModelState.IsValid)
            {
                question.Id = Guid.NewGuid();
                db.Questions.Add(question);
                db.SaveChanges();


                return(RedirectToAction("Details", new { id = question.Id }));
            }

            return(View(question));
        }
Beispiel #8
0
        internal QuestLog WriteLog(Question question, QuestionAnswer answer, User user)
        {
            // Existiert für diese Frage bereits ein Logeintrag?
            var log = db.QuestLogs.SingleOrDefault(l => l.User.Id == user.Id &&
                                                   l.Question.Id == question.Id);

            if (log != null)
            {
                // den Log aktualisieren
                log.Answer = answer;
                log.ViewCount++;
            }
            else
            {
                // einen neuen Logeintrag erstellen
                log = new QuestLog
                {
                    Question  = question,
                    Answer    = answer,
                    User      = user,
                    FirstView = DateTime.Now,
                    ViewCount = 1
                };
                db.QuestLogs.Add(log);
            }

            // Datenbank aktualisieren
            db.SaveChanges();

            return(log);
        }
Beispiel #9
0
        public ActionResult Personal_Data(User user)
        {
            // Der Benutzer soll in der Datenbank gespeichert werden
            // 1. Verbindung zur Datenbank
            var db = new QuestDbContext();

            if (ModelState.IsValid)
            {
                // das ist ein neuer User => gib ihm eine Id
                user.Id = Guid.NewGuid();

                user.Created = DateTime.Now;

                // den neuen Benutzer zur Datenbank hinzufügen
                db.Users.Add(user);

                // Änderungen jetzt wirklich in der Datenbank speichern
                db.SaveChanges();

                // jetzt das Quiz starten
                return(RedirectToAction("Index", "Quiz", new { id = user.Id }));
            }


            // wenn es nicht geklappt hat, dann hat der Benutzer wohl was falsches eingegeben
            // zeige den Dialog noch einmal
            return(View());
        }
Beispiel #10
0
        public ActionResult Create(TrainingSession trainingSession)
        {
            if (ModelState.IsValid)
            {
                var plan = db.TrainingPlans.SingleOrDefault(x => x.Id == trainingSession.TrainingPlan.Id);

                if (plan != null)
                {
                    trainingSession.Id           = Guid.NewGuid();
                    trainingSession.TrainingPlan = plan;
                    db.TrainingSessions.Add(trainingSession);
                    db.SaveChanges();
                    return(RedirectToAction("Index", new { id = plan.Id }));
                }
            }

            return(View(trainingSession));
        }
Beispiel #11
0
        public ActionResult Create(QuizQuestion quizQuestion)
        {
            if (ModelState.IsValid)
            {
                var section  = db.QuizSections.SingleOrDefault(x => x.Id == quizQuestion.Section.Id);
                var question = db.Questions.SingleOrDefault(x => x.Id == quizQuestion.Question.Id);

                if (section != null && question != null)
                {
                    quizQuestion.Id       = Guid.NewGuid();
                    quizQuestion.Section  = section;
                    quizQuestion.Question = question;
                    db.QuizQuestions.Add(quizQuestion);
                    db.SaveChanges();
                    return(RedirectToAction("Index", new { id = section.Id }));
                }
            }

            return(View(quizQuestion));
        }
        public ActionResult Create(TrainingExercise trainingExercise)
        {
            if (ModelState.IsValid)
            {
                var session = db.TrainingSessions.SingleOrDefault(x => x.Id == trainingExercise.TrainingSession.Id);
                var quiz    = db.Quizzes.SingleOrDefault(x => x.Id == trainingExercise.Quiz.Id);

                if (session != null)
                {
                    trainingExercise.Id = Guid.NewGuid();
                    trainingExercise.TrainingSession = session;
                    trainingExercise.Quiz            = quiz;
                    db.TrainingExercises.Add(trainingExercise);
                    db.SaveChanges();
                    return(RedirectToAction("Index", new { id = session.Id }));
                }
            }

            return(View(trainingExercise));
        }
        public ActionResult Create(QuizSection quizSection)
        {
            if (ModelState.IsValid)
            {
                var quiz = db.Quizzes.SingleOrDefault(x => x.Id == quizSection.Quiz.Id);

                if (quiz != null)
                {
                    quizSection.Id   = Guid.NewGuid();
                    quizSection.Quiz = quiz;
                    db.QuizSections.Add(quizSection);
                    db.SaveChanges();
                    return(RedirectToAction("Index", new { id = quiz.Id }));
                }

                return(RedirectToAction("Index"));
            }

            return(View(quizSection));
        }
Beispiel #14
0
        public static void EnsurePopulated(IApplicationBuilder app)
        {
            QuestDbContext context = (QuestDbContext)app.ApplicationServices.GetService(typeof(QuestDbContext));

            context.Database.Migrate();

            if (!context.Companies.Any())
            {
                CompanyEntity[] companies = new CompanyEntity[]
                {
                    new CompanyEntity {
                        Name = "FearCorporation", Logo = "fear.jpg"
                    },
                    new CompanyEntity {
                        Name = "BlackBox", Logo = "box.jpg"
                    },
                };
                context.AddRange(companies);

                QuestEntity[] quests = new QuestEntity[]
                {
                    new QuestEntity {
                        Name        = "Escape from house", Company = companies[0], Address = "Dubno", Email = "*****@*****.**",
                        Description = "Very scary", FearLevel = 5, HardLevel = 5, MaxPlayers = 10, MinAge = 21, MinPlayers = 3, Phone = "066-85-26-406",
                        Raiting     = 8.5, WalkTime = TimeSpan.FromMinutes(180)
                    },
                    new QuestEntity {
                        Name        = "Find predmets in house", Company = companies[1], Address = "Rivne", Email = "*****@*****.**",
                        Description = "Find predmets", FearLevel = 1, HardLevel = 3, MaxPlayers = 5, MinAge = 14, MinPlayers = 1, Phone = "095-32-21-109",
                        Raiting     = 9.2, WalkTime = TimeSpan.FromMinutes(160)
                    },
                };
                context.AddRange(quests);

                ImageEntity[] images = new ImageEntity[]
                {
                    new ImageEntity {
                        Name = "Img1", Path = "1.jpg", Quest = quests[0]
                    },
                    new ImageEntity {
                        Name = "Img2", Path = "2.jpg", Quest = quests[0]
                    },
                    new ImageEntity {
                        Name = "Img3", Path = "3.jpg", Quest = quests[1]
                    },
                    new ImageEntity {
                        Name = "Img4", Path = "4.jpg", Quest = quests[1]
                    },
                };
                context.AddRange(images);
                context.SaveChanges();
            }
        }
Beispiel #15
0
        public Data.QuizGame CreateSingleUserGame(string userId, Guid quizId)
        {
            var quiz = _quizDb.Quizzes.FirstOrDefault(x => x.Id == quizId);

            if (quiz == null)
            {
                return(null);
            }

            var level = new GameLevel
            {
                Quiz = quiz
            };

            var player = new GamePlayer
            {
                UserId      = userId,
                IsInitiator = true
            };


            var game = new QuizGame
            {
                CreatedAt = DateTime.Now,
                Levels    = new List <GameLevel>
                {
                    level
                },
                Players = new List <GamePlayer>
                {
                    player
                }
            };

            try
            {
                //quizDb.GameLevels.Add(level);
                //quizDb.GamePlayers.Add(player);
                _quizDb.QuizGames.Add(game);
                _quizDb.SaveChanges();

                return(game);
            }
            catch (Exception)
            {
                return(null);
            }
        }
Beispiel #16
0
        public IHttpActionResult GetLogAnswer(Guid?gameId, Guid?playerId, Guid?answerId)
        {
            var QuizDb = new QuestDbContext();

            var result = new QuizGameAnswerResult();

            if (gameId.HasValue && playerId.HasValue && answerId.HasValue)
            {
                var answer = QuizDb.Answers.SingleOrDefault(x => x.Id == answerId.Value);
                var game   = QuizDb.QuizGames.SingleOrDefault(x => x.Id == gameId.Value);
                var player = QuizDb.GamePlayers.SingleOrDefault(x => x.Id == playerId.Value);

                // Die Antwort

                if (answer != null && game != null && player != null)
                {
                    var log = new GameLog();
                    log.Answer      = answer;
                    log.Game        = game;
                    log.Player      = player;
                    log.LogDateTime = DateTime.Now;

                    QuizDb.GameLogs.Add(log);
                    QuizDb.SaveChanges();

                    // Update
                    var statService = new StatisticsService(QuizDb);
                    statService.NotifyUpdates();


                    result.QuizId    = game.Levels.First().Quiz.Id;
                    result.AnswerId  = answer.Id;
                    result.IsCorrect = answer.IsCorrect;
                    if (answer.IsCorrect)
                    {
                        result.Score = 1;
                    }

                    result.Message = "OK";
                }
                else
                {
                    var sb = new StringBuilder();
                    if (game == null)
                    {
                        sb.Append("Spiel fehlt");
                    }
                    if (player == null)
                    {
                        sb.Append("Spieler fehlt");
                    }
                    if (answer == null)
                    {
                        sb.Append("Antwort fehlt");
                    }
                    result.Message = sb.ToString();
                }
            }
            else
            {
                result.Message = "Falsche Parameter";
            }

            return(Ok(result));
        }