Repository navigation
Expand file tree
/
Copy pathUserDataAccess.cs
More file actions
68 lines (59 loc) · 1.94 KB
/
Copy pathUserDataAccess.cs
File metadata and controls
68 lines (59 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System;
using System.Collections.Generic;
using System.IO;
using System.Json;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using GSios.Models;
using Newtonsoft.Json;
namespace GSios.DataAccess
{
public class UserDataAccess
{
public UserDataAccess()
{
}
//Get coordinaes of all users
public IEnumerable<Coordinate> getUserLocations()
{
JsonValue json2 = GetCoords("http://gsios.azurewebsites.net/location/userLocations");
var coords = JsonConvert.DeserializeObject<IEnumerable<Coordinate>>(json2.ToString());
return coords;
}
//Add user to DB
public async Task<bool> AddUser(long id, string FullName)
{
var client = new HttpClient();
var model = new RegistrationModel()
{
UserName = "username",
Password = "password",
Latitude = 2343225,
Longitude = 2323562,
PhoneNumber = 23423452
};
var json = JsonConvert.SerializeObject(model);
HttpContent content = new StringContent(json);
content.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
var response = await client.PostAsync("http://gsios.azurewebsites.net/users/Register", content);
return response.IsSuccessStatusCode;
}
//Get all coordinates
private JsonValue GetCoords(string url)
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri(url));
request.ContentType = "application/json";
request.Method = "GET";
using (WebResponse response = request.GetResponseAsync().GetAwaiter().GetResult())
{
using (Stream stream = response.GetResponseStream())
{
JsonValue jsonDoc = JsonObject.Load(stream);
Console.Out.WriteLine("Response: {0}", jsonDoc.ToString());
return jsonDoc;
}
}
}
}
}