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)); }
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); }
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)); } }
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)); } }