public void CreateDevice(User user, string name)
 {
     _context.Devices.Add(new Device
     {
         DeviceName = name,
         UserId = user.Id
     });
     _context.SaveChanges();
 }
        public bool UpdateDevice(User user, string oldName, string newName)
        {
            Device device = GetDevice(user, oldName);

            if (device == null)
            {
                return false;
            }

            device.DeviceName = newName;
            _context.SaveChanges();
            return true;
        }
 public bool HasDevice(User user, string name)
 {
     return GetDevice(user, name) != null;
 }
 public IEnumerable<Device> GetDevices(User user)
 {
     return _context.Devices.Where(x => x.UserId == user.Id);
 }
 public Device GetDevice(User user, string name)
 {
     return GetDevices(user).FirstOrDefault(x => x.DeviceName == name);
 }
 public AuthentificationPrincipal(User user, params string[] roles)
     : base(new AuthentificationIdentity(user.Login, user.Password), roles ?? new string[]{})
 {
     User = user;
 }