aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ApartmentManager/ApartmentManager/ApartmentManager.csproj4
-rw-r--r--ApartmentManager/ApartmentManager/Persistency/ApiClient.cs95
-rw-r--r--ApartmentManager/ApartmentManager/ViewModel/LoginViewModel.cs13
3 files changed, 111 insertions, 1 deletions
diff --git a/ApartmentManager/ApartmentManager/ApartmentManager.csproj b/ApartmentManager/ApartmentManager/ApartmentManager.csproj
index 74d3c6c..dfd029d 100644
--- a/ApartmentManager/ApartmentManager/ApartmentManager.csproj
+++ b/ApartmentManager/ApartmentManager/ApartmentManager.csproj
@@ -109,11 +109,13 @@
<Compile Include="Model\CatalogSingleton.cs" />
<Compile Include="Model\Resident.cs" />
<Compile Include="Model\User.cs" />
+ <Compile Include="Persistency\ApiClient.cs" />
<Compile Include="Persistency\PersistenceFacade.cs" />
<Compile Include="Properties\Annotations.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ViewModel\ApartmentsViewModel.cs" />
<Compile Include="ViewModel\ApartmenViewModel.cs" />
+ <Compile Include="ViewModel\LoginViewModel.cs" />
<Compile Include="View\ApartmentPage.xaml.cs">
<DependentUpon>ApartmentPage.xaml</DependentUpon>
</Compile>
@@ -225,7 +227,7 @@
<Version>5.2.3</Version>
</PackageReference>
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
- <Version>5.3.1</Version>
+ <Version>5.3.3</Version>
</PackageReference>
</ItemGroup>
<ItemGroup />
diff --git a/ApartmentManager/ApartmentManager/Persistency/ApiClient.cs b/ApartmentManager/ApartmentManager/Persistency/ApiClient.cs
new file mode 100644
index 0000000..e803005
--- /dev/null
+++ b/ApartmentManager/ApartmentManager/Persistency/ApiClient.cs
@@ -0,0 +1,95 @@
+using Newtonsoft.Json;
+using System;
+using System.Net.Http;
+using System.Net.Http.Headers;
+using System.Text;
+
+namespace ApartmentManager.Persistency
+{
+ public static class ApiClient
+ {
+ private const string ServerUrl = "http://localhost:60916";
+
+ public static string GetData(string url)
+ {
+ HttpClientHandler handler = new HttpClientHandler() { UseDefaultCredentials = true };
+ using (var client = new HttpClient(handler))
+ {
+ client.BaseAddress = new Uri(ServerUrl);
+ client.DefaultRequestHeaders.Clear();
+ client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
+ try
+ {
+ var response = client.GetAsync(url).Result;
+ if (response.IsSuccessStatusCode)
+ {
+ return response.Content.ReadAsStringAsync().Result;
+ }
+ else return null;
+ }
+ catch (Exception)
+ {
+ return null;
+ }
+ }
+ }
+
+ public static void PutData(string url, object objectToPut)
+ {
+ HttpClientHandler handler = new HttpClientHandler() { UseDefaultCredentials = true };
+ using (var client = new HttpClient(handler))
+ {
+ client.BaseAddress = new Uri(ServerUrl);
+ client.DefaultRequestHeaders.Clear();
+ client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
+ try
+ {
+ string serializedData = JsonConvert.SerializeObject(objectToPut);
+ StringContent content = new StringContent(serializedData, Encoding.UTF8, "application/json");
+ var response = client.PutAsync(url, content).Result;
+ }
+ catch (Exception)
+ {
+ }
+ }
+ }
+
+ public static void PostData(string url, object objectToPost)
+ {
+ HttpClientHandler handler = new HttpClientHandler() { UseDefaultCredentials = true };
+ using (var client = new HttpClient(handler))
+ {
+ client.BaseAddress = new Uri(ServerUrl);
+ client.DefaultRequestHeaders.Clear();
+ client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
+ try
+ {
+ string serializedData = JsonConvert.SerializeObject(objectToPost);
+ StringContent content = new StringContent(serializedData, Encoding.UTF8, "application/json");
+ var response = client.PostAsync(url, content).Result;
+ }
+ catch (Exception)
+ {
+ }
+ }
+ }
+
+ public static void DeleteData(string url)
+ {
+ HttpClientHandler handler = new HttpClientHandler() { UseDefaultCredentials = true };
+ using (var client = new HttpClient(handler))
+ {
+ client.BaseAddress = new Uri(ServerUrl);
+ client.DefaultRequestHeaders.Clear();
+ client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
+ try
+ {
+ var response = client.DeleteAsync(url).Result;
+ }
+ catch (Exception)
+ {
+ }
+ }
+ }
+ }
+}
diff --git a/ApartmentManager/ApartmentManager/ViewModel/LoginViewModel.cs b/ApartmentManager/ApartmentManager/ViewModel/LoginViewModel.cs
new file mode 100644
index 0000000..51dabb5
--- /dev/null
+++ b/ApartmentManager/ApartmentManager/ViewModel/LoginViewModel.cs
@@ -0,0 +1,13 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ApartmentManager.ViewModel
+{
+ class LoginViewModel
+ {
+
+ }
+}