diff options
author | marcinzelent <marcin@zelent.net> | 2017-05-04 11:41:15 +0200 |
---|---|---|
committer | marcinzelent <marcin@zelent.net> | 2017-05-04 11:41:15 +0200 |
commit | efc710fd68fcd3d2616223398fe70391243eea77 (patch) | |
tree | b2a844f6f853b12aa9f63bb500ee165e483a8ffd | |
parent | 7a20ba55b904fc211e213903908565a3ae7f025d (diff) |
Added API client and LoginViewModel.
5 files changed, 120 insertions, 3 deletions
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 @@ <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> @@ -217,7 +219,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/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<NavMenuItem> topNavMenuItems = navMenuItems.GetRange(0, 1); + List<NavMenuItem> topNavMenuItems = navMenuItems.GetRange(0, 2); // List<NavMenuItem> 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 + { + + } +} |