public void Save(DeviceClass deviceClass)
        {
            if (deviceClass == null)
                throw new ArgumentNullException("deviceClass");

            using (var context = new DeviceHiveContext())
            {
                context.DeviceClasses.Add(deviceClass);
                if (deviceClass.ID > 0)
                {
                    context.Entry(deviceClass).State = EntityState.Modified;

                    foreach (var equipment in deviceClass.Equipment.Where(e => e.ID > 0))
                    {
                        context.Entry(equipment).State = EntityState.Modified;
                    }
                    foreach (var equipment in context.Equipments.Where(e => e.DeviceClassID == deviceClass.ID))
                    {
                        if (context.Entry(equipment).State == EntityState.Unchanged)
                            context.Equipments.Remove(equipment);
                    }
                }
                
                context.SaveChanges();
            }
        }
        public void Save(AccessKey accessKey)
        {
            if (accessKey == null)
            {
                throw new ArgumentNullException("accessKey");
            }

            using (var context = new DeviceHiveContext())
            {
                context.AccessKeys.Add(accessKey);
                if (accessKey.ID > 0)
                {
                    context.Entry(accessKey).State = EntityState.Modified;

                    foreach (var permission in accessKey.Permissions.Where(e => e.ID > 0))
                    {
                        context.Entry(permission).State = EntityState.Modified;
                    }
                    foreach (var permission in context.AccessKeyPermissions.Where(e => e.AccessKeyID == accessKey.ID))
                    {
                        if (context.Entry(permission).State == EntityState.Unchanged)
                        {
                            context.AccessKeyPermissions.Remove(permission);
                        }
                    }
                }

                context.SaveChanges();
            }
        }
        public void Save(Device device)
        {
            if (device == null)
            {
                throw new ArgumentNullException("device");
            }
            if (string.IsNullOrEmpty(device.GUID))
            {
                throw new ArgumentException("Device.GUID must have a valid value!", "device.GUID");
            }

            using (var context = new DeviceHiveContext())
            {
                if (device.Network != null)
                {
                    context.Networks.Attach(device.Network);
                }
                context.DeviceClasses.Attach(device.DeviceClass);
                context.Devices.Add(device);
                if (device.ID > 0)
                {
                    context.Entry(device).State = EntityState.Modified;
                }
                context.SaveChanges();
            }
        }
        public void Save(DeviceClass deviceClass)
        {
            if (deviceClass == null)
            {
                throw new ArgumentNullException("deviceClass");
            }

            using (var context = new DeviceHiveContext())
            {
                context.DeviceClasses.Add(deviceClass);
                if (deviceClass.ID > 0)
                {
                    context.Entry(deviceClass).State = EntityState.Modified;

                    foreach (var equipment in deviceClass.Equipment.Where(e => e.ID > 0))
                    {
                        context.Entry(equipment).State = EntityState.Modified;
                    }
                    foreach (var equipment in context.Equipments.Where(e => e.DeviceClassID == deviceClass.ID))
                    {
                        if (context.Entry(equipment).State == EntityState.Unchanged)
                        {
                            context.Equipments.Remove(equipment);
                        }
                    }
                }

                context.SaveChanges();
            }
        }
        public void Save(AccessKey accessKey)
        {
            if (accessKey == null)
                throw new ArgumentNullException("accessKey");

            using (var context = new DeviceHiveContext())
            {
                context.AccessKeys.Add(accessKey);
                if (accessKey.ID > 0)
                {
                    context.Entry(accessKey).State = EntityState.Modified;
                    
                    foreach (var permission in accessKey.Permissions.Where(e => e.ID > 0))
                    {
                        context.Entry(permission).State = EntityState.Modified;
                    }
                    foreach (var permission in context.AccessKeyPermissions.Where(e => e.AccessKeyID == accessKey.ID))
                    {
                        if (context.Entry(permission).State == EntityState.Unchanged)
                            context.AccessKeyPermissions.Remove(permission);
                    }
                }
                
                context.SaveChanges();
            }
        }
