Exemple #1
0
 public static DateTime recordShake(long userId)
 {
     var now = DateTime.Now;
     using (var dbContext = new PlannerDbContext())
     {
         var shake = new Shake
         {
             UserId = userId,
             ShakeTime = now,
             Status = "OPEN",
         };
         dbContext.Shakes.Add(shake);
         try
         {
             dbContext.SaveChanges();
             return now;
         }
         catch (DbEntityValidationException exception)
         {
             return "0001-01-01".AsDateTime();
         }
     }
 }
Exemple #2
0
        public static void setAsPaired(long userId)
        {
            using (var dbContext = new PlannerDbContext())
            {
                dbContext.Configuration.ProxyCreationEnabled = false;
                var query = from _ in dbContext.Shakes
                            where (_.Status == "OPEN")
                            where (_.UserId != userId)
                            orderby (_.ShakeTime)
                            select _;

                var list = query.ToList();
                var toSetAsPaired = list[list.Count - 1];

                var newShake = new Shake
                {
                    Id = toSetAsPaired.Id,
                    Location = toSetAsPaired.Location,
                    UserId = userId,
                    ShakeTime = toSetAsPaired.ShakeTime,
                    Status = "PAIRED"
                };

                dbContext.Shakes.Attach(newShake);
                dbContext.Entry(newShake).State = EntityState.Modified;
                dbContext.SaveChanges();
            }
        }