WPF hinzugefügt

This commit is contained in:
Husky
2021-02-26 18:31:57 +01:00
parent 6761b17f4d
commit 746353e54e
34 changed files with 1261 additions and 37 deletions

View File

@@ -0,0 +1,30 @@
using Microsoft.EntityFrameworkCore;
using Models;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DataStoring.EfCore
{
public class DPContext : DbContext
{
public DbSet<Auftraggeber> AuftraggeberSet { get; set; }
public DbSet<Bauvorhaben> BaustellenSet { get; set; }
public DbSet<Inspektionsobjekt> SewerObjectsSet { get; set; }
public DbSet<MeasureData> MessungenSet { get; set; }
public DbSet<PressureTest> PruefungSet { get; set; }
public DPContext()
{
//Debugger.Break();
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
base.OnConfiguring(optionsBuilder);
optionsBuilder.UseNpgsql("Host = localhost; Database = DP; Username = DP; Password = DP");
}
}
}

View File

@@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="5.0.2" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL.Design" Version="1.1.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DataStoring.Contract\DataStoring.Contract.csproj" />
<ProjectReference Include="..\Models\Models.csproj" />
</ItemGroup>
</Project>

View File

@@ -0,0 +1,49 @@
// <auto-generated />
using DataStoring.EfCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace DataStoring.EfCore.Migrations
{
[DbContext(typeof(DPContext))]
[Migration("20210226140235_Initialcommit")]
partial class Initialcommit
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("Relational:MaxIdentifierLength", 63)
.HasAnnotation("ProductVersion", "5.0.3")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
modelBuilder.Entity("Models.Auftraggeber", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("Ort")
.HasColumnType("text");
b.Property<string>("Strasse")
.HasColumnType("text");
b.Property<string>("Tel")
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("AuftraggeberSet");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,33 @@
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace DataStoring.EfCore.Migrations
{
public partial class Initialcommit : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "AuftraggeberSet",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
Name = table.Column<string>(type: "text", nullable: true),
Ort = table.Column<string>(type: "text", nullable: true),
Strasse = table.Column<string>(type: "text", nullable: true),
Tel = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_AuftraggeberSet", x => x.Id);
});
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "AuftraggeberSet");
}
}
}

View File

