Add Update Functionality on Customer

This commit is contained in:
francesco 2020-08-24 19:47:30 +02:00
parent c12615bc1b
commit d23f8cf465
6 changed files with 74 additions and 19 deletions

View File

@ -90,6 +90,7 @@
<Compile Include="Model\Customer.cs">
<DependentUpon>Inventar.tt</DependentUpon>
</Compile>
<Compile Include="Model\CustomerLinq.cs" />
<Compile Include="Model\Inventar.Context.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>

View File

@ -9,28 +9,16 @@
namespace LoggingClient.Model
{
using System.Data.Linq.Mapping;
[Table(Name = "inventarisierungsloesung.Customer")]
public partial class Customer
{
[Column(IsPrimaryKey = true, Name = "CustomerId")]
public long customer_id { get; set; }
[Column(Name ="FirstName")]
public string firstname { get; set; }
[Column(Name = "LastName")]
public string lastname { get; set; }
[Column(Name = "CustomerNumber")]
public string customernumber { get; set; }
[Column(Name = "KundenKontoFK")]
public long kundenkonto_fk { get; set; }
[Column(Name = "PhoneNumber")]
public string tel { get; set; }
[Column(Name = "EMail")]
public string email { get; set; }
[Column(Name = "URL")]
public string url { get; set; }
[Column(Name = "Password")]
public string password { get; set; }
public Customer() { }

View File

@ -0,0 +1,42 @@
using System.Data.Linq.Mapping;
namespace LoggingClient.Model
{
[Table(Name = "inventarisierungsloesung.Customer")]
public class CustomerLinq
{
[Column(IsPrimaryKey = true, Name = "CustomerId")]
public long customer_id { get; set; }
[Column(Name = "FirstName")]
public string firstname { get; set; }
[Column(Name = "LastName")]
public string lastname { get; set; }
[Column(Name = "CustomerNumber")]
public string customernumber { get; set; }
[Column(Name = "KundenKontoFK")]
public long kundenkonto_fk { get; set; }
[Column(Name = "PhoneNumber")]
public string tel { get; set; }
[Column(Name = "EMail")]
public string email { get; set; }
[Column(Name = "URL")]
public string url { get; set; }
[Column(Name = "Password")]
public string password { get; set; }
public CustomerLinq() { }
public CustomerLinq(long Id, string FirstName, string LastName, string CustomerNumber, long Customer_fk, string PhoneNumber, string EMail, string URL, string Password)
{
this.customer_id = Id;
this.firstname = FirstName;
this.lastname = LastName;
this.customernumber = CustomerNumber;
this.kundenkonto_fk = Customer_fk;
this.tel = PhoneNumber;
this.email = EMail;
this.url = URL;
this.password = Password;
}
}
}

View File

@ -1,6 +1,7 @@
using LoggingClient.Model;
using System;
using System.Collections.Generic;
using System.Data.Entity.Migrations;
using System.Linq;
namespace LoggingClient.Repository
@ -75,7 +76,11 @@ namespace LoggingClient.Repository
public void Update(Customer entity)
{
throw new NotImplementedException();
using (var context = new inventarisierungsloesungEntities())
{
context.Customer.AddOrUpdate(entity);
context.SaveChanges();
}
}
}
}

View File

@ -64,11 +64,11 @@ namespace LoggingClient.Repository
throw new NotImplementedException();
}
public IQueryable<Customer> GetAll()
public List<Customer> GetAll()
{
using (var context = new inventarisierungsloesungEntities())
{
return context.Customer.AsQueryable();
return context.Customer.ToList();
}
}
@ -79,7 +79,22 @@ namespace LoggingClient.Repository
public void Update(Customer entity)
{
throw new NotImplementedException();
using (var context = new inventarisierungsloesungEntities())
{
var x = (from c in context.Customer
where (c.customer_id == entity.customer_id)
select c).SingleOrDefault();
x.firstname = entity.firstname;
x.lastname = entity.lastname;
x.customernumber = entity.customernumber;
x.kundenkonto_fk = entity.kundenkonto_fk;
x.tel = entity.tel;
x.email = entity.email;
x.url = entity.url;
x.password = entity.password;
context.SaveChanges();
}
}
List<Customer> IRepositoryBase<Customer>.GetAll()

View File

@ -282,7 +282,9 @@ namespace LoggingClient.ViewModel
{
try
{
//DOTO
var customerModelRepositoryEF = new CustomerRepositoryEF();
customerModelRepositoryEF.Update(MySelectedItem);
Customers = customerModelRepositoryEF.GetAll();
}
catch (Exception ex)
{
@ -293,7 +295,9 @@ namespace LoggingClient.ViewModel
{
try
{
//DOTO
var customerModelRepositoryLinq = new CustomerRepositoryLinq();
customerModelRepositoryLinq.Update(MySelectedItem);
Customers = customerModelRepositoryLinq.GetAll().ToList();
}
catch (Exception ex)
{