public IActionResult AddDevice([FromBody] AddDeviceModel model) { var timing = userService.AddDevice(model); if (timing == 0) { return(BadRequest(new { Message = "Something went wrong." })); } return(Ok(new { SecondsElapsed = timing })); }
public IActionResult AddDevice() { AddDeviceModel model = new AddDeviceModel(); model.Model = "selflearning-switch"; model.Protocol = "arctech"; model.ParameterHouse = new Random().Next(1, 67108863).ToString(); // TODO: should be dividable by 4 model.ParameterUnit = "1"; return(View(model)); }
public double AddDevice(AddDeviceModel model) { Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); Device newDevice = new Device { DeviceId = model.Id, DeviceName = model.Name, OperationState = context.OperationStates.First(opState => opState.DisplayValue == "Online") }; context.Devices.Add(newDevice); context.SaveChanges(); stopWatch.Stop(); return(stopWatch.Elapsed.TotalSeconds); }
public IActionResult AddDevice(AddDeviceModel addDeviceModel) { if (ModelState.IsValid) { var parameters = new Dictionary <string, string>(); if (!string.IsNullOrWhiteSpace(addDeviceModel.ParameterHouse)) { parameters.Add("house", addDeviceModel.ParameterHouse); } if (!string.IsNullOrWhiteSpace(addDeviceModel.ParameterUnit)) { parameters.Add("unit", addDeviceModel.ParameterUnit); } // TODO: implement //telldusCoreService.AddDevice(addDeviceModel.Name, addDeviceModel.Protocol, addDeviceModel.Model, parameters); return(RedirectToAction("Index")); } return(View(addDeviceModel)); }
public async Task <IActionResult> RegisterDevice([FromServices] IMediatorHandler bus, [FromBody] AddDeviceModel addDeviceModel) { var command = new AddDeviceCommand(addDeviceModel.Name, addDeviceModel.Observation, addDeviceModel.MacAddress, addDeviceModel.UserId); await bus.SendCommand(command); return(ResponseCreated($"api/device/{command.Id}", new DeviceDetailsModel { Id = command.Id.ToString(), Name = command.Name, MacAddress = command.MacAddress, Observation = command.Observation })); }