From efc710fd68fcd3d2616223398fe70391243eea77 Mon Sep 17 00:00:00 2001 From: marcinzelent Date: Thu, 4 May 2017 11:41:15 +0200 Subject: Added API client and LoginViewModel. --- .../ApartmentManager/ApartmentManager.csproj | 4 +- ApartmentManager/ApartmentManager/AppShell.xaml.cs | 9 +- .../ApartmentManager/Persistency/ApiClient.cs | 95 ++++++++++++++++++++++ .../ApartmentManager/View/LoginPage.xaml.cs | 2 +- .../ApartmentManager/ViewModel/LoginViewModel.cs | 13 +++ 5 files changed, 120 insertions(+), 3 deletions(-) create mode 100644 ApartmentManager/ApartmentManager/Persistency/ApiClient.cs create mode 100644 ApartmentManager/ApartmentManager/ViewModel/LoginViewModel.cs diff --git a/ApartmentManager/ApartmentManager/ApartmentManager.csproj b/ApartmentManager/ApartmentManager/ApartmentManager.csproj index bf8ee95..5f4f7da 100644 --- a/ApartmentManager/ApartmentManager/ApartmentManager.csproj +++ b/ApartmentManager/ApartmentManager/ApartmentManager.csproj @@ -109,11 +109,13 @@ + + ApartmentPage.xaml @@ -217,7 +219,7 @@ 5.2.3 - 5.3.1 + 5.3.3 diff --git a/ApartmentManager/ApartmentManager/AppShell.xaml.cs b/ApartmentManager/ApartmentManager/AppShell.xaml.cs index 0bd4f7f..d3c0ca2 100644 --- a/ApartmentManager/ApartmentManager/AppShell.xaml.cs +++ b/ApartmentManager/ApartmentManager/AppShell.xaml.cs @@ -25,6 +25,13 @@ namespace ApartmentManager Label = "Home", DestPage = typeof(ApartmentPage), IsSelected = true + }, + new NavMenuItem() + { + Symbol= Symbol.Accept, + Label = "Defects", + DestPage = typeof(BoardMembersDefectsPage), + IsSelected = false } }); @@ -39,7 +46,7 @@ namespace ApartmentManager { InitializeComponent(); - List topNavMenuItems = navMenuItems.GetRange(0, 1); + List topNavMenuItems = navMenuItems.GetRange(0, 2); // List bottomNavMenuItems = navMenuItems.GetRange(3, 2); NavMenuList.ItemsSource = topNavMenuItems; 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/View/LoginPage.xaml.cs b/ApartmentManager/ApartmentManager/View/LoginPage.xaml.cs index 6f3a86b..4bb12ec 100644 --- a/ApartmentManager/ApartmentManager/View/LoginPage.xaml.cs +++ b/ApartmentManager/ApartmentManager/View/LoginPage.xaml.cs @@ -50,7 +50,7 @@ namespace ApartmentManager.View { // When the navigation stack isn't restored, navigate to the first page // suppressing the initial entrance animation. - appShell.AppFrame.Navigate(typeof(ApartmentPage)); + appShell.AppFrame.Navigate(typeof(BoardMembersPage)); } // Ensure the current window is active 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 + { + + } +} -- cgit v1.2.3