Esempio n. 1
0
        public static void EnsureCreated(this User user, PostMortemContext context)
        {
            var existingUser = context
                               .Users
                               .SingleOrDefault(x => x.CookieId == user.CookieId);

            if (existingUser == null)
            {
                context.Users.Add(new User()
                {
                    CookieId        = user.CookieId,
                    CreatedDateTime = DateTime.UtcNow,
                    GameMode        = user.GameMode
                });

                context.SaveChanges();
            }

            var dbUser = context
                         .Users
                         .Include(u => u.Objectives)
                         .Single(x => x.CookieId == user.CookieId);

            user = dbUser;
        }
Esempio n. 2
0
        public static void Save(this User user, PostMortemContext context)
        {
            var dbUser = context.Users.Single(x => x.CookieId == user.CookieId);

            dbUser.GameMode       = user.GameMode;
            dbUser.UsedDevCommand = user.UsedDevCommand;
            dbUser.Facts          = user.Facts;
            dbUser.Objectives     = user.Objectives;

            // Only save the first win time
            if (dbUser.WinDateTime == null)
            {
                dbUser.WinDateTime = user.WinDateTime;
            }

            context.SaveChanges();
        }
Esempio n. 3
0
        public PartialViewResult OnPostSurveyModalPartial(Survey survey)
        {
            if (ModelState.IsValid)
            {
                var user = _context
                           .Users
                           .Include(u => u.Survey)
                           .SingleOrDefault(u => u.CookieId == survey.User.CookieId);

                if (user != null && user.Survey == null)
                {
                    user.Survey = survey;
                    _context.SaveChanges();
                }
            }

            return(new PartialViewResult()
            {
                ViewName = "_SurveyModalPartial",
                ViewData = new ViewDataDictionary <Survey>(ViewData, survey)
            });
        }
        private void LogMessage(PostMortemContext context, string botName, string userCookieId, TranscriptMessageDirection direction, string message)
        {
            try
            {
                var bot  = context.Bots.Single(x => x.Name == botName);
                var user = context.Users.Single(x => x.CookieId == new Guid(userCookieId));

                context.Transcripts.Add(new Transcript()
                {
                    DateTime  = DateTime.UtcNow,
                    Bot       = bot,
                    User      = user,
                    Direction = direction,
                    Message   = message
                });

                context.SaveChanges();
            }
            catch
            {
                //
            }
        }