Exemplo n.º 1
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();

            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            using (var db = new PlayCode2012QuizDB())
            {
                if (db.Context.Any() == false)
                {
                    db.Context.Add(new Context { CurrentQuestionID = 1, CurrentState = 0 });

            #if DEBUG
                    db.Players.Add(new Player { Name = "jsakamoto" });
                    db.Players.Add(new Player { Name = "zecl" });

                    db.Questions.Add(new Question { Body = "Q-1", Option0 = "A-1-1", Option1 = "A-1-2", Option3 = "A-1-3", IndexOfCorrectOption = 0 });
                    db.Questions.Add(new Question { Body = "Q-2", Option0 = "A-2-1", Option1 = "A-2-2", Option3 = "A-2-3", IndexOfCorrectOption = 1 });
            #endif
                    db.SaveChanges();
                }
            }
        }
Exemplo n.º 2
0
 public ActionResult Login(string name)
 {
     FormsAuthentication.SetAuthCookie(name, createPersistentCookie: false);
     using (var db = new PlayCode2012QuizDB())
     {
         if (db.Players.Any(p => p.Name == name) == false)
         {
             db.Players.Add(new Player { Name = name });
             db.SaveChanges();
         }
     }
     return RedirectToAction("Index", "Player");
 }
Exemplo n.º 3
0
        public ActionResult ImportQuestion(FormCollection f)
        {
            #if NORMALIAN
            var client = new WebClient { Encoding = Encoding.UTF8 };
            var jsonStr = client.DownloadString(new Uri("http://codejp2012quiz.cloudapp.net/Quiz/GetList"));

            var normalianQuestions = JsonConvert.DeserializeObject<List<NormalianQuestion>>(jsonStr);

            var qs = normalianQuestions
                .Select(q => new Question
                {
                    Body = q.QuestionSummary,
                    Option0 = q.Answer1,
                    Option1 = q.Answer2,
                    Option2 = q.Answer3,
                    Option3 = q.Answer4,
                    Option4 = q.Answer5,
                    Option5 = q.Answer6,
                    Comment = q.AnswerDetail,
                    IndexOfCorrectOption = q.AnswerNo
                })
                .ToList();

            using (var db = new PlayCode2012QuizDB())
            {
                db.Database.ExecuteSqlCommand("TRUNCATE TABLE Questions");

                qs.ForEach(q => db.Questions.Add(q));

                db.SaveChanges();
            }

            #else
            var GDbUser = ConfigurationManager.AppSettings["GData.User"];
            var GDbPwd = ConfigurationManager.AppSettings["GData.Password"];

            var questions =
                new GDataDB.DatabaseClient(GDbUser, GDbPwd)
                .GetDatabase("CopyOfCode2012Quiz")
                .GetTable<GDataQuestion>("Sheet1")
                .FindAll()
                .Select(r => r.Element)
                .ToArray();

            using (var db = new PlayCode2012QuizDB())
            {
                db.Database.ExecuteSqlCommand("TRUNCATE TABLE Questions");

                var qs = questions
                    .Select(q => new Question
                    {
                        Body = q.Body,
                        Option0 = q.Option0,
                        Option1 = q.Option1,
                        Option2 = q.Option2,
                        Option3 = q.Option3,
                        Option4 = q.Option4,
                        Option5 = q.Option5,
                        Comment = q.Comment,
                        IndexOfCorrectOption = int.Parse(Regex.Match(q.IndexOfCorrectOption, @"\d+").Value) - 1,
                        Category = q.Category
                    })
                    .ToList();
                qs.ForEach(q => db.Questions.Add(q));

                db.SaveChanges();
            }
            #endif

            return View();
        }