Exemple #6
0
 public void Delete(int id)
 {
     using (var context = new DeviceHiveContext())
     {
         var notification = context.DeviceNotifications.Find(id);
         if (notification != null)
         {
             context.DeviceNotifications.Remove(notification);
             context.SaveChanges();
         }
     }
 }
Exemple #7
0
 public void Delete(int id)
 {
     using (var context = new DeviceHiveContext())
     {
         var command = context.DeviceCommands.Find(id);
         if (command != null)
         {
             context.DeviceCommands.Remove(command);
             context.SaveChanges();
         }
     }
 }
Exemple #8
0
 public void Delete(int id)
 {
     using (var context = new DeviceHiveContext())
     {
         var network = context.Networks.Find(id);
         if (network != null)
         {
             context.Networks.Remove(network);
             context.SaveChanges();
         }
     }
 }
 public void Delete(int id)
 {
     using (var context = new DeviceHiveContext())
     {
         var command = context.DeviceCommands.Find(id);
         if (command != null)
         {
             context.DeviceCommands.Remove(command);
             context.SaveChanges();
         }
     }
 }
 public void Delete(int id)
 {
     using (var context = new DeviceHiveContext())
     {
         var network = context.Networks.Find(id);
         if (network != null)
         {
             context.Networks.Remove(network);
             context.SaveChanges();
         }
     }
 }
 public void Delete(int id)
 {
     using (var context = new DeviceHiveContext())
     {
         var equipment = context.Equipments.Find(id);
         if (equipment != null)
         {
             context.Equipments.Remove(equipment);
             context.SaveChanges();
         }
     }
 }
Exemple #12
0
 public void Delete(int id)
 {
     using (var context = new DeviceHiveContext())
     {
         var user = context.Users.Find(id);
         if (user != null)
         {
             context.Users.Remove(user);
             context.SaveChanges();
         }
     }
 }
 public void Delete(int id)
 {
     using (var context = new DeviceHiveContext())
     {
         var user = context.Users.Find(id);
         if (user != null)
         {
             context.Users.Remove(user);
             context.SaveChanges();
         }
     }
 }
 public void Delete(int id)
 {
     using (var context = new DeviceHiveContext())
     {
         var deviceClass = context.DeviceClasses.Find(id);
         if (deviceClass != null)
         {
             context.DeviceClasses.Remove(deviceClass);
             context.SaveChanges();
         }
     }
 }
Exemple #15
0
 public void Delete(int id)
 {
     using (var context = new DeviceHiveContext())
     {
         var oauthClient = context.OAuthClients.Find(id);
         if (oauthClient != null)
         {
             context.OAuthClients.Remove(oauthClient);
             context.SaveChanges();
         }
     }
 }
 public void Delete(int id)
 {
     using (var context = new DeviceHiveContext())
     {
         var deviceClass = context.DeviceClasses.Find(id);
         if (deviceClass != null)
         {
             context.DeviceClasses.Remove(deviceClass);
             context.SaveChanges();
         }
     }
 }
 public void Delete(int id)
 {
     using (var context = new DeviceHiveContext())
     {
         var accessKey = context.AccessKeys.Find(id);
         if (accessKey != null)
         {
             context.AccessKeys.Remove(accessKey);
             context.SaveChanges();
         }
     }
 }
 public void Delete(int id)
 {
     using (var context = new DeviceHiveContext())
     {
         var oauthClient = context.OAuthClients.Find(id);
         if (oauthClient != null)
         {
             context.OAuthClients.Remove(oauthClient);
             context.SaveChanges();
         }
     }
 }
 public void Delete(int id)
 {
     using (var context = new DeviceHiveContext())
     {
         var notification = context.DeviceNotifications.Find(id);
         if (notification != null)
         {
             context.DeviceNotifications.Remove(notification);
             context.SaveChanges();
         }
     }
 }
