public async Task <bool> SetColor(int deviceId, ARGBB color) { var device = dbContext.Device.Single(x => x.Id == deviceId); HttpClient client = await GetHttpClient(device.Ip); var result = await client.PostAsync("rgb", await DataToStringContent(color)); if (result.IsSuccessStatusCode) { var colorHistory = new ColorHistory() { DeviceId = device.Id, Red = color.Red, Green = color.Green, Blue = color.Blue, Brightness = color.Brightness, Date = DateTime.Now }; dbContext.ColorHistory.Add(colorHistory); await dbContext.SaveChangesAsync(); return(true); } return(false); }
public async Task <IActionResult> SetColor([FromBody] ARGBB color, int deviceId) { try { var response = await _colorService.SetColor(deviceId, color); return(Json(response)); } catch (Exception ex) { return(Json(false)); } }