I'm using javascript to receive data from an arduino, to save the data on the database i'm using dapper and to test it i'm using postman.
Here's my javascript code for receiving the Json data. I'm compairing the names on my javascript code (which are use to receive the data) with the ones i'm using on my c# code that are mapped with my database, if the names match then save the data i just received in my database and post it on my website
var Latitude = ("#Latitude").val();
var Longitude = ("#Longitude").val();
var Country = ("#Country").val();
var ObtainedDate = ("#ObtainedDate").val();
$.ajax({
type: 'POST',
url: 'http://localhost:59319/Home/Map',
data: { Latitude: Latitude, Longitude: Longitude, Country: Country, ObtainedDate: ObtainedDate },
dataType: "json",
success: function (lctn) {
$.each(lctn, function (i, lctns) {
$lctn.append(lctns.Latitude + lctns.Longitude + lctns.Country + lctns.ObtainedDate)
});
}
});
Here's the code i used to connect to my data base
SqlConnection conn = new SqlConnection();
public GeoDapperConnection()
{
conn.ConnectionString = "Server=tcp:espejo.database.windows.net,1433;Initial Catalog=DbEspejo;Persist Security Info=False;User ID=IntecEspejo;Password=P@ssw0rd;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;";
var data = conn.Query<Geography>("SELECT * FROM GEOGRAPHY").ToList();
}
This is to show the data from my data base
public List<Geography> Locations()
{
conn.Open();
var data = conn.Query<Geography>("GET_LOCATION", null, commandType: System.Data.CommandType.StoredProcedure).ToList();
conn.Close();
return data;
}
And this code is to receive the data from the javascript part and send it to my database
public void ReceiveData(Geography Geo)
{
conn.Open();
var queryParameters = new DynamicParameters();
queryParameters.Add("@Lat", Geo.Latitude);
queryParameters.Add("@Long", Geo.Longitude);
queryParameters.Add("@Country", Geo.Country);
queryParameters.Add("@DateCreated", Geo.ObtainedDate);
var data = conn.Query("INSERT_LOCATION", queryParameters, commandType: System.Data.CommandType.StoredProcedure);
conn.Close();
}
Here's the json data i'm posting to my website Postman
Here's the picture of my website, it doesn't show me on my list my new data
And this is my Geography class
public class Geography
{
[Key]
public int RouteID { get; set; }
public double Latitude { get; set; }
public double Longitude { get; set; }
public string ISO { get; set; }
public string Country { get; set; }
public string ISO3 { get; set; }
public DateTime ObtainedDate { get; set; }
}