public async Task <IActionResult> GetLastState() { try { await Db.Connection.OpenAsync(); var query = new HistoryStateLampuQuery(Db); var result = await query.AllDataSyn(); if (result != null) { int hsil = 1; var returnedJson = "{"; foreach (var hasil in result) { returnedJson += "\"" + hsil + "\": " + hasil.Lampu_State + ","; hsil++; } returnedJson += "}"; // parse the json response so that we can get at the key/value pairs dynamic api = JObject.Parse(returnedJson); return(new OkObjectResult(api)); } else { var response = new ResponsePushDataMicroCTRL(); response.message = "Data tidak ditemukan !"; response.status = 1; return(new OkObjectResult(response)); } } catch (Exception exc) { var response = new ResponsePushDataMicroCTRL(); response.message = "Error ! " + exc.ToString(); response.status = 1; return(new OkObjectResult(response)); } }
public async Task <IActionResult> GetAllData() { try { await Db.Connection.OpenAsync(); var query = new HistoryStateLampuQuery(Db); var result = await query.AllDataSyn(); return(new OkObjectResult(result)); } catch (Exception exc) { var response = new ResponseHistoryStateLampu(); response.message = "Error ! " + exc.ToString(); response.status = 1; return(new OkObjectResult(response)); } }
public async Task <IActionResult> GetDataWithFilter([FromBody] HistoryFilterBody body) { try { var response = new ResponseHistoryStateLampu(); if (body is null) { response.message = "Data tidak ditemukan ! "; response.status = 1; return(new OkObjectResult(response)); } await Db.Connection.OpenAsync(); var query = new HistoryStateLampuQuery(Db); var DateFrom = body.Date_From; var DateTo = body.Date_To; var result = await query.SelectWithFilterSync(body.Lampu_ID, body.Lampu_State, DateFrom, DateTo); if (result is null) { response.message = "Data tidak ditemukan ! "; response.status = 1; return(new OkObjectResult(response)); } return(new OkObjectResult(result)); } catch (Exception exc) { var response = new ResponseHistoryStateLampu(); response.message = "Error ! " + exc.ToString(); response.status = 1; return(new OkObjectResult(response)); } }