Esempio n. 1
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();
            }
        }