From b9aa21de49f96aa2e951aeec702dc3d16368351b Mon Sep 17 00:00:00 2001 From: marcinzelent Date: Mon, 22 May 2017 13:00:42 +0200 Subject: Fixed more errors. --- .../ApartmentManager/ApartmentManager.csproj | 2 +- .../ViewModel/ApartmenViewModel.cs | 89 -------------- .../ViewModel/ApartmentViewModel.cs | 89 ++++++++++++++ .../Controllers/AllResidentsController.cs | 133 --------------------- .../Controllers/ApartmentResidentsController.cs | 133 --------------------- .../Controllers/ResidentsController.cs | 15 ++- ApartmentManager/HousingWebApi/DataModel.cs | 18 --- .../HousingWebApi/HousingWebApi.csproj | 4 - .../HousingWebApi/Models/AllResident.cs | 15 --- .../HousingWebApi/Models/ApartmentResident.cs | 37 ------ 10 files changed, 100 insertions(+), 435 deletions(-) delete mode 100644 ApartmentManager/ApartmentManager/ViewModel/ApartmenViewModel.cs create mode 100644 ApartmentManager/ApartmentManager/ViewModel/ApartmentViewModel.cs delete mode 100644 ApartmentManager/HousingWebApi/Controllers/AllResidentsController.cs delete mode 100644 ApartmentManager/HousingWebApi/Controllers/ApartmentResidentsController.cs delete mode 100644 ApartmentManager/HousingWebApi/Models/AllResident.cs delete mode 100644 ApartmentManager/HousingWebApi/Models/ApartmentResident.cs diff --git a/ApartmentManager/ApartmentManager/ApartmentManager.csproj b/ApartmentManager/ApartmentManager/ApartmentManager.csproj index 373b8f7..f267a50 100644 --- a/ApartmentManager/ApartmentManager/ApartmentManager.csproj +++ b/ApartmentManager/ApartmentManager/ApartmentManager.csproj @@ -118,7 +118,7 @@ - + ApartmentDefectPage.xaml diff --git a/ApartmentManager/ApartmentManager/ViewModel/ApartmenViewModel.cs b/ApartmentManager/ApartmentManager/ViewModel/ApartmenViewModel.cs deleted file mode 100644 index eceed48..0000000 --- a/ApartmentManager/ApartmentManager/ViewModel/ApartmenViewModel.cs +++ /dev/null @@ -1,89 +0,0 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Runtime.CompilerServices; -using System.Text; -using System.Threading.Tasks; -using System.Windows.Input; -using ApartmentManager.Annotations; -using ApartmentManager.Common; -using ApartmentManager.Handler; -using ApartmentManager.Model; -using ApartmentManager.Persistency; -using ApartmentManager.Singletons; - -namespace ApartmentManager.ViewModel -{ - public class ApartmentViewModel : INotifyPropertyChanged - { - public ApartmentHandler ApartmentHandler { get; set; } - public CatalogSingleton CatalogSingleton { get; set; } - public UserSingleton UserSingleton { get; set; } - - private User _newUser; - private Resident _newResident; - private Defect _newDefect; - - public static int ApartmentNumber { get; set; } - - - public ICommand CreateResidentCommand { get; set; } - public ICommand DeleteResidentCommand { get; set; } - public ICommand UpdateResidentCommand { get; set; } - public ICommand UploadResidentPhoto { get; set; } - - public ApartmentViewModel() - { - NewUser = new User(); - NewResident = new Resident(); - - ApartmentHandler = new ApartmentHandler(this); - CatalogSingleton = CatalogSingleton.Instance; - UserSingleton = UserSingleton.Instance; - //ApartmentNumber = UserSingleton.CurrentUser.ApartmentNr; - - UploadResidentPhoto = new RelayCommand(ApartmentHandler.UploadResidentPhoto); - CreateResidentCommand = new RelayCommand(ApartmentHandler.CreateResident); - DeleteResidentCommand = new RelayCommand(ApartmentHandler.DeleteResident); - UpdateResidentCommand = new RelayCommand(ApartmentHandler.UpdateResident); - ApartmentHandler.GetApartmentResidents(); - ApartmentHandler.GetApartment(); - } - - public Defect NewDefect - { - get => _newDefect; - set - { - _newDefect = value; - OnPropertyChanged(); - } - } - public User NewUser - { - get => _newUser; - set - { - _newUser = value; - OnPropertyChanged(); - } - } - public Resident NewResident - { - get => _newResident; - set - { - _newResident = value; - OnPropertyChanged(); - } - } - public event PropertyChangedEventHandler PropertyChanged; - - [NotifyPropertyChangedInvocator] - protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) - { - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); - } - } -} \ No newline at end of file diff --git a/ApartmentManager/ApartmentManager/ViewModel/ApartmentViewModel.cs b/ApartmentManager/ApartmentManager/ViewModel/ApartmentViewModel.cs new file mode 100644 index 0000000..2e2e0ea --- /dev/null +++ b/ApartmentManager/ApartmentManager/ViewModel/ApartmentViewModel.cs @@ -0,0 +1,89 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Runtime.CompilerServices; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Input; +using ApartmentManager.Annotations; +using ApartmentManager.Common; +using ApartmentManager.Handler; +using ApartmentManager.Model; +using ApartmentManager.Persistency; +using ApartmentManager.Singletons; + +namespace ApartmentManager.ViewModel +{ + public class ApartmentViewModel : INotifyPropertyChanged + { + public ApartmentHandler ApartmentHandler { get; set; } + public CatalogSingleton CatalogSingleton { get; set; } + public UserSingleton UserSingleton { get; set; } + + private User _newUser; + private Resident _newResident; + private Defect _newDefect; + + public static int ApartmentNumber { get; set; } + + + public ICommand CreateResidentCommand { get; set; } + public ICommand DeleteResidentCommand { get; set; } + public ICommand UpdateResidentCommand { get; set; } + public ICommand UploadResidentPhoto { get; set; } + + public ApartmentViewModel() + { + NewUser = new User(); + NewResident = new Resident(); + + ApartmentHandler = new ApartmentHandler(this); + CatalogSingleton = CatalogSingleton.Instance; + UserSingleton = UserSingleton.Instance; + ApartmentNumber = UserSingleton.CurrentUser.ApartmentId; + + UploadResidentPhoto = new RelayCommand(ApartmentHandler.UploadResidentPhoto); + CreateResidentCommand = new RelayCommand(ApartmentHandler.CreateResident); + DeleteResidentCommand = new RelayCommand(ApartmentHandler.DeleteResident); + UpdateResidentCommand = new RelayCommand(ApartmentHandler.UpdateResident); + ApartmentHandler.GetApartmentResidents(); + ApartmentHandler.GetApartment(); + } + + public Defect NewDefect + { + get => _newDefect; + set + { + _newDefect = value; + OnPropertyChanged(); + } + } + public User NewUser + { + get => _newUser; + set + { + _newUser = value; + OnPropertyChanged(); + } + } + public Resident NewResident + { + get => _newResident; + set + { + _newResident = value; + OnPropertyChanged(); + } + } + public event PropertyChangedEventHandler PropertyChanged; + + [NotifyPropertyChangedInvocator] + protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + } +} \ No newline at end of file diff --git a/ApartmentManager/HousingWebApi/Controllers/AllResidentsController.cs b/ApartmentManager/HousingWebApi/Controllers/AllResidentsController.cs deleted file mode 100644 index 046a385..0000000 --- a/ApartmentManager/HousingWebApi/Controllers/AllResidentsController.cs +++ /dev/null @@ -1,133 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Data; -using System.Data.Entity; -using System.Data.Entity.Infrastructure; -using System.Linq; -using System.Net; -using System.Net.Http; -using System.Web.Http; -using System.Web.Http.Description; -using HousingWebApi; - -namespace HousingWebApi.Controllers -{ - public class AllResidentsController : ApiController - { - private DataModel db = new DataModel(); - - // GET: api/AllResidents - public IQueryable GetAllResidents() - { - return db.AllResidents; - } - - // GET: api/AllResidents/5 - [ResponseType(typeof(AllResident))] - public IHttpActionResult GetAllResident(string id) - { - AllResident allResident = db.AllResidents.Find(id); - if (allResident == null) - { - return NotFound(); - } - - return Ok(allResident); - } - - // PUT: api/AllResidents/5 - [ResponseType(typeof(void))] - public IHttpActionResult PutAllResident(string id, AllResident allResident) - { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - - if (id != allResident.FirstName) - { - return BadRequest(); - } - - db.Entry(allResident).State = EntityState.Modified; - - try - { - db.SaveChanges(); - } - catch (DbUpdateConcurrencyException) - { - if (!AllResidentExists(id)) - { - return NotFound(); - } - else - { - throw; - } - } - - return StatusCode(HttpStatusCode.NoContent); - } - - // POST: api/AllResidents - [ResponseType(typeof(AllResident))] - public IHttpActionResult PostAllResident(AllResident allResident) - { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - - db.AllResidents.Add(allResident); - - try - { - db.SaveChanges(); - } - catch (DbUpdateException) - { - if (AllResidentExists(allResident.FirstName)) - { - return Conflict(); - } - else - { - throw; - } - } - - return CreatedAtRoute("DefaultApi", new { id = allResident.FirstName }, allResident); - } - - // DELETE: api/AllResidents/5 - [ResponseType(typeof(AllResident))] - public IHttpActionResult DeleteAllResident(string id) - { - AllResident allResident = db.AllResidents.Find(id); - if (allResident == null) - { - return NotFound(); - } - - db.AllResidents.Remove(allResident); - db.SaveChanges(); - - return Ok(allResident); - } - - protected override void Dispose(bool disposing) - { - if (disposing) - { - db.Dispose(); - } - base.Dispose(disposing); - } - - private bool AllResidentExists(string id) - { - return db.AllResidents.Count(e => e.FirstName == id) > 0; - } - } -} \ No newline at end of file diff --git a/ApartmentManager/HousingWebApi/Controllers/ApartmentResidentsController.cs b/ApartmentManager/HousingWebApi/Controllers/ApartmentResidentsController.cs deleted file mode 100644 index a754255..0000000 --- a/ApartmentManager/HousingWebApi/Controllers/ApartmentResidentsController.cs +++ /dev/null @@ -1,133 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Data; -using System.Data.Entity; -using System.Data.Entity.Infrastructure; -using System.Linq; -using System.Net; -using System.Net.Http; -using System.Web.Http; -using System.Web.Http.Description; -using HousingWebApi; - -namespace HousingWebApi.Controllers -{ - public class ApartmentResidentsController : ApiController - { - private DataModel db = new DataModel(); - - // GET: api/ApartmentResidents - public IQueryable GetApartmentResidents() - { - return db.ApartmentResidents; - } - - // GET: api/ApartmentResidents/5 - [ResponseType(typeof(ApartmentResident))] - public IHttpActionResult GetApartmentResident(int id) - { - ApartmentResident apartmentResident = db.ApartmentResidents.Find(id); - if (apartmentResident == null) - { - return NotFound(); - } - - return Ok(apartmentResident); - } - - // PUT: api/ApartmentResidents/5 - [ResponseType(typeof(void))] - public IHttpActionResult PutApartmentResident(int id, ApartmentResident apartmentResident) - { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - - if (id != apartmentResident.ApartmentNumber) - { - return BadRequest(); - } - - db.Entry(apartmentResident).State = EntityState.Modified; - - try - { - db.SaveChanges(); - } - catch (DbUpdateConcurrencyException) - { - if (!ApartmentResidentExists(id)) - { - return NotFound(); - } - else - { - throw; - } - } - - return StatusCode(HttpStatusCode.NoContent); - } - - // POST: api/ApartmentResidents - [ResponseType(typeof(ApartmentResident))] - public IHttpActionResult PostApartmentResident(ApartmentResident apartmentResident) - { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - - db.ApartmentResidents.Add(apartmentResident); - - try - { - db.SaveChanges(); - } - catch (DbUpdateException) - { - if (ApartmentResidentExists(apartmentResident.ApartmentNumber)) - { - return Conflict(); - } - else - { - throw; - } - } - - return CreatedAtRoute("DefaultApi", new { id = apartmentResident.ApartmentNumber }, apartmentResident); - } - - // DELETE: api/ApartmentResidents/5 - [ResponseType(typeof(ApartmentResident))] - public IHttpActionResult DeleteApartmentResident(int id) - { - ApartmentResident apartmentResident = db.ApartmentResidents.Find(id); - if (apartmentResident == null) - { - return NotFound(); - } - - db.ApartmentResidents.Remove(apartmentResident); - db.SaveChanges(); - - return Ok(apartmentResident); - } - - protected override void Dispose(bool disposing) - { - if (disposing) - { - db.Dispose(); - } - base.Dispose(disposing); - } - - private bool ApartmentResidentExists(int id) - { - return db.ApartmentResidents.Count(e => e.ApartmentNumber == id) > 0; - } - } -} \ No newline at end of file diff --git a/ApartmentManager/HousingWebApi/Controllers/ResidentsController.cs b/ApartmentManager/HousingWebApi/Controllers/ResidentsController.cs index ebb0188..80d5741 100644 --- a/ApartmentManager/HousingWebApi/Controllers/ResidentsController.cs +++ b/ApartmentManager/HousingWebApi/Controllers/ResidentsController.cs @@ -1,14 +1,10 @@ -using System; -using System.Collections.Generic; -using System.Data; +using System.Data; using System.Data.Entity; using System.Data.Entity.Infrastructure; using System.Linq; using System.Net; -using System.Net.Http; using System.Web.Http; using System.Web.Http.Description; -using HousingWebApi; namespace HousingWebApi.Controllers { @@ -16,6 +12,15 @@ namespace HousingWebApi.Controllers { private DataModel db = new DataModel(); + [Route("api/ApartmentResidents/{id}")] + public IQueryable GetResidents(int id) + { + var roomlist = from resident in db.Residents + where (resident.ApartmentId == id) + select resident; + return roomlist; + } + // GET: api/Residents public IQueryable GetResidents() { diff --git a/ApartmentManager/HousingWebApi/DataModel.cs b/ApartmentManager/HousingWebApi/DataModel.cs index 0b953a6..00f4811 100644 --- a/ApartmentManager/HousingWebApi/DataModel.cs +++ b/ApartmentManager/HousingWebApi/DataModel.cs @@ -23,8 +23,6 @@ namespace HousingWebApi public virtual DbSet PastUsers { get; set; } public virtual DbSet Residents { get; set; } public virtual DbSet Users { get; set; } - public virtual DbSet AllResidents { get; set; } - public virtual DbSet ApartmentResidents { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { @@ -172,22 +170,6 @@ namespace HousingWebApi modelBuilder.Entity() .Property(e => e.Email) .IsUnicode(false); - - modelBuilder.Entity() - .Property(e => e.FirstName) - .IsUnicode(false); - - modelBuilder.Entity() - .Property(e => e.FirstName) - .IsUnicode(false); - - modelBuilder.Entity() - .Property(e => e.LastName) - .IsUnicode(false); - - modelBuilder.Entity() - .Property(e => e.Email) - .IsUnicode(false); } } } diff --git a/ApartmentManager/HousingWebApi/HousingWebApi.csproj b/ApartmentManager/HousingWebApi/HousingWebApi.csproj index 18a8c73..117dc9d 100644 --- a/ApartmentManager/HousingWebApi/HousingWebApi.csproj +++ b/ApartmentManager/HousingWebApi/HousingWebApi.csproj @@ -151,12 +151,8 @@ - - - - diff --git a/ApartmentManager/HousingWebApi/Models/AllResident.cs b/ApartmentManager/HousingWebApi/Models/AllResident.cs deleted file mode 100644 index 655ee84..0000000 --- a/ApartmentManager/HousingWebApi/Models/AllResident.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace HousingWebApi -{ - using System; - using System.Collections.Generic; - using System.ComponentModel.DataAnnotations; - using System.ComponentModel.DataAnnotations.Schema; - using System.Data.Entity.Spatial; - - public partial class AllResident - { - [Key] - [StringLength(20)] - public string FirstName { get; set; } - } -} diff --git a/ApartmentManager/HousingWebApi/Models/ApartmentResident.cs b/ApartmentManager/HousingWebApi/Models/ApartmentResident.cs deleted file mode 100644 index 092c95f..0000000 --- a/ApartmentManager/HousingWebApi/Models/ApartmentResident.cs +++ /dev/null @@ -1,37 +0,0 @@ -namespace HousingWebApi -{ - using System; - using System.Collections.Generic; - using System.ComponentModel.DataAnnotations; - using System.ComponentModel.DataAnnotations.Schema; - using System.Data.Entity.Spatial; - - public partial class ApartmentResident - { - [Key] - [Column(Order = 0)] - [DatabaseGenerated(DatabaseGeneratedOption.None)] - public int ApartmentNumber { get; set; } - - [Key] - [Column(Order = 1)] - [StringLength(20)] - public string FirstName { get; set; } - - [Key] - [Column(Order = 2)] - [StringLength(20)] - public string LastName { get; set; } - - [Column(TypeName = "date")] - public DateTime? BirthDate { get; set; } - - public int? PhoneNo { get; set; } - - [StringLength(30)] - public string Email { get; set; } - - [Column(TypeName = "image")] - public byte[] Picture { get; set; } - } -} -- cgit v1.2.3 From 899b172cdc92776d5405858853c4e68a5edf7e88 Mon Sep 17 00:00:00 2001 From: Donatas Adamonis Date: Mon, 22 May 2017 17:34:39 +0200 Subject: boardmemebermanageApartment methods commented cannot build. --- .../View/BoardMemberManageApartment.xaml.cs | 23 +++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/ApartmentManager/ApartmentManager/View/BoardMemberManageApartment.xaml.cs b/ApartmentManager/ApartmentManager/View/BoardMemberManageApartment.xaml.cs index 81fa3a8..aa5f0c3 100644 --- a/ApartmentManager/ApartmentManager/View/BoardMemberManageApartment.xaml.cs +++ b/ApartmentManager/ApartmentManager/View/BoardMemberManageApartment.xaml.cs @@ -14,6 +14,7 @@ using Windows.UI.Xaml.Input; using Windows.UI.Xaml.Media; using Windows.UI.Xaml.Navigation; using ApartmentManager.Model; +using ApartmentManager.Singletons; // The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=234238 @@ -39,17 +40,17 @@ namespace ApartmentManager.View this.Frame.Navigate(typeof(BoardMemberCreateApartmentPage)); } - private bool ApartmentFilter(object item) - { - if (String.IsNullOrEmpty(TextFilter.Text)) - return true; - else - return ((item as Apartment).BoardMemberCatalogSingleton.IndexOf(TextFilter.Text, StringComparison.OrdinalIgnoreCase) >= 0); - } + //private bool ApartmentFilter(object item) + //{ + // if (String.IsNullOrEmpty(TextFilter.Text)) + // return true; + // else + // return ((item as Apartment).BoardMemberCatalogSingleton.IndexOf(TextFilter.Text, StringComparison.OrdinalIgnoreCase) >= 0); + //} - private void txtFilter_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e) - { - CollectionViewSource.GetDefaultView(lvUsers.ItemsSource).Refresh(); - } + //private void txtFilter_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e) + //{ + // CollectionViewSource.GetDefaultView(lvUsers.ItemsSource).Refresh(); + //} } } -- cgit v1.2.3 From ad0091548a5b023b74a3f72ca8086cd83b6cc760 Mon Sep 17 00:00:00 2001 From: Donatas Adamonis Date: Mon, 22 May 2017 20:24:01 +0200 Subject: Updated personalInfoPage and residents page --- .../ApartmentManager/View/ApartmentPage.xaml | 2 +- .../View/ApartmentResidentsPage.xaml | 47 +++++++++++++++++++++- .../ApartmentManager/View/PersonalInfoPage.xaml | 45 +++++++++------------ 3 files changed, 65 insertions(+), 29 deletions(-) diff --git a/ApartmentManager/ApartmentManager/View/ApartmentPage.xaml b/ApartmentManager/ApartmentManager/View/ApartmentPage.xaml index acf1cbc..6a3f6c1 100644 --- a/ApartmentManager/ApartmentManager/View/ApartmentPage.xaml +++ b/ApartmentManager/ApartmentManager/View/ApartmentPage.xaml @@ -35,7 +35,7 @@ - + diff --git a/ApartmentManager/ApartmentManager/View/ApartmentResidentsPage.xaml b/ApartmentManager/ApartmentManager/View/ApartmentResidentsPage.xaml index ff394b3..ea4711e 100644 --- a/ApartmentManager/ApartmentManager/View/ApartmentResidentsPage.xaml +++ b/ApartmentManager/ApartmentManager/View/ApartmentResidentsPage.xaml @@ -14,10 +14,53 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + -