Пример #1
0
 public static bool UserExistsInDB(User user)
 {
     using (var context = new AlarmDBContext())
     {
         return(context.Users.Any(u => (u.Login == user.Login) || (u.Email == user.Email)));
     }
 }
Пример #2
0
 public static IEnumerable <Alarm> GetAlarms(Guid guid)
 {
     using (var context = new AlarmDBContext())
     {
         return(context.Alarms.Where(r => r.UserGuid == guid).ToList());
     }
 }
Пример #3
0
 public static void SaveAlarm(Alarm alarm)
 {
     using (var context = new AlarmDBContext())
     {
         context.Entry(alarm).State = EntityState.Modified;
         context.SaveChanges();
     }
 }
Пример #4
0
 public static void AddAlarm(Alarm alarm)
 {
     using (var context = new AlarmDBContext())
     {
         context.Alarms.Add(alarm);
         context.SaveChanges();
     }
 }
Пример #5
0
 public static void AddUser(User user)
 {
     using (var context = new AlarmDBContext())
     {
         context.Users.Add(user);
         context.SaveChanges();
     }
 }
Пример #6
0
 public static void DeleteAlarm(Alarm alarm)
 {
     using (var context = new AlarmDBContext())
     {
         alarm.deleteDBValues();
         context.Alarms.Attach(alarm);
         context.Alarms.Remove(alarm);
         context.SaveChanges();
     }
 }
Пример #7
0
 public static void UpdateAlarms()
 {
     using (var context = new AlarmDBContext())
     {
         foreach (Alarm al in context.Alarms)
         {
             al.BeginTime = al.CountDate(al.Hour, al.Minutes);
         }
         context.SaveChanges();
     }
 }
Пример #8
0
 public static void EndAlarm(Alarm alarm, DateTime end)
 {
     using (var context = new AlarmDBContext())
     {
         Alarm al = context.Alarms.Where(u => u.Guid == alarm.Guid).First();
         if (al != null)
         {
             al.EndTime = end;
         }
         context.SaveChanges();
     }
 }
Пример #9
0
 public static void UpdateAlarm(Alarm alarm, int h, int m)
 {
     using (var context = new AlarmDBContext())
     {
         if (context.Alarms.Any(u => u.Hour == h && u.Minutes == m && u.Guid != alarm.Guid))
         {
             throw new Exception("This alarm is already exists!");
         }
         Alarm al = context.Alarms.Where(u => u.Guid == alarm.Guid).First();
         al.Hour    = h;
         al.Minutes = m;
         context.SaveChanges();
     }
 }
Пример #10
0
        public static User UserByGuid(Guid guid)
        {
            using (var context = new AlarmDBContext())

                return(context.Users.Include(us => us.Alarms).FirstOrDefault(us => us.Guid == guid));
        }
Пример #11
0
        public static User UserByLogin(string login)
        {
            using (var context = new AlarmDBContext())

                return(context.Users.Include(us => us.Alarms).FirstOrDefault(us => us.Login == login));
        }