Esempio n. 1
0
        // GET api/<controller>
        //public IEnumerable<string> Get() {
        //    return new string[] { "value1", "value2" };
        //}

        //// GET api/<controller>/5
        //public string Get(int id) {
        //    return "value";
        //}

        // POST api/values returns json
        /// <summary>
        /// Json-t vár POST data-ként: 
        /// </summary>
        /// <param name="value">Json-t vár POST data-ként, pl:  {sessions:{db:'Ostomy',action:'list_sessions',pars:{sid:'0',machineid:'1'}}}</param>
        /// <returns>Json-ként formázott DataSet. Pl: { "sessions": [  {  "sid": 30,  "machineid": 1,  "machinename": "A200",  "startdate": "2015-12-01T13:55:29.8",  "shid": 1,  "shname": "T1",  "enddate": "2015-12-10T08:34:21.45",  "prodid": 78,  "prodcode": "1703597",  "lotid": "123123",  "goodamount": 1  } ] }</returns>
        public DataSet Post([FromBody]string value) {
            using (DataSet ds = new DataSet()) {
                var oJsons = new Dictionary<string, JsonRequest>();
                try {
                    oJsons = JsonConvert.DeserializeObject<Dictionary<string, JsonRequest>>(value);
                }
                catch (Exception) {
                    try {
                        var Json = JsonConvert.DeserializeObject<JsonRequest>(value);
                        oJsons.Add("0", Json);
                    }
                    catch (Exception) {
                        throw new Exception("Nem sikerült értelmezni a JSON adatot. A helyes formátum pl: {sessions:{db:'Ostomy',action:'list_sessions',pars:{sid:'0',machineid:'1'}}}");
                    }
                }
                //var oJson = JsonConvert.DeserializeObject<JsonRequest>(value);
                foreach (KeyValuePair<string, JsonRequest> item in oJsons) {
                    JsonRequest oJson = item.Value;
                    _sql = new Sql(getConnectionString(oJson.db));
                    using (DataTable dt = _sql.spExecuters[oJson.action](oJson.pars)) {
                        dt.TableName = item.Key;
                        ds.Tables.Add(dt);
                    }
                }
                return ds;
            }
        }
Esempio n. 2
0
        //// GET api/<controller>
        //public IEnumerable<string> Get() {
        //    return new string[] { "value1", "value2" };
        //}

        //// GET api/<controller>/5
        //public string Get(int id) {
        //    return "value";
        //}

        // POST api/values returns json
        /// <summary>
        /// Json-t vár POST data-ként: 
        /// </summary>
        /// <param name="value">Json-t vár POST data-ként, pl:  {db:'Ostomy',action:'list_sessions',pars:{sid:'0',machineid:'1'}}</param>
        /// <returns>Json-ként formázott DataSet. Pl:  [  {  "sid": 30,  "machineid": 1,  "machinename": "A200",  "startdate": "2015-12-01T13:55:29.8",  "shid": 1,  "shname": "T1",  "enddate": "2015-12-10T08:34:21.45",  "prodid": 78,  "prodcode": "1703597",  "lotid": "123123",  "goodamount": 1  } ] </returns>
        public DataTable Post([FromBody]object value) {
            JsonRequest oJson;
            try {
                oJson = JsonConvert.DeserializeObject<JsonRequest>(value.ToString());
            }
            catch (Exception) {
                throw new Exception("Nem sikerült értelmezni a JSON adatot. A helyes formátum pl: {db:'Ostomy',action:'list_sessions',pars:{sid:'0',machineid:'1'}}");
            }

            //var oJson = JsonConvert.DeserializeObject<JsonRequest>(value);
            _sql = new Sql(getConnectionString(oJson.db));
            using (DataTable dt = _sql.spExecuters[oJson.action](oJson.pars)) {
                return dt;
            }
        }