public async Task <ActionResult> AddDevice(AddDeviceViewModel model) { if (String.IsNullOrEmpty(model.UserId)) { var user = _identityParser.Parse(User); model.UserId = user.id; } var response = await this._climateDeviceService.AssignToUserAsync(model.ViewToDomain()); if (!response.Value && response.ErrorCode != null) { ShowMessage(new GenericMessageViewModel { Type = MessageTypes.warning, Message = response.Error }); } else { ShowMessage(new GenericMessageViewModel { Type = MessageTypes.success, Message = "Device has been added" }); } return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Add(AddDeviceViewModel model) { if (ModelState.IsValid) { var device = new DeviceModel { Name = model.Name, SymmetricKey = model.SymmetricKey, DeviceToken = null, UserId = _userManager.GetUserId(User), Registered = false, Id = new Guid(model.Id) }; await _dbContext.AddAsync(device); var result = await _dbContext.SaveChangesAsync(); if (result == 1) { return(RedirectToAction(nameof(Index))); } else { return(View(model)); } } else { // Model validation did not pass model.Id = Guid.NewGuid().ToString(); return(View(model)); } }
public async Task <IActionResult> AddDevice(AddDeviceViewModel deviceData) { if (HttpContext.Session.GetInt32(UserController._UserID) < 0) { return(Redirect(UserController._LoginPath)); } if (ValidateDeviceData(deviceData)) { Models.Device device = new Models.Device { IpAddress = deviceData.IpAddress, Port = deviceData.Port, RoomId = deviceData.RoomID }; device = await GetDeviceData(device); //_context.Add(device); Models.Device.AddDevice(_context, device); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(OpenRoomDeviceList), new { roomID = deviceData.RoomID })); } return(View(_ViewPath + "AddDevice", deviceData)); }
public AddDevicePage(AuthViewModel authViewModel) { AddDeviceViewModel viewModel = new AddDeviceViewModel(authViewModel); DataContext = viewModel; InitializeComponent(); }
public static DeviceAddToUserDomainModel ViewToDomain(this AddDeviceViewModel @this) { return(new DeviceAddToUserDomainModel { name = @this.Name, serial_number = @this.SerialNumber, user_id = @this.UserId, type = @this.Type }); }
public async Task <ActionResult> AddDevice(AddDeviceViewModel model) { if (String.IsNullOrEmpty(model.UserId)) { var user = _identityParser.Parse(User); model.UserId = user.id; } if (_useFakeData) { fakeModels.Add(new LedViewModel { Name = model.Name, SerialNumber = model.SerialNumber, Power = String.Format("{0}W", new Random().Next(10, 120)), Intensity = new Random().Next(10, 100), IsEnable = new Random().Next(0, 1) == 1 ? true : false, IsOnline = new Random().Next(0, 1) == 1 ? true : false, VoltageRange = "100-220V" }); ShowMessage(new GenericMessageViewModel { Type = MessageTypes.success, Message = "Device has been added" }); return(RedirectToAction(nameof(Index))); } var response = await this._ledDeviceService.AssignToUserAsync(model.ViewToDomain()); if (!response.Value && response.ErrorCode != null) { ShowMessage(new GenericMessageViewModel { Type = MessageTypes.warning, Message = response.Error }); } else { ShowMessage(new GenericMessageViewModel { Type = MessageTypes.success, Message = "Device has been added" }); } return(RedirectToAction(nameof(Index))); }
public IActionResult Add() { // Create 256 bit random key byte[] bytes = new byte[32]; _rng.GetBytes(bytes); var key = Convert.ToBase64String(bytes); var id = Guid.NewGuid().ToString(); var registerURI = string.Format(RegisterUriFormat, key, id); var model = new AddDeviceViewModel { Id = id, SymmetricKey = key, RegisterURI = registerURI }; return(View(model)); }
public ActionResult OpenAddDeviceWindow(int?roomID) { if (HttpContext.Session.GetInt32(UserController._UserID) < 0) { return(Redirect(UserController._LoginPath)); } if (roomID == null) { return(NotFound()); } AddDeviceViewModel vm = new AddDeviceViewModel { RoomID = roomID.Value }; return(View(_ViewPath + "AddDevice", vm)); }
public override void OnReceive(Context context, Intent intent) { IList <ScanResult> scanResults = wifiManager.ScanResults; string dbm; foreach (ScanResult i in scanResults) { if (!string.IsNullOrEmpty(i.Ssid)) { foreach (var j in AddDeviceViewModel.GetInstance().wirelessCollection) { if (j.name == i.Ssid) { return; } } if (i.Level < 0 && i.Level >= -80) { dbm = "좋음"; } else if (i.Level < -80 && i.Level >= -90) { dbm = "보통"; } else { dbm = "나쁨"; } AddDeviceViewModel.GetInstance().wirelessCollection.Add(new Wireless() { name = i.Ssid, type = dbm, itemClickCommand = AddDeviceViewModel.GetInstance().wifiClickCommand }); } } }
public async Task <IActionResult> AddDevice() { var user = await _userManager.GetUserAsync(User); if (user == null) { throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'."); } using (var context = _context){ user = context.Users.Include(ApplicationUser => ApplicationUser.Devices) .Single(u => u.Id == user.Id); } var model = new AddDeviceViewModel(); //TODO: Redo with TOTP? or better implement HOTP in AddDeviceViewModel var hotp = new Hotp(Encoding.ASCII.GetBytes(user.Email), mode: OtpHashMode.Sha512); model.newToken = hotp.GetHashCode().ToString(); return(View(model)); }
public AddDeviceView() { InitializeComponent(); BindingContext = AddDeviceViewModel.GetInstance(); AddDeviceViewModel.GetInstance().Init(); }
public bool ValidateDeviceData(AddDeviceViewModel deviceData) { return(ModelState.IsValid); }