public void AddUser(string firstName, string lastName, string login, string email, string password)
 {
     using (var context = new AlarmClockDbContext())
     {
         var resUserLogin = context.Users.FirstOrDefault(u => u.Login == login || u.Email == email);
         if (resUserLogin != null)
         {
             throw new ArgumentException("User with that login or email already exists");
         }
         context.Users.Add(new User(firstName, lastName, login, email, password));
         context.SaveChanges();
     }
 }
 public void DeleteAlarmClock(Guid alarmGuid)
 {
     using (var context = new AlarmClockDbContext())
     {
         var cl = context.AlarmClocks.FirstOrDefault(c => c.Guid == alarmGuid);
         if (cl != null)
         {
             context.AlarmClocks.Remove(cl);
         }
         else
         {
             throw new ArgumentException("Couldn't find clock in database: " + alarmGuid);
         }
         context.SaveChanges();
     }
 }
 public void AddAlarmClock(Guid userGuid, DBModels.AlarmClock clock)
 {
     using (var context = new AlarmClockDbContext())
     {
         var user = context.Users.Include(i => i.AlarmClocks)
                    .FirstOrDefault(u => u.Guid == userGuid);
         if (user != null)
         {
             user.AlarmClocks.Add(clock);
             context.SaveChanges();
         }
         else
         {
             throw new ArgumentException("Couldn't find user with that guid");
         }
     }
 }
 public void UpdateAlarmClock(Guid alarmGuid, DateTime lastTime, DateTime nextTime)
 {
     using (var context = new AlarmClockDbContext())
     {
         try
         {
             var cl = context.AlarmClocks.FirstOrDefault(c => c.Guid == alarmGuid);
             if (cl != null)
             {
                 cl.LastAlarmTime = lastTime;
                 cl.NextAlarmTime = nextTime;
                 context.SaveChanges();
             }
             else
             {
                 throw new ArgumentException("Couldn't find clock in database: ");
             }
         }
         catch (Exception e)
         {
             throw e;
         }
     }
 }