Objekte können hinzugefügt werdne
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using KanSan.Base.Interfaces;
|
using KanSan.Base.Interfaces;
|
||||||
|
using KanSan.Base.Models;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@@ -19,6 +20,7 @@ namespace KanSan.Base
|
|||||||
this.context = context;
|
this.context = context;
|
||||||
if (context == null) throw new ArgumentNullException("context");
|
if (context == null) throw new ArgumentNullException("context");
|
||||||
this.dbSet = context.Set<TEntity>();
|
this.dbSet = context.Set<TEntity>();
|
||||||
|
|
||||||
}
|
}
|
||||||
public virtual void Delete(TEntity entityToDelete)
|
public virtual void Delete(TEntity entityToDelete)
|
||||||
{
|
{
|
||||||
@@ -33,10 +35,16 @@ namespace KanSan.Base
|
|||||||
Delete(entityToDelete);
|
Delete(entityToDelete);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IEnumerable<TEntity> GetAll(string include)
|
||||||
|
{
|
||||||
|
return dbSet.Include(include);
|
||||||
|
}
|
||||||
|
|
||||||
public IEnumerable<TEntity> Get(Expression<Func<TEntity, bool>> filter = null, Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = null, string includeProperties = "")
|
public IEnumerable<TEntity> Get(Expression<Func<TEntity, bool>> filter = null, Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = null, string includeProperties = "")
|
||||||
{
|
{
|
||||||
IQueryable<TEntity> query = dbSet;
|
IQueryable<TEntity> query = dbSet;
|
||||||
|
|
||||||
|
|
||||||
if (filter != null)
|
if (filter != null)
|
||||||
{
|
{
|
||||||
query = query.Where(filter);
|
query = query.Where(filter);
|
||||||
@@ -72,9 +80,30 @@ namespace KanSan.Base
|
|||||||
dbSet.Add(entity);
|
dbSet.Add(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Update(TEntity entityToUpdate)
|
public IQueryable<TEntity> Include(params Expression<Func<TEntity,object>>[] includeExpressions)
|
||||||
|
{
|
||||||
|
IQueryable<TEntity> query = null;
|
||||||
|
foreach(var include in includeExpressions)
|
||||||
|
{
|
||||||
|
query = dbSet.Include(include);
|
||||||
|
}
|
||||||
|
return query ?? dbSet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(TEntity entityToUpdate, bool attach = true)
|
||||||
|
{
|
||||||
|
if (!attach)
|
||||||
|
{
|
||||||
|
var d = context.Entry(entityToUpdate);
|
||||||
|
if (d != null)
|
||||||
|
{
|
||||||
|
d.State = EntityState.Detached;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
dbSet.Attach(entityToUpdate);
|
dbSet.Attach(entityToUpdate);
|
||||||
|
}
|
||||||
IDatabaseEntry x = (entityToUpdate as IDatabaseEntry);
|
IDatabaseEntry x = (entityToUpdate as IDatabaseEntry);
|
||||||
if(x == null)
|
if(x == null)
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -6,16 +6,18 @@ using System.Text;
|
|||||||
|
|
||||||
namespace KanSan.Base.Interfaces
|
namespace KanSan.Base.Interfaces
|
||||||
{
|
{
|
||||||
public interface IRepository<TEntity> where TEntity: class
|
public interface IRepository<TEntity> where TEntity : class
|
||||||
{
|
{
|
||||||
void Delete(TEntity entityToDelete);
|
void Delete(TEntity entityToDelete);
|
||||||
void Delete(object id);
|
void Delete(object id);
|
||||||
|
IEnumerable<TEntity> GetAll(string include);
|
||||||
IEnumerable<TEntity> Get(
|
IEnumerable<TEntity> Get(
|
||||||
Expression<Func<TEntity, bool>> filter = null,
|
Expression<Func<TEntity, bool>> filter = null,
|
||||||
Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = null,
|
Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = null,
|
||||||
string includeProperties = "");
|
string includeProperties = "");
|
||||||
TEntity GetByID(object id);
|
TEntity GetByID(object id);
|
||||||
void Insert(TEntity entity);
|
void Insert(TEntity entity);
|
||||||
void Update(TEntity entityToUpdate);
|
void Update(TEntity entityToUpdate, bool attach = true);
|
||||||
|
IQueryable<TEntity> Include(params Expression<Func<TEntity, object>>[] includes);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ namespace KanSan.Base
|
|||||||
public UnitOfWork(KanSanContext dbContext)
|
public UnitOfWork(KanSanContext dbContext)
|
||||||
{
|
{
|
||||||
_dbContext = dbContext;
|
_dbContext = dbContext;
|
||||||
|
//_dbContext.ChangeTracker.QueryTrackingBehavior = Microsoft.EntityFrameworkCore.QueryTrackingBehavior.NoTracking;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IRepository<Projekt> ProjekteRepository => _projekte ?? (_projekte = new BaseRepository<Projekt>(_dbContext));
|
public IRepository<Projekt> ProjekteRepository => _projekte ?? (_projekte = new BaseRepository<Projekt>(_dbContext));
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ namespace KanSan.ViewModel.Objekte
|
|||||||
newSewer.StrasseName = Strasse;
|
newSewer.StrasseName = Strasse;
|
||||||
newSewer.ObjektNummer = PunktOben;
|
newSewer.ObjektNummer = PunktOben;
|
||||||
|
|
||||||
unitOfWork.KanaeleRepository.Update(newSewer);
|
unitOfWork.KanaeleRepository.Update(newSewer,false);
|
||||||
unitOfWork.Commit();
|
unitOfWork.Commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -28,6 +28,8 @@ namespace KanSan.ViewModel
|
|||||||
this.selectedBaustelle = selectedBaustelle;
|
this.selectedBaustelle = selectedBaustelle;
|
||||||
//
|
//
|
||||||
List<Sewer> list = unitOfWork.KanaeleRepository.Get(x => x.Baustelle.Equals(selectedBaustelle)).ToList();
|
List<Sewer> list = unitOfWork.KanaeleRepository.Get(x => x.Baustelle.Equals(selectedBaustelle)).ToList();
|
||||||
|
var my = unitOfWork.KanaeleRepository.Include(c => c.PunktOben);
|
||||||
|
|
||||||
var x = list.GroupBy(x => x.StrasseName).Select(x => new ObjekteTransfer
|
var x = list.GroupBy(x => x.StrasseName).Select(x => new ObjekteTransfer
|
||||||
{
|
{
|
||||||
Strassename = x.Key,
|
Strassename = x.Key,
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
|
xmlns:self="clr-namespace:KanSan.ViewModel;assembly=KanSan.ViewModel"
|
||||||
|
xmlns:model="clr-namespace:KanSan.Base.Models;assembly=KanSan.Base"
|
||||||
xmlns:local="clr-namespace:KanSan.UI"
|
xmlns:local="clr-namespace:KanSan.UI"
|
||||||
xmlns:sd ="clr-namespace:KanSan.SampleData"
|
xmlns:sd ="clr-namespace:KanSan.SampleData"
|
||||||
mc:Ignorable="d"
|
mc:Ignorable="d"
|
||||||
@@ -17,18 +19,31 @@
|
|||||||
<RowDefinition Height="50" />
|
<RowDefinition Height="50" />
|
||||||
<RowDefinition Height="50" />
|
<RowDefinition Height="50" />
|
||||||
</Grid.RowDefinitions>
|
</Grid.RowDefinitions>
|
||||||
<TreeView ItemsSource="{Binding KanalObjekte}">
|
<TreeView Name="trvStreets" ItemsSource="{Binding KanalObjekte}">
|
||||||
|
<TreeView.Resources>
|
||||||
|
<HierarchicalDataTemplate DataType="{x:Type self:ObjekteTransfer}" ItemsSource="{Binding Objekte}">
|
||||||
|
<StackPanel Orientation="Horizontal">
|
||||||
|
<TextBlock Text="{Binding Strassename}"/>
|
||||||
|
<TextBlock Text=" [" Foreground="Blue" />
|
||||||
|
<TextBlock Text="{Binding Objekte.Count}" Foreground="Blue" />
|
||||||
|
<TextBlock Text="]" Foreground="Blue" />
|
||||||
|
</StackPanel>
|
||||||
|
</HierarchicalDataTemplate>
|
||||||
|
<DataTemplate DataType="{x:Type model:Sewer}">
|
||||||
|
<StackPanel Orientation="Horizontal">
|
||||||
|
<TextBlock Text="Von [" />
|
||||||
|
<TextBlock Text="{Binding PunktOben.Objektnummer}"/>
|
||||||
|
<TextBlock Text="] Nach [" />
|
||||||
|
<TextBlock Text="{Binding PunktUnten.Objektnummer}" />
|
||||||
|
<TextBlock Text="] DN [" />
|
||||||
|
<TextBlock Text="{Binding DN}"/>
|
||||||
|
<TextBlock Text="] Material ["/>
|
||||||
|
<TextBlock Text="{Binding Material}" />
|
||||||
|
<TextBlock Text="]" />
|
||||||
|
</StackPanel>
|
||||||
|
</DataTemplate>
|
||||||
|
</TreeView.Resources>
|
||||||
</TreeView>
|
</TreeView>
|
||||||
<!--<DataGrid ItemsSource="{Binding KanalObjekte}" Name="dgObjekte" AutoGenerateColumns="False">
|
|
||||||
<DataGrid.Columns>
|
|
||||||
<DataGridTextColumn Header="Strasse" Binding="{Binding StrasseName}" />
|
|
||||||
<DataGridTextColumn Header="Objektnummer" Binding="{Binding ObjektNummer}" />
|
|
||||||
<DataGridTextColumn Header="Durchmesser" Binding="{Binding DN}" />
|
|
||||||
<DataGridTextColumn Header="Material" Binding="{Binding Material}" />
|
|
||||||
</DataGrid.Columns>
|
|
||||||
|
|
||||||
</DataGrid>-->
|
|
||||||
<Button Grid.Row="1" x:Name="ProjektSelect" Content="Objekt Auswählen" />
|
<Button Grid.Row="1" x:Name="ProjektSelect" Content="Objekt Auswählen" />
|
||||||
<Button Grid.Row="2" Name="ProjektEdit" Content="Objekt Editieren" />
|
<Button Grid.Row="2" Name="ProjektEdit" Content="Objekt Editieren" />
|
||||||
<Button Grid.Row="3" Name="ObjektNew" Content="Neue Objekt Hinzufügen" Click="ObjektNew_Click" />
|
<Button Grid.Row="3" Name="ObjektNew" Content="Neue Objekt Hinzufügen" Click="ObjektNew_Click" />
|
||||||
|
|||||||
Reference in New Issue
Block a user