public void RegisterNewNetwork(string name, string pass) { try { localDb = new SQLiteDataService(); using (var client = new HttpClient()) { var currentUser = localDb.GetCurrentUser(); Network net = new Network() { Name = name, Password = pass, CreatorUserId = currentUser.UserId }; var response = client.PostAsJsonAsync <Network>(APP_PATH + "/api/network/CreateNewNetwork", net); Network deserializedNetwork; if (response.Result.StatusCode == HttpStatusCode.Created) { deserializedNetwork = JsonConvert.DeserializeObject <Network>(response.Result.Content.ReadAsStringAsync().Result); SQLiteDataService localBD = new SQLiteDataService(); localBD.AddCurrentNetwork(deserializedNetwork); currentUser.NetworkId = deserializedNetwork.NetworkId; } else { System.Diagnostics.Debug.WriteLine($"Got wrong response StatusCode while creating new network: {response.Result.StatusCode}"); Log.Error($"Got wrong response StatusCode while creating new network: {response.Result.StatusCode}"); } } } catch (Exception e) { System.Diagnostics.Debug.WriteLine($"Couldn't create new network: {e}"); Log.Error(e, "Couldn't create new network"); } }
public bool JoinToNetwork(string name, string pass) { try { localDb = new SQLiteDataService(); using (var client = new HttpClient()) { var currentUser = localDb.GetCurrentUser(); var tt = $"{APP_PATH}/api/network/GetNetwork?name={name}&pass={pass}"; var response = client.GetAsync($"{APP_PATH}/api/network/GetNetwork?name={name}&pass={pass}"); Network deserializedNetwork; if (response.Result.StatusCode == HttpStatusCode.Found) { deserializedNetwork = JsonConvert.DeserializeObject <Network>(response.Result.Content.ReadAsStringAsync().Result); SQLiteDataService localBD = new SQLiteDataService(); localBD.AddCurrentNetwork(deserializedNetwork); currentUser.NetworkId = deserializedNetwork.NetworkId; return(true); } else if (response.Result.StatusCode == HttpStatusCode.NotFound) { return(false); } else { System.Diagnostics.Debug.WriteLine($"Got wrong response StatusCode while creating new network: {response.Result.StatusCode}"); Log.Error($"Got wrong response StatusCode while creating new network: {response.Result.StatusCode}"); return(false); } } } catch (Exception e) { System.Diagnostics.Debug.WriteLine($"Couldn't get a network: {e}"); Log.Error(e, "Couldn't get a network"); return(false); } }