Example #1
0
        public void VerifyEmail(string id, string email)
        {
            using (var context = new safetyquizbotContext())
            {
                var user = context.UserTable.Single(e => e.Id == id);

                if (user.Verified == "true")
                {
                    SendMessage(GenericMessage("We already have your email address.\n" +
                                               "Thanks for taking the quiz. Goodbye, and Stay Safe!", id).ToJson());
                }
                else
                {
                    context.UserTable.Attach(user);
                    user.Email    = email;
                    user.Verified = "true";


                    context.Entry(user).Property(x => x.Verified).IsModified = true;
                    context.Entry(user).Property(x => x.Email).IsModified    = true;
                    context.SaveChanges();
                    SendMessage(GenericMessage($"Your email address has been recorded", user.Id).ToJson());
                    SendMessage(
                        GenericMessage($"Thanks for taking the quiz. Goodbye, and Stay Safe!", user.Id).ToJson());
                }
            }
        }
Example #2
0
        public async Task ProfileInfoHandler(string ID)
        {
            try
            {
                Stopwatch stop = new Stopwatch();
                stop.Start();
                using (var context = new safetyquizbotContext())
                {
                    if (context.UserTable.Where(e => e.Id == ID).Select(p => p).FirstOrDefault() == null)
                    {
                        var xt = await GetPageProfileAsync(ID);

                        xt.Verified = "false";
                        context.UserTable.Add(xt);
                        context.SaveChanges();
                        Console.WriteLine("Added ProfileInfo");
                    }
                    Console.WriteLine($"Profileinfo: {stop.Elapsed.Seconds}");
                    stop.Stop();
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
Example #3
0
 public QuizState GetStateAsync(string PSID)
 {
     using (safetyquizbotContext context = new safetyquizbotContext())
     {
         var quizstate = context.QuizState.Where(e => e.Uid == PSID).Select(p => p).FirstOrDefault();
         Console.WriteLine("passed quizstate");
         return(quizstate);
     }
 }
Example #4
0
        public void FinishScorecard(string PSID)
        {
            var context = new safetyquizbotContext();

            if (context.ScoreBoard.Where(e => (e.Psid == PSID) && (e.State == Startup.BotContext.Start.ToString())).Select(p => p).LastOrDefault() != null)
            {
                var lastScore = context.ScoreBoard.Where(e => (e.Psid == PSID) && (e.State == Startup.BotContext.Start.ToString())).Select(p => p).LastOrDefault();
                lastScore.State = Startup.BotContext.Finish.ToString();
                context.SaveChanges();
                Console.WriteLine("Passed Scorecard");
            }
        }
Example #5
0
        public bool GetScore(string PSID)
        {
            var context   = new safetyquizbotContext();
            var lastScore = context.ScoreBoard.Where(e => (e.Psid == PSID) && (e.State == Startup.BotContext.Finish.ToString())).Select(p => p).LastOrDefault();

            if (lastScore.CorrectTap == Startup.quiz.Questions.Count)
            {
                Typing(PSID);
                return(true);
            }
            else
            {
                Typing(PSID);
                return(false);
            }
        }
Example #6
0
        public void CalculateInputScore(string PSID, bool correct)
        {
            var context   = new safetyquizbotContext();
            var lastScore = context.ScoreBoard.Where(e => (e.Psid == PSID) && (e.State == Startup.BotContext.Start.ToString())).Select(p => p).LastOrDefault();

            lastScore.Input++;
            if (correct)
            {
                lastScore.CorrectTap += 1;
            }
            else
            {
                lastScore.IncorrectTap += 1;
            }

            context.SaveChanges();
        }
Example #7
0
        public void PrintScore(string PSID)
        {
            var context   = new safetyquizbotContext();
            var lastScore = context.ScoreBoard.Where(e => (e.Psid == PSID) && (e.State == Startup.BotContext.Start.ToString())).Select(p => p).LastOrDefault();

            SendMessage(GenericMessage("Now, it is marking time ...", PSID).ToJson());
            if (lastScore.CorrectTap >= 2)
            {
                SendMessage(GenericMessage($"Out of {Startup.quiz.Questions.Count}, you have answered {lastScore.CorrectTap} questions correctly", PSID).ToJson());
            }
            else
            {
                SendMessage(GenericMessage($"Out of {Startup.quiz.Questions.Count}, you have answered {lastScore.CorrectTap} question correctly", PSID).ToJson());
            }
            Typing(PSID);
            FinishScorecard((PSID));
        }
Example #8
0
        public void CreateScorecard(string PSID)
        {
            var context = new safetyquizbotContext();

            context.ScoreBoard.Add(new ScoreBoard()
            {
                SessionId      = PSID + (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds,
                Timestamp      = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds,
                Psid           = PSID,
                CorrectInput   = 0,
                CorrectTap     = 0,
                IncorrectInput = 0,
                IncorrectTap   = 0,
                PartialInput   = 0,
                State          = Startup.BotContext.Start.ToString(),
                Tap            = 0,
                Input          = 0
            });
            context.SaveChanges();
            Console.WriteLine("Created Scorecard");
        }
Example #9
0
        private int InsertComments(string PSID, string comment)
        {
            try
            {
                if (comment == Startup.Force_Wrong)
                {
                    return(100);
                }
                else
                {
                    using (var context = new safetyquizbotContext())
                    {
                        context.FeedBack.Add(new FeedBack()
                        {
                            FeedbackId =
                                PSID + (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds,
                            UserId  = PSID,
                            Comment = comment
                        });
                        context.SaveChanges();
                    }

                    return(1);
                }
            }
            catch (Exception e)
            {
                if (e.InnerException != null && e.InnerException.Message.Contains("Incorrect string value"))
                {
                    return(99);
                }
                else
                {
                    return(0);
                }
            }
        }
Example #10
0
        private void EmailPre(string PSID)
        {
            var xt = new safetyquizbotContext().UserTable.Where(e => e.Id == PSID).Select(p => p).LastOrDefault();

            if (graph.GetScore(PSID))
            {
                if (xt.Verified == "false")
                {
                    graph.SendMessage(GenericMessage("Do you want to enter the lucky draw? If yes, type in your email address", PSID).ToJson());
                    graph.SendMessage(GenericMessage("If not, type no", PSID).ToJson());
                }
                else
                {
                    graph.SendMessage(GenericMessage("Thank you for taking the quiz.\nWe have your email address. " +
                                                     "So your name is in the lucky draw.", PSID).ToJson());
                    graph.SetState(PSID, -1, Startup.BotContext.Welcome.ToString());
                }
            }
            else
            {
                if (xt.Verified == "false")
                {
                    graph.SendMessage(GenericMessage("If you answer all questions correctly, " +
                                                     "you will be eligible to enter a lucky draw to win one of the three JB Hi-Fi gift cards (1x $100 & 2x $50). " +
                                                     "\nIf you’d like to retake the quiz, enter Restart", PSID).ToJson());
                    graph.SetState(PSID, -1, Startup.BotContext.Ineligible.ToString());
                }
                else
                {
                    graph.SendMessage(GenericMessage("Thank you for taking the quiz.\nYou had answered all the questions correctly before." +
                                                     " So, your name is already in the lucky draw.", PSID).ToJson());
                    graph.SendMessage(GenericMessage("If you’d like to retake the quiz, enter Restart", PSID).ToJson());
                    graph.SetState(PSID, -1, Startup.BotContext.Welcome.ToString());
                }
            }
        }
Example #11
0
 public void SetState(string PSID, int state, string chatcontext)
 {
     using (safetyquizbotContext context = new safetyquizbotContext())
     {
         if (context.QuizState.Where(e => e.Uid == PSID).Select(p => p).FirstOrDefault() == null)
         {
             context.QuizState.Add(new QuizState()
             {
                 Uid            = PSID,
                 LastState      = -1,
                 CurrentContext = chatcontext
             });
             context.SaveChanges();
         }
         else
         {
             var user = context.QuizState.Where(e => e.Uid == PSID).Select(p => p).FirstOrDefault();
             user.LastState      = state;
             user.CurrentContext = chatcontext;
             context.SaveChanges();
             Console.WriteLine("Passed context handler");
         }
     }
 }
Example #12
0
        public string GetName(string PSID)
        {
            var user = new safetyquizbotContext().UserTable.Where(e => e.Id == PSID).Select(p => p).LastOrDefault();

            return(user.FirstName + " " + user.LastName);
        }