@@ -0,0 +1,209 @@
// <auto-generated />
using System;
using DataStoring.EfCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace DataStoring.EfCore.Migrations
{
[DbContext(typeof(DPContext))]
[Migration("20210226145817_TabellenAdded")]
partial class TabellenAdded
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("Relational:MaxIdentifierLength", 63)
.HasAnnotation("ProductVersion", "5.0.3")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
modelBuilder.Entity("Models.Auftraggeber", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("Ort")
.HasColumnType("text");
b.Property<string>("Strasse")
.HasColumnType("text");
b.Property<string>("Tel")
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("AuftraggeberSet");
});
modelBuilder.Entity("Models.Bauvorhaben", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<int?>("AuftraggeberId")
.HasColumnType("integer");
b.Property<string>("Ort")
.HasColumnType("text");
b.Property<string>("Standort")
.HasColumnType("text");
b.Property<string>("Strasse")
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("AuftraggeberId");
b.ToTable("BaustellenSet");
});
modelBuilder.Entity("Models.Inspektionsobjekt", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<int?>("BauvorhabenId")
.HasColumnType("integer");
b.Property<string>("Bemerkung")
.HasColumnType("text");
b.Property<decimal>("Durchmesser")
.HasColumnType("numeric");
b.Property<string>("ObereSchacht")
.HasColumnType("text");
b.Property<decimal>("ObjektLänge")
.HasColumnType("numeric");
b.Property<string>("Objektname")
.HasColumnType("text");
b.Property<string>("UntereSchacht")
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("BauvorhabenId");
b.ToTable("SewerObjectsSet");
});
modelBuilder.Entity("Models.MeasureData", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<DateTime>("Datum")
.HasColumnType("timestamp without time zone");
b.Property<int>("EintragID")
.HasColumnType("integer");
b.Property<int>("MeasureType")
.HasColumnType("integer");
b.Property<string>("Pressure")
.HasColumnType("text");
b.Property<int?>("PressureTestId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("PressureTestId");
b.ToTable("MessungenSet");
});
modelBuilder.Entity("Models.PressureTest", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<int?>("InspektionsobjektId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("InspektionsobjektId");
b.ToTable("PruefungSet");
});
modelBuilder.Entity("Models.Bauvorhaben", b =>
{
b.HasOne("Models.Auftraggeber", "Auftraggeber")
.WithMany("Baustellen")
.HasForeignKey("AuftraggeberId");
b.Navigation("Auftraggeber");
});
modelBuilder.Entity("Models.Inspektionsobjekt", b =>
{
b.HasOne("Models.Bauvorhaben", "Bauvorhaben")
.WithMany("Prüfobjekte")
.HasForeignKey("BauvorhabenId");
b.Navigation("Bauvorhaben");
});
modelBuilder.Entity("Models.MeasureData", b =>
{
b.HasOne("Models.PressureTest", null)
.WithMany("Measuredatas")
.HasForeignKey("PressureTestId");
});
modelBuilder.Entity("Models.PressureTest", b =>
{
b.HasOne("Models.Inspektionsobjekt", null)
.WithMany("pressureTests")
.HasForeignKey("InspektionsobjektId");
});
modelBuilder.Entity("Models.Auftraggeber", b =>
{
b.Navigation("Baustellen");
});
modelBuilder.Entity("Models.Bauvorhaben", b =>
{
b.Navigation("Prüfobjekte");
});
modelBuilder.Entity("Models.Inspektionsobjekt", b =>
{
b.Navigation("pressureTests");
});
modelBuilder.Entity("Models.PressureTest", b =>
{
b.Navigation("Measuredatas");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,136 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace DataStoring.EfCore.Migrations
{
public partial class TabellenAdded : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "BaustellenSet",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
AuftraggeberId = table.Column<int>(type: "integer", nullable: true),
Standort = table.Column<string>(type: "text", nullable: true),
Strasse = table.Column<string>(type: "text", nullable: true),
Ort = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_BaustellenSet", x => x.Id);
table.ForeignKey(
name: "FK_BaustellenSet_AuftraggeberSet_AuftraggeberId",
column: x => x.AuftraggeberId,
principalTable: "AuftraggeberSet",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "SewerObjectsSet",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
BauvorhabenId = table.Column<int>(type: "integer", nullable: true),
Objektname = table.Column<string>(type: "text", nullable: true),
ObereSchacht = table.Column<string>(type: "text", nullable: true),
UntereSchacht = table.Column<string>(type: "text", nullable: true),
ObjektLänge = table.Column<decimal>(type: "numeric", nullable: false),
Durchmesser = table.Column<decimal>(type: "numeric", nullable: false),
Bemerkung = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_SewerObjectsSet", x => x.Id);
table.ForeignKey(
name: "FK_SewerObjectsSet_BaustellenSet_BauvorhabenId",
column: x => x.BauvorhabenId,
principalTable: "BaustellenSet",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "PruefungSet",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
InspektionsobjektId = table.Column<int>(type: "integer", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_PruefungSet", x => x.Id);
table.ForeignKey(
name: "FK_PruefungSet_SewerObjectsSet_InspektionsobjektId",
column: x => x.InspektionsobjektId,
principalTable: "SewerObjectsSet",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateTable(
name: "MessungenSet",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
EintragID = table.Column<int>(type: "integer", nullable: false),
Datum = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
Pressure = table.Column<string>(type: "text", nullable: true),
MeasureType = table.Column<int>(type: "integer", nullable: false),
PressureTestId = table.Column<int>(type: "integer", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_MessungenSet", x => x.Id);
table.ForeignKey(
name: "FK_MessungenSet_PruefungSet_PressureTestId",
column: x => x.PressureTestId,
principalTable: "PruefungSet",
principalColumn: "Id",
onDelete: ReferentialAction.Restrict);
});
migrationBuilder.CreateIndex(
name: "IX_BaustellenSet_AuftraggeberId",
table: "BaustellenSet",
column: "AuftraggeberId");
migrationBuilder.CreateIndex(
name: "IX_MessungenSet_PressureTestId",
table: "MessungenSet",
column: "PressureTestId");
migrationBuilder.CreateIndex(
name: "IX_PruefungSet_InspektionsobjektId",
table: "PruefungSet",
column: "InspektionsobjektId");
migrationBuilder.CreateIndex(
name: "IX_SewerObjectsSet_BauvorhabenId",
table: "SewerObjectsSet",
column: "BauvorhabenId");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "MessungenSet");
migrationBuilder.DropTable(
name: "PruefungSet");
migrationBuilder.DropTable(
name: "SewerObjectsSet");
migrationBuilder.DropTable(
name: "BaustellenSet");
}
}
}

View File

@@ -0,0 +1,207 @@
// <auto-generated />
using System;
using DataStoring.EfCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace DataStoring.EfCore.Migrations
{
[DbContext(typeof(DPContext))]
partial class DPContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("Relational:MaxIdentifierLength", 63)
.HasAnnotation("ProductVersion", "5.0.3")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
modelBuilder.Entity("Models.Auftraggeber", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<string>("Name")
.HasColumnType("text");
b.Property<string>("Ort")
.HasColumnType("text");
b.Property<string>("Strasse")
.HasColumnType("text");
b.Property<string>("Tel")
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("AuftraggeberSet");
});
modelBuilder.Entity("Models.Bauvorhaben", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<int?>("AuftraggeberId")
.HasColumnType("integer");
b.Property<string>("Ort")
.HasColumnType("text");
b.Property<string>("Standort")
.HasColumnType("text");
b.Property<string>("Strasse")
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("AuftraggeberId");
b.ToTable("BaustellenSet");
});
modelBuilder.Entity("Models.Inspektionsobjekt", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<int?>("BauvorhabenId")
.HasColumnType("integer");
b.Property<string>("Bemerkung")
.HasColumnType("text");
b.Property<decimal>("Durchmesser")
.HasColumnType("numeric");
b.Property<string>("ObereSchacht")
.HasColumnType("text");
b.Property<decimal>("ObjektLänge")
.HasColumnType("numeric");
b.Property<string>("Objektname")
.HasColumnType("text");
b.Property<string>("UntereSchacht")
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("BauvorhabenId");
b.ToTable("SewerObjectsSet");
});
modelBuilder.Entity("Models.MeasureData", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<DateTime>("Datum")
.HasColumnType("timestamp without time zone");
b.Property<int>("EintragID")
.HasColumnType("integer");
b.Property<int>("MeasureType")
.HasColumnType("integer");
b.Property<string>("Pressure")
.HasColumnType("text");
b.Property<int?>("PressureTestId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("PressureTestId");
b.ToTable("MessungenSet");
});
modelBuilder.Entity("Models.PressureTest", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn);
b.Property<int?>("InspektionsobjektId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("InspektionsobjektId");
b.ToTable("PruefungSet");
});
modelBuilder.Entity("Models.Bauvorhaben", b =>
{
b.HasOne("Models.Auftraggeber", "Auftraggeber")
.WithMany("Baustellen")
.HasForeignKey("AuftraggeberId");
b.Navigation("Auftraggeber");
});
modelBuilder.Entity("Models.Inspektionsobjekt", b =>
{
b.HasOne("Models.Bauvorhaben", "Bauvorhaben")
.WithMany("Prüfobjekte")
.HasForeignKey("BauvorhabenId");
b.Navigation("Bauvorhaben");
});
modelBuilder.Entity("Models.MeasureData", b =>
{
b.HasOne("Models.PressureTest", null)
.WithMany("Measuredatas")
.HasForeignKey("PressureTestId");
});
modelBuilder.Entity("Models.PressureTest", b =>
{
b.HasOne("Models.Inspektionsobjekt", null)
.WithMany("pressureTests")
.HasForeignKey("InspektionsobjektId");
});
modelBuilder.Entity("Models.Auftraggeber", b =>
{
b.Navigation("Baustellen");
});
modelBuilder.Entity("Models.Bauvorhaben", b =>
{
b.Navigation("Prüfobjekte");
});
modelBuilder.Entity("Models.Inspektionsobjekt", b =>
{
b.Navigation("pressureTests");
});
modelBuilder.Entity("Models.PressureTest", b =>
{
b.Navigation("Measuredatas");
});
#pragma warning restore 612, 618
}
}
}

View File

@@ -0,0 +1,55 @@
using DataStoring.Contract;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
namespace DataStoring.EfCore
{
public class Repository<TEntity> : IRepository<TEntity> where TEntity : class
{
private readonly DPContext _db;
public IQueryable<TEntity> Query => _db.Set<TEntity>();
public Repository(DPContext db)
{
_db = db;
}
public void Delete(int id)
{
try
{
var entity = _db.Set<TEntity>().Find(id);
if(entity == null)
{
throw new Exception("Id not found");
}
}
catch(Exception e)
{
throw new Exception("Cant delete entity with id " + id);
}
}
public void Insert(TEntity entity)
{
_db.Set<TEntity>().Add(entity);
_db.SaveChanges();
}
public void Update(TEntity entity)
{
_db.Entry(entity).State = EntityState.Modified;
_db.SaveChanges();
}
public IEnumerable<TEntity> Get(Expression<Func<TEntity, bool>> filter = null, Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> orderBy = null, string includeProperties = "")
{
IQueryable<TEntity> query = _db.Set<TEntity>();
}
}
}