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));
            }
        }
Beispiel #2
0
        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));
            }
        }