Exemple #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());
                }
            }
        }
Exemple #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);
            }
        }
Exemple #3
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");
            }
        }
Exemple #4
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");
         }
     }
 }
Exemple #5
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();
        }
Exemple #6
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");
        }
Exemple #7
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);
                }
            }
        }