public newTask BuildData(string dataString) { newTask responseJsonString = JsonConvert.DeserializeObject <newTask>(dataString); responseJsonString.isPin = ConvertBoolField.Convert(responseJsonString.isPin); responseJsonString.isComplete = ConvertBoolField.Convert(responseJsonString.isComplete); responseJsonString.dateBind = ConvertDataField.Convert(responseJsonString.dateBind); responseJsonString.dateCreate = ConvertDataField.Convert(responseJsonString.dateCreate); return(responseJsonString); }
public string PostJson(string jsonString) { if (jsonString == null) { return("Invalid data format"); } else { Connect connect = new Connect(); MySqlConnection mySqlConnect = connect.SqlConnect(); NewDataObject buildDataObject = new NewDataObject(); newTask responseJsonString = buildDataObject.BuildData(jsonString); MySqlCommand cmd = new MySqlCommand { CommandText = $"INSERT INTO organizer (id, dateBind, dateCreate, title, descr, isPin, isComplete) " + $"values('{responseJsonString.id}','{responseJsonString.dateBind}','{responseJsonString.dateCreate}'," + $"'{responseJsonString.title}','{responseJsonString.descr}','{responseJsonString.isPin}'," + $"'{responseJsonString.isComplete}')", Connection = mySqlConnect, }; try { int countRows = cmd.ExecuteNonQuery(); mySqlConnect.Close(); return("201"); } catch (MySqlException ex) { string cmdStatus = ex.Message; mySqlConnect.Close(); return(cmdStatus); } } }