diff options
31 files changed, 1318 insertions, 466 deletions
diff --git a/ApartmentManager/ApartmentManager/ApartmentManager.csproj b/ApartmentManager/ApartmentManager/ApartmentManager.csproj index 1b3c63e..0f22d96 100644 --- a/ApartmentManager/ApartmentManager/ApartmentManager.csproj +++ b/ApartmentManager/ApartmentManager/ApartmentManager.csproj @@ -104,7 +104,7 @@ <Compile Include="Handler\LoginHandler.cs" /> <Compile Include="Handler\ApartmentHandler.cs" /> <Compile Include="Model\Apartment.cs" /> - <Compile Include="Model\DefectComments.cs" /> + <Compile Include="Model\DefectComment.cs" /> <Compile Include="Model\DefectPicture.cs" /> <Compile Include="Persistency\ImgurPhotoUploader.cs" /> <Compile Include="Singletons\BmSingleton.cs" /> @@ -115,7 +115,6 @@ <Compile Include="Model\User.cs" /> <Compile Include="Singletons\UserSingleton.cs" /> <Compile Include="Persistency\ApiClient.cs" /> - <Compile Include="Persistency\PersistenceFacade.cs" /> <Compile Include="Properties\Annotations.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="ViewModel\BmViewModel.cs" /> @@ -136,9 +135,15 @@ <Compile Include="View\BmChangesPage.xaml.cs"> <DependentUpon>BmChangesPage.xaml</DependentUpon> </Compile> + <Compile Include="View\BmCreateDefectPage.xaml.cs"> + <DependentUpon>BmCreateDefectPage.xaml</DependentUpon> + </Compile> <Compile Include="View\BmEditApartmentPage.xaml.cs"> <DependentUpon>BmEditApartmentPage.xaml</DependentUpon> </Compile> + <Compile Include="View\BmEditDefectPage.xaml.cs"> + <DependentUpon>BmEditDefectPage.xaml</DependentUpon> + </Compile> <Compile Include="View\BmResidentsPage.xaml.cs"> <DependentUpon>BmResidentsPage.xaml</DependentUpon> </Compile> @@ -154,6 +159,9 @@ <Compile Include="View\BmCreateApartmentPage.xaml.cs"> <DependentUpon>BmCreateApartmentPage.xaml</DependentUpon> </Compile> + <Compile Include="View\BmSingleDefectPage.xaml.cs"> + <DependentUpon>BmSingleDefectPage.xaml</DependentUpon> + </Compile> <Compile Include="View\BmUsersPage.xaml.cs"> <DependentUpon>BmUsersPage.xaml</DependentUpon> </Compile> @@ -215,10 +223,18 @@ <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> + <Page Include="View\BmCreateDefectPage.xaml"> + <SubType>Designer</SubType> + <Generator>MSBuild:Compile</Generator> + </Page> <Page Include="View\BmEditApartmentPage.xaml"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> + <Page Include="View\BmEditDefectPage.xaml"> + <SubType>Designer</SubType> + <Generator>MSBuild:Compile</Generator> + </Page> <Page Include="View\BmResidentsPage.xaml"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> @@ -239,6 +255,10 @@ <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> </Page> + <Page Include="View\BmSingleDefectPage.xaml"> + <SubType>Designer</SubType> + <Generator>MSBuild:Compile</Generator> + </Page> <Page Include="View\BmUsersPage.xaml"> <SubType>Designer</SubType> <Generator>MSBuild:Compile</Generator> diff --git a/ApartmentManager/ApartmentManager/Common/Controls/NavMenuListView.cs b/ApartmentManager/ApartmentManager/Common/Controls/NavMenuListView.cs deleted file mode 100644 index 9591ad1..0000000 --- a/ApartmentManager/ApartmentManager/Common/Controls/NavMenuListView.cs +++ /dev/null @@ -1,120 +0,0 @@ -using System; -using Windows.UI.Xaml; -using Windows.UI.Xaml.Controls; -using Windows.UI.Xaml.Media; -using Windows.UI.Xaml.Media.Animation; - -namespace ApartmentManager.Controls -{ - /// <summary> - /// A specialized ListView to represent the items in the navigation menu. - /// </summary> - /// <remarks> - /// This class handles the following: - /// 1. Sizes the panel that hosts the items so they fit in the hosting pane. Otherwise, the keyboard - /// may appear cut off on one side b/c the Pane clips instead of affecting layout. - /// 2. Provides a single selection experience where keyboard focus can move without changing selection. - /// Both the 'Space' and 'Enter' keys will trigger selection. The up/down arrow keys can move - /// keyboard focus without triggering selection. This is different than the default behavior when - /// SelectionMode == Single. The default behavior for a ListView in single selection requires using - /// the Ctrl + arrow key to move keyboard focus without triggering selection. Users won't expect - /// this type of keyboarding model on the nav menu. - /// </remarks> - public class NavMenuListView : ListView - { - private SplitView _splitViewHost; - - public NavMenuListView() - { - SelectionMode = ListViewSelectionMode.Single; - IsItemClickEnabled = true; - ItemClick += ItemClickedHandler; - - // Locate the hosting SplitView control - Loaded += (s, a) => - { - var parent = VisualTreeHelper.GetParent(this); - while (parent != null && !(parent is SplitView)) - { - parent = VisualTreeHelper.GetParent(parent); - } - - if (parent != null) - { - _splitViewHost = parent as SplitView; - } - }; - } - - protected override void OnApplyTemplate() - { - base.OnApplyTemplate(); - - // Remove the entrance animation on the item containers. - for (int i = 0; i < ItemContainerTransitions.Count; i++) - { - if (ItemContainerTransitions[i] is EntranceThemeTransition) - { - ItemContainerTransitions.RemoveAt(i); - } - } - } - - /// <summary> - /// Mark the <paramref name="item"/> as selected and ensures everything else is not. - /// If the <paramref name="item"/> is null then everything is unselected. - /// </summary> - /// <param name="item"></param> - public void SetSelectedItem(ListViewItem item) - { - int index = -1; - if (item != null) - { - index = IndexFromContainer(item); - } - - for (int i = 0; i < Items.Count; i++) - { - var lvi = (ListViewItem)ContainerFromIndex(i); - if (i != index) - { - lvi.IsSelected = false; - } - else if (i == index) - { - lvi.IsSelected = true; - } - } - } - - /// <summary> - /// Occurs when an item has been selected - /// </summary> - public event EventHandler<ListViewItem> ItemInvoked; - - private void ItemClickedHandler(object sender, ItemClickEventArgs e) - { - // Triggered when the item is selected using something other than a keyboard - var item = ContainerFromItem(e.ClickedItem); - InvokeItem(item); - } - - private void InvokeItem(object focusedItem) - { - SetSelectedItem(focusedItem as ListViewItem); - ItemInvoked?.Invoke(this, focusedItem as ListViewItem); - - if (_splitViewHost.IsPaneOpen && ( - _splitViewHost.DisplayMode == SplitViewDisplayMode.CompactOverlay || - _splitViewHost.DisplayMode == SplitViewDisplayMode.Overlay)) - { - _splitViewHost.IsPaneOpen = false; - } - - if (focusedItem is ListViewItem) - { - ((ListViewItem)focusedItem).Focus(FocusState.Programmatic); - } - } - } -}
\ No newline at end of file diff --git a/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs b/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs index df38ecb..34cbb7c 100644 --- a/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs +++ b/ApartmentManager/ApartmentManager/Handler/ApartmentHandler.cs @@ -172,7 +172,7 @@ namespace ApartmentManager.Handler var defecttlist = JsonConvert.DeserializeObject<ObservableCollection<Defect>>(defectsFromDatabase); foreach (var defect in defecttlist) { - var picturesFromDatabase = ApiClient.GetData("api/DefectPictures/" + defect.DefectId); + var picturesFromDatabase = ApiClient.GetData("api/DefectPicturesById/" + defect.DefectId); if (picturesFromDatabase != "[]") { ApartmentViewModel.CatalogSingleton.DefectPictures = JsonConvert.DeserializeObject<ObservableCollection<DefectPicture>>(picturesFromDatabase); @@ -246,10 +246,10 @@ namespace ApartmentManager.Handler { var defectFromDatabase = ApiClient.GetData("api/defects/" + ApartmentViewModel.NewDefect.DefectId); ApartmentViewModel.CatalogSingleton.Defect = JsonConvert.DeserializeObject<Defect>(defectFromDatabase); - var picturesFromDatabase = ApiClient.GetData("api/DefectPictures/" + ApartmentViewModel.NewDefect.DefectId); + var picturesFromDatabase = ApiClient.GetData("api/DefectPicturesById/" + ApartmentViewModel.NewDefect.DefectId); ApartmentViewModel.CatalogSingleton.DefectPictures = JsonConvert.DeserializeObject<ObservableCollection<DefectPicture>>(picturesFromDatabase); var defectComments = ApiClient.GetData("api/Defectcomments/" + ApartmentViewModel.NewDefect.DefectId); - ApartmentViewModel.CatalogSingleton.DefectComments = JsonConvert.DeserializeObject<ObservableCollection<DefectComments>>(defectComments); + ApartmentViewModel.CatalogSingleton.DefectComments = JsonConvert.DeserializeObject<ObservableCollection<DefectComment>>(defectComments); CatalogSingleton.Instance.DefectId = ApartmentViewModel.NewDefect.DefectId; } catch (Exception e) @@ -263,7 +263,7 @@ namespace ApartmentManager.Handler { try { - DefectComments Comment = new DefectComments(); + DefectComment Comment = new DefectComment(); Comment.Comment = ApartmentViewModel.NewDefectComment.Comment; Comment.DefectId = CatalogSingleton.Instance.Defect.DefectId; Comment.Name = UserSingleton.Instance.CurrentUser.FirstName + " " + UserSingleton.Instance.CurrentUser.LastName; @@ -273,7 +273,7 @@ namespace ApartmentManager.Handler ApiClient.PostData("api/Defectcomments/", Comment); } var response = ApiClient.GetData("api/Defectcomments/" + CatalogSingleton.Instance.DefectId); - var commentlist = JsonConvert.DeserializeObject<ObservableCollection<DefectComments>>(response); + var commentlist = JsonConvert.DeserializeObject<ObservableCollection<DefectComment>>(response); CatalogSingleton.Instance.DefectComments.Clear(); foreach (var comment in commentlist) { diff --git a/ApartmentManager/ApartmentManager/Handler/BmHandler.cs b/ApartmentManager/ApartmentManager/Handler/BmHandler.cs index 2cbffea..8709180 100644 --- a/ApartmentManager/ApartmentManager/Handler/BmHandler.cs +++ b/ApartmentManager/ApartmentManager/Handler/BmHandler.cs @@ -6,6 +6,7 @@ using ApartmentManager.Persistency; using ApartmentManager.ViewModel; using Newtonsoft.Json; using ApartmentManager.Singletons; +using System.Collections.Generic; namespace ApartmentManager.Handler { @@ -204,5 +205,127 @@ namespace ApartmentManager.Handler } #endregion + #region DEFECTS + + public void GetDefects() + { + var defects = JsonConvert.DeserializeObject<ObservableCollection<Defect>>(ApiClient.GetData("api/Defects/")); + BmSingleton.Instance.Defects.Clear(); + foreach (var defect in defects) + { + defect.Pictures = JsonConvert.DeserializeObject<ObservableCollection<DefectPicture>>(ApiClient.GetData("api/DefectPicturesById/" + defect.DefectId)); + defect.Comments = JsonConvert.DeserializeObject<ObservableCollection<DefectComment>>(ApiClient.GetData("api/DefectComments/" + defect.DefectId)); + BmSingleton.Instance.Defects.Add(defect); + } + } + + public void CreateDefect() + { + try + { + _vm.DefectTemplate.Status = "New"; + _vm.DefectTemplate.UploadDate = DateTime.Now; + var response = JsonConvert.DeserializeObject<Defect>(ApiClient.PostData("api/Defects/", _vm.DefectTemplate)); + foreach(var defectPicture in _vm.DefectTemplate.Pictures) + { + defectPicture.DefectId = response.DefectId; + ApiClient.PostData("api/DefectPictures", defectPicture); + } + GetDefects(); + _vm.DefectTemplate = new Defect(); + } + catch (Exception e) + { + var msg = new MessageDialog(e.Message).ShowAsync(); + } + } + public void UpdateDefect() + { + try + { + ApiClient.PutData("api/Defects/" + _vm.DefectTemplate.DefectId, _vm.DefectTemplate); + var deletedDefectPictures = new List<DefectPicture>(_vm.DeletedDefectPictures); + var addedDefectPictures = new List<DefectPicture>(_vm.AddedDefectPictures); + + foreach (var defectPicture in deletedDefectPictures) + { + ApiClient.DeleteData("api/DefectPictures/" + defectPicture.Pictureid); + _vm.DeletedDefectPictures.Remove(defectPicture); + } + foreach (var defectPicture in addedDefectPictures) + { + defectPicture.DefectId = _vm.DefectTemplate.DefectId; + ApiClient.PostData("api/DefectPictures", defectPicture); + addedDefectPictures.Remove(defectPicture); + } + GetDefects(); + } + catch (Exception e) + { + var msg = new MessageDialog(e.Message).ShowAsync(); + } + } + public void DeleteDefect() + { + try + { + ApiClient.DeleteData("api/Defects/" + _vm.DefectTemplate.DefectId); + BmSingleton.Instance.Defects.Remove(_vm.DefectTemplate); + GetDefects(); + } + catch (Exception e) + { + var msg = new MessageDialog(e.Message).ShowAsync(); + } + } + + public void ClearDefectTemplate() + { + _vm.DefectTemplate = new Defect(); + } + + public async void UploadDefectPicture() + { + if (_vm.DefectTemplate.Pictures == null) _vm.DefectTemplate.Pictures = new ObservableCollection<DefectPicture>(); + var picture = new DefectPicture() { Picture = await ImgurPhotoUploader.UploadPhotoAsync() }; + _vm.DefectTemplate.Pictures.Add(picture); + _vm.AddedDefectPictures.Add(picture); + } + + public void DeleteDefectPicture() + { + _vm.DefectTemplate.Pictures.Remove(_vm.SelectedDefectPicture); + } + + public void DeleteDefectPictureTemp() + { + _vm.DeletedDefectPictures.Add(_vm.SelectedDefectPicture); + _vm.DefectTemplate.Pictures.Remove(_vm.SelectedDefectPicture); + } + + public void CreateDefectComment() + { + try + { + var comment = new DefectComment() + { + Comment = _vm.NewDefectComment.Comment, + DefectId = _vm.DefectTemplate.DefectId, + Name = UserSingleton.Instance.CurrentUser.FirstName + " " + UserSingleton.Instance.CurrentUser.LastName, + Date = DateTimeOffset.Now + }; + if (!string.IsNullOrEmpty(comment.Comment)) + { + ApiClient.PostData("api/DefectComments/", comment); + _vm.DefectTemplate.Comments.Add(comment); + _vm.NewDefectComment = new DefectComment(); + } + } + catch (Exception e) + { + new MessageDialog(e.Message).ShowAsync(); + } + } + #endregion } } diff --git a/ApartmentManager/ApartmentManager/Handler/LoginHandler.cs b/ApartmentManager/ApartmentManager/Handler/LoginHandler.cs index e4d9721..4f93cc1 100644 --- a/ApartmentManager/ApartmentManager/Handler/LoginHandler.cs +++ b/ApartmentManager/ApartmentManager/Handler/LoginHandler.cs @@ -79,6 +79,7 @@ namespace ApartmentManager.Handler bvm.BmHandler.GetApartments(); bvm.BmHandler.GetUsers(); bvm.BmHandler.GetResidents(); + bvm.BmHandler.GetDefects(); appShell.AppFrame.Navigate(typeof(BmMainPage)); } else diff --git a/ApartmentManager/ApartmentManager/Model/Defect.cs b/ApartmentManager/ApartmentManager/Model/Defect.cs index ea305e6..6e78e66 100644 --- a/ApartmentManager/ApartmentManager/Model/Defect.cs +++ b/ApartmentManager/ApartmentManager/Model/Defect.cs @@ -1,8 +1,12 @@ -using System; +using ApartmentManager.Annotations; +using System; +using System.Collections.ObjectModel; +using System.ComponentModel; +using System.Runtime.CompilerServices; namespace ApartmentManager.Model { - public class Defect + public class Defect : INotifyPropertyChanged { public int DefectId { get; set; } public int ApartmentId { get; set; } @@ -11,6 +15,8 @@ namespace ApartmentManager.Model public string Description { get; set; } public string Status { get; set; } public string MainPicture { get; set; } + private ObservableCollection<DefectPicture> _pictures; + private ObservableCollection<DefectComment> _comments; public Defect() { } @@ -23,9 +29,39 @@ namespace ApartmentManager.Model Description = description; Status = status; } + public override string ToString() { return string.Format($"Defect ID: {DefectId}, Apartment number: {ApartmentId}, Name: {Name}, Upload date: {UploadDate}, Description: {Description}, Status: {Status}"); } + + public ObservableCollection<DefectPicture> Pictures + { + get => _pictures; + set + { + _pictures = value; + OnPropertyChanged(nameof(Pictures)); + } + } + + public ObservableCollection<DefectComment> Comments + { + get => _comments; + set + { + _comments = value; + OnPropertyChanged(nameof(Comments)); + } + } + + public event PropertyChangedEventHandler PropertyChanged; + + [NotifyPropertyChangedInvocator] + protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + + } } } diff --git a/ApartmentManager/ApartmentManager/Model/DefectComments.cs b/ApartmentManager/ApartmentManager/Model/DefectComment.cs index a1e6d1e..7610e0b 100644 --- a/ApartmentManager/ApartmentManager/Model/DefectComments.cs +++ b/ApartmentManager/ApartmentManager/Model/DefectComment.cs @@ -1,14 +1,9 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; namespace ApartmentManager.Model { - public class DefectComments + public class DefectComment { - public int CommentId { get; set; } public int DefectId { get; set; } public string Comment { get; set; } diff --git a/ApartmentManager/ApartmentManager/Persistency/ApiClient.cs b/ApartmentManager/ApartmentManager/Persistency/ApiClient.cs index b99f582..8f59a38 100644 --- a/ApartmentManager/ApartmentManager/Persistency/ApiClient.cs +++ b/ApartmentManager/ApartmentManager/Persistency/ApiClient.cs @@ -3,8 +3,6 @@ using System; using System.Net.Http; using System.Net.Http.Headers; using System.Text; -using ApartmentManager.Model; -using ApartmentManager.ViewModel; namespace ApartmentManager.Persistency { diff --git a/ApartmentManager/ApartmentManager/Persistency/PersistenceFacade.cs b/ApartmentManager/ApartmentManager/Persistency/PersistenceFacade.cs deleted file mode 100644 index 3a6f85e..0000000 --- a/ApartmentManager/ApartmentManager/Persistency/PersistenceFacade.cs +++ /dev/null @@ -1,118 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Net.Http; -using System.Net.Http.Headers; -using System.Text; -using System.Threading.Tasks; -using Windows.UI.Popups; -using ApartmentManager.Model; -using Newtonsoft.Json; - -namespace ApartmentManager.Persistency -{ - class PersistenceFacade - { - - const string ServerUrl = "http://localhost:60916"; - HttpClientHandler handler; - - public PersistenceFacade() - { - handler = new HttpClientHandler(); - handler.UseDefaultCredentials = true; - } - - // Get apartments - - public void CreateApartment(Apartment apartment) - { - using (var client = new HttpClient(handler)) - { - client.BaseAddress = new Uri(ServerUrl); - client.DefaultRequestHeaders.Clear(); - client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); - try - { - string postBody = JsonConvert.SerializeObject(apartment); - var response = client.PostAsync("api/apartments/", - new StringContent(postBody, Encoding.UTF8, "application/json")) - .Result; - if (response.IsSuccessStatusCode) - { - new MessageDialog("Success").ShowAsync(); - } - else - { - new MessageDialog("Error").ShowAsync(); - } - - } - catch (Exception ex) - { - new MessageDialog(ex.Message).ShowAsync(); - } - } - } - - ///Get Get Residents/// - public List<Resident> GetApartmentResidents(Resident resident) - { - using (var client = new HttpClient(handler)) - { - client.BaseAddress = new Uri(ServerUrl); - client.DefaultRequestHeaders.Clear(); - client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); - try - { - string residentsBody = "api/residents/" + resident.ApartmentId; - var response = client.GetAsync(residentsBody).Result; - - if (response.IsSuccessStatusCode) - { - var residentList = response.Content.ReadAsAsync<IEnumerable<Resident>>().Result; - return residentList.ToList(); - } - - } - catch (Exception ex) - { - new MessageDialog(ex.Message).ShowAsync(); - } - return null; - } - } - ///Get Get Residents/// - public void CreateResident(Resident resident) - { - using (var client = new HttpClient(handler)) - { - client.BaseAddress = new Uri(ServerUrl); - client.DefaultRequestHeaders.Clear(); - client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); - try - { - string postBody = JsonConvert.SerializeObject(resident); - var response = client.PostAsync("api/Residents", - new StringContent(postBody, Encoding.UTF8, "application/json")) - .Result; - if (response.IsSuccessStatusCode) - { - new MessageDialog("Success").ShowAsync(); - } - else - { - new MessageDialog("Error").ShowAsync(); - } - - } - catch (Exception ex) - { - new MessageDialog(ex.Message).ShowAsync(); - } - } - - } - - } -} diff --git a/ApartmentManager/ApartmentManager/Singletons/BmSingleton.cs b/ApartmentManager/ApartmentManager/Singletons/BmSingleton.cs index 737a1f3..5ee5019 100644 --- a/ApartmentManager/ApartmentManager/Singletons/BmSingleton.cs +++ b/ApartmentManager/ApartmentManager/Singletons/BmSingleton.cs @@ -17,6 +17,7 @@ namespace ApartmentManager.Singletons { Users = new ObservableCollection<User>(); Residents = new ObservableCollection<Resident> |