public List <Network> GetAll() { using (var context = new DeviceHiveContext()) { return(context.Networks.ToList()); } }
public List<User> GetAll(UserFilter filter = null) { using (var context = new DeviceHiveContext()) { return context.Users.Filter(filter).ToList(); } }
public List<OAuthClient> GetAll(OAuthClientFilter filter = null) { using (var context = new DeviceHiveContext()) { return context.OAuthClients.Filter(filter).ToList(); } }
public List <DeviceClass> GetAll() { using (var context = new DeviceHiveContext()) { return(context.DeviceClasses.ToList()); } }
public List <Network> GetAll(NetworkFilter filter = null) { using (var context = new DeviceHiveContext()) { return(context.Networks.Filter(filter).ToList()); } }
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 List<Network> GetAll() { using (var context = new DeviceHiveContext()) { return context.Networks.ToList(); } }
public Network Get(int id) { using (var context = new DeviceHiveContext()) { return context.Networks.Find(id); } }
public Network Get(int id) { using (var context = new DeviceHiveContext()) { return(context.Networks.Find(id)); } }
public DateTime GetCurrentTimestamp() { using (var context = new DeviceHiveContext()) { return(context.Database.SqlQuery <DateTime>("select sysutcdatetime()").First()); } }
public User Get(int id) { using (var context = new DeviceHiveContext()) { return(context.Users.Find(id)); } }
public DeviceNotification Get(int id) { using (var context = new DeviceHiveContext()) { return(context.DeviceNotifications.Find(id)); } }
public OAuthClient Get(int id) { using (var context = new DeviceHiveContext()) { return(context.OAuthClients.Find(id)); } }
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 OAuthClient Get(int id) { using (var context = new DeviceHiveContext()) { return context.OAuthClients.Find(id); } }
public DeviceEquipment Get(int id) { using (var context = new DeviceHiveContext()) { return(context.DeviceEquipments.Find(id)); } }
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 DeviceEquipment GetByDeviceAndCode(int deviceId, string code) { using (var context = new DeviceHiveContext()) { return(context.DeviceEquipments.FirstOrDefault(e => e.Device.ID == deviceId && e.Code == code)); } }
public List<User> GetAll() { using (var context = new DeviceHiveContext()) { return context.Users.ToList(); } }
public List<DeviceEquipment> GetByDevice(int deviceId) { using (var context = new DeviceHiveContext()) { return context.DeviceEquipments.Where(e => e.Device.ID == deviceId).ToList(); } }
public List <User> GetAll() { using (var context = new DeviceHiveContext()) { return(context.Users.ToList()); } }
public List <OAuthClient> GetAll(OAuthClientFilter filter = null) { using (var context = new DeviceHiveContext()) { return(context.OAuthClients.Filter(filter).ToList()); } }
public List <User> GetAll(UserFilter filter = null) { using (var context = new DeviceHiveContext()) { return(context.Users.Filter(filter).ToList()); } }
public List<DeviceClass> GetAll() { using (var context = new DeviceHiveContext()) { return context.DeviceClasses.ToList(); } }
public User Get(int id) { using (var context = new DeviceHiveContext()) { return context.Users.Find(id); } }
public DeviceEquipment Get(int id) { using (var context = new DeviceHiveContext()) { return context.DeviceEquipments.Find(id); } }
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 DeviceNotification Get(int id) { using (var context = new DeviceHiveContext()) { return context.DeviceNotifications.Find(id); } }
public DateTime GetCurrentTimestamp() { using (var context = new DeviceHiveContext()) { return context.Database.SqlQuery<DateTime>("select sysutcdatetime()").First(); } }
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 List<Network> GetAll(NetworkFilter filter = null) { using (var context = new DeviceHiveContext()) { return context.Networks.Filter(filter).ToList(); } }
public DeviceClass Get(int id) { using (var context = new DeviceHiveContext()) { return(context.DeviceClasses.Find(id)); } }
public DeviceClass Get(int id) { using (var context = new DeviceHiveContext()) { return context.DeviceClasses.Find(id); } }
public List <DeviceEquipment> GetByDevice(int deviceId) { using (var context = new DeviceHiveContext()) { return(context.DeviceEquipments.Where(e => e.Device.ID == deviceId).ToList()); } }
public DeviceEquipment GetByDeviceAndCode(int deviceId, string code) { using (var context = new DeviceHiveContext()) { return context.DeviceEquipments.FirstOrDefault(e => e.Device.ID == deviceId && e.Code == code); } }
public void Cleanup(DateTime timestamp) { using (var context = new DeviceHiveContext()) { context.Database.ExecuteSqlCommand("delete from [AccessKey] where [Type] = @Type and [ExpirationDate] < @Timestamp", new SqlParameter("Type", (int)AccessKeyType.Session), new SqlParameter("Timestamp", timestamp)); } }
public void Cleanup(DateTime timestamp) { using (var context = new DeviceHiveContext()) { context.Database.CommandTimeout = 300; context.Database.ExecuteSqlCommand("delete from [DeviceNotification] where [Timestamp] < @Timestamp", new SqlParameter("Timestamp", timestamp)); } }
public List <DeviceNotification> GetByDevice(int deviceId, DeviceNotificationFilter filter = null) { using (var context = new DeviceHiveContext()) { var query = context.DeviceNotifications.Where(e => e.Device.ID == deviceId); return(query.Filter(filter, FilterByGridInterval(filter == null ? null : filter.GridInterval)).ToList()); } }
public List <DeviceCommand> GetByDevice(int deviceId, DeviceCommandFilter filter = null) { using (var context = new DeviceHiveContext()) { var query = context.DeviceCommands.Where(e => e.Device.ID == deviceId); return(query.Filter(filter).ToList()); } }
public List<DeviceNotification> GetByDevice(int deviceId, DeviceNotificationFilter filter = null) { using (var context = new DeviceHiveContext()) { var query = context.DeviceNotifications.Where(e => e.Device.ID == deviceId); return query.Filter(filter, FilterByGridInterval(filter == null ? null : filter.GridInterval)).ToList(); } }
public List <Network> GetByUser(int userId) { using (var context = new DeviceHiveContext()) { return(context.Networks.Where(n => context.UserNetworks .Where(un => un.UserID == userId).Select(un => un.NetworkID).Contains(n.ID)).ToList()); } }
public List<DeviceCommand> GetByDevice(int deviceId, DeviceCommandFilter filter = null) { using (var context = new DeviceHiveContext()) { var query = context.DeviceCommands.Where(e => e.Device.ID == deviceId); return query.Filter(filter).ToList(); } }
public List<Network> GetByUser(int userId) { using (var context = new DeviceHiveContext()) { return context.Networks.Where(n => context.UserNetworks .Where(un => un.UserID == userId).Select(un => un.NetworkID).Contains(n.ID)).ToList(); } }
public AccessKey Get(int id) { using (var context = new DeviceHiveContext()) { return context.AccessKeys .Include(e => e.Permissions) .FirstOrDefault(e => e.ID == id); } }
public List <AccessKey> GetByUsers(int[] userIds, AccessKeyFilter filter = null) { using (var context = new DeviceHiveContext()) { return(context.AccessKeys .Include(e => e.Permissions) .Where(e => userIds.Contains(e.UserID)).Filter(filter).ToList()); } }
public List<DeviceClass> GetAll(DeviceClassFilter filter = null) { using (var context = new DeviceHiveContext()) { return context.DeviceClasses .Include(e => e.Equipment) .Filter(filter).ToList(); } }
public void SetLastOnline(int id) { using (var context = new DeviceHiveContext()) { context.Database.ExecuteSqlCommand( "update [Device] set [LastOnline] = sysutcdatetime() where [ID] = @ID", new SqlParameter("ID", id)); } }
public List <DeviceClass> GetAll(DeviceClassFilter filter = null) { using (var context = new DeviceHiveContext()) { return(context.DeviceClasses .Include(e => e.Equipment) .Filter(filter).ToList()); } }
public DeviceClass Get(int id) { using (var context = new DeviceHiveContext()) { return(context.DeviceClasses .Include(e => e.Equipment) .FirstOrDefault(e => e.ID == id)); } }
public Equipment Get(int id) { using (var context = new DeviceHiveContext()) { return context.Equipments .Include(e => e.DeviceClass) .FirstOrDefault(e => e.ID == id); } }
public List<Equipment> GetByDeviceClass(int deviceClassId) { using (var context = new DeviceHiveContext()) { return context.Equipments .Include(e => e.DeviceClass) .Where(e => e.DeviceClass.ID == deviceClassId).ToList(); } }
public List <Equipment> GetByDeviceClass(int deviceClassId) { using (var context = new DeviceHiveContext()) { return(context.Equipments .Include(e => e.DeviceClass) .Where(e => e.DeviceClass.ID == deviceClassId).ToList()); } }
public List<AccessKey> GetByUsers(int[] userIds, AccessKeyFilter filter = null) { using (var context = new DeviceHiveContext()) { return context.AccessKeys .Include(e => e.Permissions) .Where(e => userIds.Contains(e.UserID)).Filter(filter).ToList(); } }
public AccessKey Get(int id) { using (var context = new DeviceHiveContext()) { return(context.AccessKeys .Include(e => e.Permissions) .FirstOrDefault(e => e.ID == id)); } }
public Device Get(int id) { using (var context = new DeviceHiveContext()) { return context.Devices .Include(e => e.Network) .Include(e => e.DeviceClass.Equipment) .FirstOrDefault(e => e.ID == id); } }
public OAuthClient Get(string oauthId) { if (string.IsNullOrEmpty(oauthId)) throw new ArgumentNullException("oauthId"); using (var context = new DeviceHiveContext()) { return context.OAuthClients.SingleOrDefault(u => u.OAuthID == oauthId); } }
public UserNetwork Get(int userId, int networkId) { using (var context = new DeviceHiveContext()) { return context.UserNetworks .Include(un => un.User) .Include(un => un.Network) .FirstOrDefault(un => un.UserID == userId && un.NetworkID == networkId); } }
public Network Get(string name) { if (string.IsNullOrEmpty(name)) throw new ArgumentNullException("name"); using (var context = new DeviceHiveContext()) { return context.Networks.SingleOrDefault(u => u.Name == name); } }
public UserNetwork Get(int userId, int networkId) { using (var context = new DeviceHiveContext()) { return(context.UserNetworks .Include(un => un.User) .Include(un => un.Network) .FirstOrDefault(un => un.UserID == userId && un.NetworkID == networkId)); } }