public async Task AddLightPoint(Guid homeLightSystemId, LightPointDto lightPointDto) { try { await $"{_homeAutomationLightSystemApi}/{lightPointUrl}/{homeLightSystemId}". PostJsonAsync(lightPointDto); } catch (Exception ex) { Console.Write(ex); // throw; } }
public async Task <IActionResult> PostLightPoint(Guid homeLightSystemId, [FromBody] LightPointDto request) { var bulbs = new List <LightBulb>(); bulbs = _mapper.Map <List <LightBulb> >(request.LightBulbs); var lightPoint = await _mediator.Send( new AddLightPointCommand( request.Id, request.CustomName, homeLightSystemId, bulbs)); // TODO mapper return(Created(string.Empty, lightPoint)); }
private async Task UserConnected(string payload) { //TODO try catch serializer can crash LightPoint lightPointSwitch = JsonConvert.DeserializeObject <LightPoint>(payload); try { var lightPoint = await _restClient.GetLightPoints(Guid.Parse(lightPointSwitch.Id)); if (lightPoint.CustomName == null) { var lightBulb = new List <LightBulbDto>(); foreach (var id in lightPointSwitch.BulbsId) { lightBulb.Add(new LightBulbDto() { Id = Guid.Parse(id) }); } var lightPointDto = new LightPointDto() { CustomName = lightPointSwitch.CustomName, Id = Guid.Parse(lightPointSwitch.Id), LightBulbs = lightBulb }; //TODO auto generation of guid and saving to memeory of rPi await _restClient.AddLightPoint(Guid.Parse(_homeAutomationLocalLightSystemId), lightPointDto); } else { await _restClient.EnableLightPoint(Guid.Parse(lightPointSwitch.Id)); } } catch (Exception ex) { await _logger.SendMessage($"Lighting System {ex}", LogLevel.Error); await _lokiLogger.SendMessage($"Lighting System {ex}", LogLevel.Error); Console.WriteLine(ex); } }
public async Task AddLightPoint(Guid homeLightSystemId, LightPointDto lightPointDto) { try { var token = await GetToken(); await $"{_homeAutomationLightSystemApi}/{lightPointUrl}/{homeLightSystemId}" .SetQueryParams(new { access_token = token }) .PostJsonAsync(lightPointDto); } catch (Exception ex) { await _lokiLogger.SendMessage($"Lighting System {ex}", LogLevel.Error); Console.Write(ex); } }