Ejemplo n.º 1
0
        public int AddDevice(AcDeviceDto deviceDto)
        {
            var device = new ACDevice()
            {
                Id    = deviceDto.Id,
                Brand = deviceDto.Brand,
                Model = deviceDto.Model,

                //fixed values, because other devices are not supported at this moment
                DutyCycle = 0.5,
                ModulationFrequencyInHz = 38000
            };

            return(AddDevice(device));
        }
Ejemplo n.º 2
0
        public AcDeviceDto UpdateDevice(AcDeviceDto deviceDto)
        {
            var dev = _acDeviceRepository.Find(x => x.Id.Equals(deviceDto.Id)).SingleOrDefault();

            if (dev == null)
            {
                throw new ItemNotFoundException($"AcDevice with id {deviceDto.Id} not found!");
            }

            dev.Brand = deviceDto.Brand;
            dev.Model = deviceDto.Model;

            _acDeviceRepository.Update(dev);

            return(deviceDto);
        }
Ejemplo n.º 3
0
        public IActionResult Put([FromBody] AcDeviceDto device)
        {
            try
            {
                try
                {
                    device = _acDeviceService.UpdateDevice(device);
                }
                catch (ItemNotFoundException e)
                {
                    return(BadRequest(e.Message));
                }
                return(Ok(device));
            }

            catch (Exception ex)
            {
                _logger.LogError(ex, "500: Internal Server Error");
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }
Ejemplo n.º 4
0
        public IActionResult Post([FromBody] AcDeviceDto device)
        {
            try
            {
                int retId;
                try
                {
                    retId = _acDeviceService.AddDevice(device);
                }
                catch (ItemAlreadyExistsException e)
                {
                    return(BadRequest(e.Message));
                }
                return(Ok(retId));
            }

            catch (Exception ex)
            {
                _logger.LogError(ex, "500: Internal Server Error");
                return(StatusCode(StatusCodes.Status500InternalServerError));
            }
        }