public void SetController(HttpContext context, string controllerId) { if (context.Request.Payload.Length > 0) { string json = context.Request.Payload.ReadAll(); Controller controller = JsonSerializer.DeserializeJson <Controller>(json); int id = ApiBase.ParseId(controllerId); if (controller == null) { throw new BadRequestException(BadRequestException.MSG_INVALID_PAYLOAD); } else { _controllerHandler.ChangeController(id, controller.Name, controller.LedCount); Controller response = _controllerHandler.GetController(id); string jsonResponse = JsonSerializer.SerializeJson(response); context.Response.Payload.Write(jsonResponse); context.Response.Status = HttpStatus.OK; } } else { throw new BadRequestException(BadRequestException.MSG_PAYLOAD_EXPECTED); } }