diff --git a/LoggingClient/LoggingClient/Model/Customer.cs b/LoggingClient/LoggingClient/Model/Customer.cs index 9d758f4..3c547e4 100755 --- a/LoggingClient/LoggingClient/Model/Customer.cs +++ b/LoggingClient/LoggingClient/Model/Customer.cs @@ -9,10 +9,9 @@ namespace LoggingClient.Model { - using Org.BouncyCastle.Asn1.TeleTrust; using System; using System.Collections.Generic; - + public partial class Customer { public long customer_id { get; set; } @@ -39,5 +38,5 @@ namespace LoggingClient.Model this.url = URL; this.password = Password; } - } + } } diff --git a/LoggingClient/LoggingClient/Model/Inventar.edmx b/LoggingClient/LoggingClient/Model/Inventar.edmx index 06d70b4..8a3b258 100755 --- a/LoggingClient/LoggingClient/Model/Inventar.edmx +++ b/LoggingClient/LoggingClient/Model/Inventar.edmx @@ -9,7 +9,7 @@ - + @@ -31,7 +31,7 @@ - + diff --git a/LoggingClient/LoggingClient/Repository/CustomerRepositoryEF.cs b/LoggingClient/LoggingClient/Repository/CustomerRepositoryEF.cs index c2814c2..e93e68d 100755 --- a/LoggingClient/LoggingClient/Repository/CustomerRepositoryEF.cs +++ b/LoggingClient/LoggingClient/Repository/CustomerRepositoryEF.cs @@ -2,56 +2,66 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Windows; namespace LoggingClient.Repository { - public class CustomerRepositoryEF : RepositoryBase + public class CustomerRepositoryEF { - public CustomerRepositoryEF(string connectionString) : base(connectionString) + public CustomerRepositoryEF() { Customers = new List(); } public List Customers { get; set; } - public override string TableName => throw new NotImplementedException(); - public override string ColumnsForSelect => throw new NotImplementedException(); + public void Add(Customer newCustomerEntry) + { + using (var context = new inventarisierungsloesungEntities()) + { + var customer = new Customer() + { + firstname = newCustomerEntry.firstname, + lastname = newCustomerEntry.lastname, + customernumber = newCustomerEntry.customernumber, + kundenkonto_fk = newCustomerEntry.kundenkonto_fk, + tel = newCustomerEntry.tel, + email = newCustomerEntry.email, + url = newCustomerEntry.url, + password = newCustomerEntry.password + }; + context.Customer.Add(customer); + context.SaveChanges(); + } + } - public override string ColumnsForAdd => throw new NotImplementedException(); + public void Delete(Customer entity) + { + using (var context = new inventarisierungsloesungEntities()) + { + var deleteCustomer = context.Customer.Where(c => c.customer_id == entity.customer_id).FirstOrDefault(); + context.Customer.Remove(deleteCustomer); + context.SaveChanges(); + } + } - public override string PrimaryKeyFromTable => throw new NotImplementedException(); - - public override void Add(Customer entity) + public List GetAll(string whereCondition, Dictionary parameterValues) { throw new NotImplementedException(); } - public override void CallStoredProcedure(Customer entity) + public List GetAll() + { + using (var context = new inventarisierungsloesungEntities()) + { + return context.Customer.ToList(); + } + } + + public Customer GetSingle

(P pkValue) { throw new NotImplementedException(); } - public override void Delete(Customer entity) - { - throw new NotImplementedException(); - } - - public override List GetAll(string whereCondition, Dictionary parameterValues) - { - throw new NotImplementedException(); - } - - public override List GetAll() - { - throw new NotImplementedException(); - } - - public override Customer GetSingle

(P pkValue) - { - throw new NotImplementedException(); - } - - public override void Update(Customer entity) + public void Update(Customer entity) { throw new NotImplementedException(); } diff --git a/LoggingClient/LoggingClient/ViewModel/CustomerViewModel.cs b/LoggingClient/LoggingClient/ViewModel/CustomerViewModel.cs index 7940abd..106408d 100755 --- a/LoggingClient/LoggingClient/ViewModel/CustomerViewModel.cs +++ b/LoggingClient/LoggingClient/ViewModel/CustomerViewModel.cs @@ -22,6 +22,7 @@ namespace LoggingClient.ViewModel private ICommand _btnLoadDataClick; private ICommand _btnDeleteDataClick; + private List _customers; public List Customers { get => _customers; @@ -31,12 +32,21 @@ namespace LoggingClient.ViewModel OnPropertyChanged("Customers"); } } - private List _customers; + public Customer NewCustomerEntry { get; set; } - private bool _EfIsChecked; - private bool _LinqIsChecked; + private long _customerId; + public long customer_id + { + get { return _customerId; } + set + { + _customerId = value; + OnPropertyChanged(nameof(customer_id)); + } + } + private bool _EfIsChecked; public bool EfIsChecked { get { return _EfIsChecked; } @@ -47,6 +57,7 @@ namespace LoggingClient.ViewModel } } + private bool _LinqIsChecked; public bool LinqIsChecked { get { return _LinqIsChecked; } @@ -56,6 +67,7 @@ namespace LoggingClient.ViewModel OnPropertyChanged(nameof(LinqIsChecked)); } } + public Customer SelectedItem { get; set; } public CustomerViewModel() { @@ -145,13 +157,10 @@ namespace LoggingClient.ViewModel { if (_EfIsChecked) { - // TODO Implement Repository-Pattern try { - using (var context = new inventarisierungsloesungEntities()) - { - Customers = context.Customer.ToList(); - } + var customerModelRepositoryEF = new CustomerRepositoryEF(); + Customers = customerModelRepositoryEF.GetAll(); } catch (Exception ex) { @@ -162,12 +171,12 @@ namespace LoggingClient.ViewModel { //TODO } - if (!(_EfIsChecked && _LinqIsChecked)) + if (!_EfIsChecked && !_LinqIsChecked) { try { var customerModelRepository = new CustomerRepository(TxtConnectionString); - this.Customers = customerModelRepository.GetAll().ToList(); + Customers = customerModelRepository.GetAll().ToList(); } catch (Exception ex) { @@ -181,22 +190,9 @@ namespace LoggingClient.ViewModel { try { - using (var context = new inventarisierungsloesungEntities()) - { - var Customer = new Customer() - { - customer_id = 6, - firstname = "bvla", - lastname = "asdf", - customernumber = "asdf", - kundenkonto_fk = 99, - tel = "0798765432", - email = "asdf@adsf.asdf", - url = "www.asdf.ch", - password = "password" - }; - - } + var customerModelRepositoryEF = new CustomerRepositoryEF(); + customerModelRepositoryEF.Add(NewCustomerEntry); + Customers = customerModelRepositoryEF.GetAll(); } catch (Exception ex) { @@ -207,7 +203,7 @@ namespace LoggingClient.ViewModel { // TODO } - if (!(_EfIsChecked && _LinqIsChecked)) + if (!_EfIsChecked && !_LinqIsChecked) { try { @@ -223,15 +219,31 @@ namespace LoggingClient.ViewModel } private void DeleteData() { - try + if (_EfIsChecked) { - var customerModelRepository = new CustomerRepository(TxtConnectionString); - customerModelRepository.Delete(this.NewCustomerEntry); - this.Customers = customerModelRepository.GetAll().ToList(); + try + { + var customerModelRepositoryEF = new CustomerRepositoryEF(); + customerModelRepositoryEF.Delete(MySelectedItem); + Customers = customerModelRepositoryEF.GetAll(); + } + catch (Exception ex) + { + MessageBox.Show("Error occurred: " + ex.Message); + } } - catch (Exception ex) + if (!_EfIsChecked && !_LinqIsChecked) { - MessageBox.Show("Error occurred: " + ex.Message); + try + { + var customerModelRepository = new CustomerRepository(TxtConnectionString); + customerModelRepository.Delete(this.NewCustomerEntry); + this.Customers = customerModelRepository.GetAll().ToList(); + } + catch (Exception ex) + { + MessageBox.Show("Error occurred: " + ex.Message); + } } } private void UpdateData() diff --git a/LoggingClient/LoggingClient/Views/CustomerView.xaml b/LoggingClient/LoggingClient/Views/CustomerView.xaml index 3078005..dfc9405 100755 --- a/LoggingClient/LoggingClient/Views/CustomerView.xaml +++ b/LoggingClient/LoggingClient/Views/CustomerView.xaml @@ -21,19 +21,135 @@ - + + +