Exemple #20
0
 public void Delete(int id)
 {
     using (var context = new DeviceHiveContext())
     {
         var equipment = context.Equipments.Find(id);
         if (equipment != null)
         {
             context.Equipments.Remove(equipment);
             context.SaveChanges();
         }
     }
 }
        public void Save(User user)
        {
            if (user == null)
                throw new ArgumentNullException("user");

            using (var context = new DeviceHiveContext())
            {
                context.Users.Add(user);
                if (user.ID > 0)
                {
                    context.Entry(user).State = EntityState.Modified;
                }
                context.SaveChanges();
            }
        }
        public void Save(DeviceClass deviceClass)
        {
            if (deviceClass == null)
                throw new ArgumentNullException("deviceClass");

            using (var context = new DeviceHiveContext())
            {
                context.DeviceClasses.Add(deviceClass);
                if (deviceClass.ID > 0)
                {
                    context.Entry(deviceClass).State = EntityState.Modified;
                }
                context.SaveChanges();
            }
        }
        public void Save(OAuthClient oauthClient)
        {
            if (oauthClient == null)
                throw new ArgumentNullException("oauthClient");

            using (var context = new DeviceHiveContext())
            {
                context.OAuthClients.Add(oauthClient);
                if (oauthClient.ID > 0)
                {
                    context.Entry(oauthClient).State = EntityState.Modified;
                }
                context.SaveChanges();
            }
        }
        public void Save(Network network)
        {
            if (network == null)
                throw new ArgumentNullException("network");

            using (var context = new DeviceHiveContext())
            {
                context.Networks.Add(network);
                if (network.ID > 0)
                {
                    context.Entry(network).State = EntityState.Modified;
                }
                context.SaveChanges();
            }
        }
        public void Save(DeviceCommand command)
        {
            if (command == null)
                throw new ArgumentNullException("command");

            using (var context = new DeviceHiveContext())
            {
                context.Devices.Attach(command.Device);
                context.DeviceCommands.Add(command);
                if (command.ID > 0)
                {
                    context.Entry(command).State = EntityState.Modified;
                }
                context.SaveChanges();
            }
        }
        public void Save(DeviceNotification notification)
        {
            if (notification == null)
                throw new ArgumentNullException("notification");

            using (var context = new DeviceHiveContext())
            {
                context.Devices.Attach(notification.Device);
                context.DeviceNotifications.Add(notification);
                if (notification.ID > 0)
                {
                    context.Entry(notification).State = EntityState.Modified;
                }
                context.SaveChanges();
            }
        }
        public void Save(Equipment equipment)
        {
            if (equipment == null)
                throw new ArgumentNullException("equipment");

            using (var context = new DeviceHiveContext())
            {
                context.DeviceClasses.Attach(equipment.DeviceClass);
                context.Equipments.Add(equipment);
                if (equipment.ID > 0)
                {
                    context.Entry(equipment).State = EntityState.Modified;
                }
                context.SaveChanges();
            }
        }
Exemple #28
0
        public void Save(OAuthClient oauthClient)
        {
            if (oauthClient == null)
            {
                throw new ArgumentNullException("oauthClient");
            }

            using (var context = new DeviceHiveContext())
            {
                context.OAuthClients.Add(oauthClient);
                if (oauthClient.ID > 0)
                {
                    context.Entry(oauthClient).State = EntityState.Modified;
                }
                context.SaveChanges();
            }
        }
Exemple #29
0
        public void Save(User user)
        {
            if (user == null)
            {
                throw new ArgumentNullException("user");
            }

            using (var context = new DeviceHiveContext())
            {
                context.Users.Add(user);
                if (user.ID > 0)
                {
                    context.Entry(user).State = EntityState.Modified;
                }
                context.SaveChanges();
            }
        }
