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(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(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;
                }
                context.SaveChanges();
            }
        }
示例#7
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();
            }
        }
        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();
            }
        }
示例#13
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();
            }
        }
示例#14
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();
            }
        }
        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();
            }
        }
示例#17
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();
            }
        }
示例#18
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();
            }
        }
示例#19
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();
            }
        }
示例#20
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();
            }
        }
示例#21
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();
            }
        }
示例#22
0
        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();
            }
        }