Ejemplo n.º 1
0
        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 }));
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
        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));
        }
Ejemplo n.º 5
0
        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
            }));
        }