From b67302361b60bd32417b3e4c5896b33bf44bbe4e Mon Sep 17 00:00:00 2001 From: Francesco Date: Sat, 8 Aug 2020 15:27:39 +0200 Subject: [PATCH] Prepared ViewModel for Linq, Add CustomerRepositoryLinq --- LoggingClient/LoggingClient/App.config | 1 + .../LoggingClient/LoggingClient.csproj | 99 +++++++++++++++++++ .../Repository/CustomerRepository.cs | 1 - .../Repository/CustomerRepositoryLinq.cs | 61 ++++++++++++ .../ViewModel/CustomerViewModel.cs | 72 ++++++++++++-- 5 files changed, 225 insertions(+), 9 deletions(-) create mode 100755 LoggingClient/LoggingClient/Repository/CustomerRepositoryLinq.cs diff --git a/LoggingClient/LoggingClient/App.config b/LoggingClient/LoggingClient/App.config index 2950779..0ad6cd9 100644 --- a/LoggingClient/LoggingClient/App.config +++ b/LoggingClient/LoggingClient/App.config @@ -16,6 +16,7 @@ + diff --git a/LoggingClient/LoggingClient/LoggingClient.csproj b/LoggingClient/LoggingClient/LoggingClient.csproj index 25b0884..3417f4a 100644 --- a/LoggingClient/LoggingClient/LoggingClient.csproj +++ b/LoggingClient/LoggingClient/LoggingClient.csproj @@ -86,6 +86,87 @@ MSBuild:Compile Designer + + DataAccessLayer.tt + + + DataAccessLayer.tt + + + DataAccessLayer.tt + + + DataAccessLayer.tt + + + DataAccessLayer.tt + + + True + True + DataAccessLayer.Context.tt + + + True + True + DataAccessLayer.tt + + + True + True + DataAccessLayer.edmx + + + DataAccessLayer.tt + + + DataAccessLayer.tt + + + DataAccessLayer.tt + + + DataAccessLayer.tt + + + DataAccessLayer.tt + + + DataAccessLayer.tt + + + DataAccessLayer.tt + + + DataAccessLayer.tt + + + DataAccessLayer.tt + + + DataAccessLayer.tt + + + DataAccessLayer.tt + + + DataAccessLayer.tt + + + DataAccessLayer.tt + + + DataAccessLayer.tt + + + DataAccessLayer.tt + + + DataAccessLayer.tt + + + DataAccessLayer.tt + Inventar.tt @@ -110,6 +191,7 @@ + @@ -180,6 +262,13 @@ EntityModelCodeGenerator Inventar.Designer.cs + + EntityModelCodeGenerator + DataAccessLayer.Designer.cs + + + DataAccessLayer.edmx + Inventar.edmx @@ -195,6 +284,16 @@ + + TextTemplatingFileGenerator + DataAccessLayer.edmx + DataAccessLayer.Context.cs + + + TextTemplatingFileGenerator + DataAccessLayer.edmx + DataAccessLayer.cs + TextTemplatingFileGenerator Inventar.Context.cs diff --git a/LoggingClient/LoggingClient/Repository/CustomerRepository.cs b/LoggingClient/LoggingClient/Repository/CustomerRepository.cs index 83ae162..c2c6a78 100755 --- a/LoggingClient/LoggingClient/Repository/CustomerRepository.cs +++ b/LoggingClient/LoggingClient/Repository/CustomerRepository.cs @@ -22,7 +22,6 @@ namespace LoggingClient.Repository public override string PrimaryKeyFromTable => "customer_id"; public List Customers { get; set; } - public Customer _Customers { get; set; } public override void Add(Customer entity) { diff --git a/LoggingClient/LoggingClient/Repository/CustomerRepositoryLinq.cs b/LoggingClient/LoggingClient/Repository/CustomerRepositoryLinq.cs new file mode 100755 index 0000000..d7820da --- /dev/null +++ b/LoggingClient/LoggingClient/Repository/CustomerRepositoryLinq.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Data; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LoggingClient.Repository +{ + public class CustomerRepositoryLinq : RepositoryBase + { + public List Customers { get; set; } + public CustomerRepositoryLinq(string connectionString) : base(connectionString) + { + Customers = new List(); + } + + public override string TableName => throw new NotImplementedException(); + + public override string ColumnsForSelect => throw new NotImplementedException(); + + public override string ColumnsForAdd => throw new NotImplementedException(); + + public override string PrimaryKeyFromTable => throw new NotImplementedException(); + + public override void Add(Customer entity) + { + throw new NotImplementedException(); + } + + public override void CallStoredProcedure(Customer entity) + { + 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) + { + throw new NotImplementedException(); + } + } +} diff --git a/LoggingClient/LoggingClient/ViewModel/CustomerViewModel.cs b/LoggingClient/LoggingClient/ViewModel/CustomerViewModel.cs index 106408d..ab6255e 100755 --- a/LoggingClient/LoggingClient/ViewModel/CustomerViewModel.cs +++ b/LoggingClient/LoggingClient/ViewModel/CustomerViewModel.cs @@ -169,7 +169,15 @@ namespace LoggingClient.ViewModel } if (_LinqIsChecked) { - //TODO + try + { + var customerModelRepositoryLinq = new CustomerRepositoryLinq(TxtConnectionString); + Customers = customerModelRepositoryLinq.GetAll(); + } + catch (Exception ex) + { + MessageBox.Show("Error occurred: " + ex.Message); + } } if (!_EfIsChecked && !_LinqIsChecked) { @@ -201,7 +209,16 @@ namespace LoggingClient.ViewModel } if (_LinqIsChecked) { - // TODO + try + { + var customerModelRepositoryLinq = new CustomerRepositoryLinq(TxtConnectionString); + customerModelRepositoryLinq.Add(NewCustomerEntry); + Customers = customerModelRepositoryLinq.GetAll(); + } + catch (Exception ex) + { + MessageBox.Show("Error occurred: " + ex.Message); + } } if (!_EfIsChecked && !_LinqIsChecked) { @@ -232,6 +249,19 @@ namespace LoggingClient.ViewModel MessageBox.Show("Error occurred: " + ex.Message); } } + if (_LinqIsChecked) + { + try + { + var customerModelRepositoryLinq = new CustomerRepositoryLinq(TxtConnectionString); + customerModelRepositoryLinq.Delete(MySelectedItem); + Customers = customerModelRepositoryLinq.GetAll(); + } + catch (Exception ex) + { + MessageBox.Show("Error occurred: " + ex.Message); + } + } if (!_EfIsChecked && !_LinqIsChecked) { try @@ -248,15 +278,41 @@ namespace LoggingClient.ViewModel } private void UpdateData() { - try + if (_EfIsChecked) { - var customerModelRepository = new CustomerRepository(TxtConnectionString); - customerModelRepository.Update(this.NewCustomerEntry); - this.Customers = customerModelRepository.GetAll().ToList(); + try + { + //DOTO + } + catch (Exception ex) + { + MessageBox.Show("Error occurred: " + ex.Message); + } } - catch (Exception ex) + if (_LinqIsChecked) { - MessageBox.Show("Error occurred: " + ex.Message); + try + { + //DOTO + } + catch (Exception ex) + { + MessageBox.Show("Error occurred: " + ex.Message); + } + } + if (!_EfIsChecked && !_LinqIsChecked) + { + + try + { + var customerModelRepository = new CustomerRepository(TxtConnectionString); + customerModelRepository.Update(this.NewCustomerEntry); + this.Customers = customerModelRepository.GetAll().ToList(); + } + catch (Exception ex) + { + MessageBox.Show("Error occurred: " + ex.Message); + } } }