Ejemplo n.º 1
0
 public static long log(string message)
 {
     using (var dbContext = new PlannerDbContext())
     {
         var log = new Log
         {
             Message = message,
             Datetime = DateTime.Now
         };
         dbContext.Logs.Add(log);
         try
         {
             dbContext.SaveChanges();
             return log.Id;
         }
         catch (DbEntityValidationException exception)
         {
             return -1;
         }
     }
 }
Ejemplo n.º 2
0
 public static bool Add(string fileAsString, long userId)
 {
     using (var dbContext = new PlannerDbContext())
     {
         var file = new File
         {
             FileLink = fileAsString,
             UserId = userId
         };
         dbContext.Files.Add(file);
         try
         {
             dbContext.SaveChanges();
             return true;
         }
         catch (DbEntityValidationException exception)
         {
             return false;
         }
     }
 }
Ejemplo n.º 3
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();
         }
     }
 }
Ejemplo n.º 4
0
 public static long Create(string email, string password, string type, string tagline, string fullName)
 {
     using (var dbContext = new PlannerDbContext())
     {
         var user = new User
         {
             Email = email,
             Password = password,
             Type = type,
             Tagline = tagline,
             FullName = fullName
         };
         dbContext.Users.Add(user);
         try
         {
             dbContext.SaveChanges();
             return user.Id;
         }
         catch (DbEntityValidationException exception)
         {
             var s = "";
             foreach (var eve in exception.EntityValidationErrors)
             {
                 s +=
                     string.Format(
                         "Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                         eve.Entry.Entity.GetType().Name, eve.Entry.State);
                 foreach (var ve in eve.ValidationErrors)
                 {
                     s += string.Format("- Property: \"{0}\", Error: \"{1}\"",
                         ve.PropertyName, ve.ErrorMessage);
                 }
             }
             return -1;
         }
     }
 }
Ejemplo n.º 5
0
 public static bool makeConnection(long one, long two)
 {
     //setAsPaired(one);
     //setAsPaired(two);
     
     using (var dbContext = new PlannerDbContext())
     {
         var connection = new Connection
         {
             UserA = one,
             UserB = two
         };
         dbContext.Connections.Add(connection);
         try
         {
             dbContext.SaveChanges();
             return true;
         }
         catch (DbEntityValidationException exception)
         {
             return false;
         }
     }
 }
Ejemplo n.º 6
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();
            }
        }