Exemple #30
0
        public void Save(Network network)
        {
            if (network == null)
            {
                throw new ArgumentNullException("network");
            }

            using (var context = new DeviceHiveContext())
            {
                context.Networks.Add(network);
                if (network.ID > 0)
                {
                    context.Entry(network).State = EntityState.Modified;
                }
                context.SaveChanges();
            }
        }
        public void Save(DeviceClass deviceClass)
        {
            if (deviceClass == null)
            {
                throw new ArgumentNullException("deviceClass");
            }

            using (var context = new DeviceHiveContext())
            {
                context.DeviceClasses.Add(deviceClass);
                if (deviceClass.ID > 0)
                {
                    context.Entry(deviceClass).State = EntityState.Modified;
                }
                context.SaveChanges();
            }
        }
        public void Save(UserNetwork userNetwork)
        {
            if (userNetwork == null)
                throw new ArgumentNullException("userNetwork");

            using (var context = new DeviceHiveContext())
            {
                context.Users.Attach(userNetwork.User);
                context.Networks.Attach(userNetwork.Network);
                context.UserNetworks.Add(userNetwork);
                if (userNetwork.ID > 0)
                {
                    context.Entry(userNetwork).State = EntityState.Modified;
                }
                context.SaveChanges();
            }
        }
Exemple #33
0
        public void Save(DeviceCommand command)
        {
            if (command == null)
            {
                throw new ArgumentNullException("command");
            }

            using (var context = new DeviceHiveContext())
            {
                context.Devices.Attach(command.Device);
                context.DeviceCommands.Add(command);
                if (command.ID > 0)
                {
                    context.Entry(command).State = EntityState.Modified;
                }
                context.SaveChanges();
            }
        }
Exemple #34
0
        public void Save(DeviceNotification notification)
        {
            if (notification == null)
            {
                throw new ArgumentNullException("notification");
            }

            using (var context = new DeviceHiveContext())
            {
                context.Devices.Attach(notification.Device);
                context.DeviceNotifications.Add(notification);
                if (notification.ID > 0)
                {
                    context.Entry(notification).State = EntityState.Modified;
                }
                context.SaveChanges();
            }
        }
Exemple #35
0
        public void Save(Equipment equipment)
        {
            if (equipment == null)
            {
                throw new ArgumentNullException("equipment");
            }

            using (var context = new DeviceHiveContext())
            {
                context.DeviceClasses.Attach(equipment.DeviceClass);
                context.Equipments.Add(equipment);
                if (equipment.ID > 0)
                {
                    context.Entry(equipment).State = EntityState.Modified;
                }
                context.SaveChanges();
            }
        }
Exemple #36
0
        public void Save(UserNetwork userNetwork)
        {
            if (userNetwork == null)
            {
                throw new ArgumentNullException("userNetwork");
            }

            using (var context = new DeviceHiveContext())
            {
                context.Users.Attach(userNetwork.User);
                context.Networks.Attach(userNetwork.Network);
                context.UserNetworks.Add(userNetwork);
                if (userNetwork.ID > 0)
                {
                    context.Entry(userNetwork).State = EntityState.Modified;
                }
                context.SaveChanges();
            }
        }
        public void Save(Device device)
        {
            if (device == null)
                throw new ArgumentNullException("device");
            if (device.GUID == Guid.Empty)
                throw new ArgumentException("Device.ID must have a valid value!", "device.ID");

            using (var context = new DeviceHiveContext())
            {
                if (device.Network != null)
                {
                    context.Networks.Attach(device.Network);
                }
                context.DeviceClasses.Attach(device.DeviceClass);
                context.Devices.Add(device);
                if (device.ID > 0)
                {
                    context.Entry(device).State = EntityState.Modified;
                }
                context.SaveChanges();
            }
        }
 public void Delete(int id)
 {
     using (var context = new DeviceHiveContext())
     {
         var accessKey = context.AccessKeys.Find(id);
         if (accessKey != null)
         {
             context.AccessKeys.Remove(accessKey);
             context.SaveChanges();
         }
     }
 }