Рабочая база данных.

This commit is contained in:
maksim 2024-11-26 15:30:46 +04:00
parent 85f1ed3e2b
commit 09714b4501
9 changed files with 598 additions and 17 deletions

26
Data/ApplicationConext.cs Normal file
View File

@ -0,0 +1,26 @@
using EmployeeManager.Model;
using Microsoft.EntityFrameworkCore;
namespace EmployeeManager.Data
{
public class ApplicationConext : DbContext
{
public DbSet<Employee> Employees { get; set; }
public DbSet<PhysicalPerson> PhysicalPersons { get; set; }
public DbSet<Salary> Salaries { get; set; }
public DbSet<Vacation> Vacations { get; set; }
public ApplicationConext()
{
Database.EnsureCreated();
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (!optionsBuilder.IsConfigured)
{
optionsBuilder.UseNpgsql("Host=localhost;Database=EmployeeManagerDataBase;Username=postgres;Password=23859");
}
base.OnConfiguring(optionsBuilder);
}
}
}

View File

@ -8,4 +8,23 @@
<UseWPF>true</UseWPF>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.Analyzers" Version="3.11.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.10" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.10">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.10">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.1" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.10" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,203 @@
// <auto-generated />
using System;
using EmployeeManager.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace EmployeeManager.Migrations
{
[DbContext(typeof(ApplicationConext))]
[Migration("20241126112638_InitDB")]
partial class InitDB
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.10")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("EmployeeManager.Model.Employee", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<float>("Bid")
.HasColumnType("real");
b.Property<DateTime?>("EndJob")
.HasColumnType("timestamp with time zone");
b.Property<string>("NameJob")
.IsRequired()
.HasColumnType("text");
b.Property<string>("PartTimeJob")
.HasColumnType("text");
b.Property<int?>("PhysicalPersonsId")
.HasColumnType("integer");
b.Property<DateTime>("StartJob")
.HasColumnType("timestamp with time zone");
b.HasKey("Id");
b.HasIndex("PhysicalPersonsId");
b.ToTable("Employees");
});
modelBuilder.Entity("EmployeeManager.Model.PhysicalPerson", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Address")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("Birthday")
.HasColumnType("timestamp with time zone");
b.Property<string>("Gender")
.IsRequired()
.HasColumnType("text");
b.Property<string>("NamePhysicalPersons")
.IsRequired()
.HasColumnType("text");
b.Property<string>("PatronomicPhysicalPersons")
.IsRequired()
.HasColumnType("text");
b.Property<string>("SurnamePhysicalPersons")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Telephone")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("PhysicalPersons");
});
modelBuilder.Entity("EmployeeManager.Model.Salary", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("CountHours")
.HasColumnType("integer");
b.Property<DateTime?>("Date")
.HasColumnType("timestamp with time zone");
b.Property<int?>("EmployeeId")
.HasColumnType("integer");
b.Property<bool>("Passed")
.HasColumnType("boolean");
b.Property<float?>("Premium")
.HasColumnType("real");
b.Property<float>("PriceHour")
.HasColumnType("real");
b.HasKey("Id");
b.HasIndex("EmployeeId");
b.ToTable("Salaries");
});
modelBuilder.Entity("EmployeeManager.Model.Vacation", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int?>("EmployeeId")
.HasColumnType("integer");
b.Property<DateTime>("EndData")
.HasColumnType("timestamp with time zone");
b.Property<bool>("Passed")
.HasColumnType("boolean");
b.Property<DateTime>("StartData")
.HasColumnType("timestamp with time zone");
b.HasKey("Id");
b.HasIndex("EmployeeId");
b.ToTable("Vacations");
});
modelBuilder.Entity("EmployeeManager.Model.Employee", b =>
{
b.HasOne("EmployeeManager.Model.PhysicalPerson", "PhysicalPersons")
.WithMany("Employees")
.HasForeignKey("PhysicalPersonsId");
b.Navigation("PhysicalPersons");
});
modelBuilder.Entity("EmployeeManager.Model.Salary", b =>
{
b.HasOne("EmployeeManager.Model.Employee", "Employees")
.WithMany("Salarys")
.HasForeignKey("EmployeeId");
b.Navigation("Employees");
});
modelBuilder.Entity("EmployeeManager.Model.Vacation", b =>
{
b.HasOne("EmployeeManager.Model.Employee", "Employees")
.WithMany("Vacations")
.HasForeignKey("EmployeeId");
b.Navigation("Employees");
});
modelBuilder.Entity("EmployeeManager.Model.Employee", b =>
{
b.Navigation("Salarys");
b.Navigation("Vacations");
});
modelBuilder.Entity("EmployeeManager.Model.PhysicalPerson", b =>
{
b.Navigation("Employees");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,133 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace EmployeeManager.Migrations
{
/// <inheritdoc />
public partial class InitDB : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "PhysicalPersons",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
NamePhysicalPersons = table.Column<string>(type: "text", nullable: false),
SurnamePhysicalPersons = table.Column<string>(type: "text", nullable: false),
PatronomicPhysicalPersons = table.Column<string>(type: "text", nullable: false),
Birthday = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
Gender = table.Column<string>(type: "text", nullable: false),
Address = table.Column<string>(type: "text", nullable: false),
Telephone = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_PhysicalPersons", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Employees",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
NameJob = table.Column<string>(type: "text", nullable: false),
StartJob = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
EndJob = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
PartTimeJob = table.Column<string>(type: "text", nullable: true),
Bid = table.Column<float>(type: "real", nullable: false),
PhysicalPersonsId = table.Column<int>(type: "integer", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Employees", x => x.Id);
table.ForeignKey(
name: "FK_Employees_PhysicalPersons_PhysicalPersonsId",
column: x => x.PhysicalPersonsId,
principalTable: "PhysicalPersons",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "Salaries",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
CountHours = table.Column<int>(type: "integer", nullable: false),
PriceHour = table.Column<float>(type: "real", nullable: false),
Premium = table.Column<float>(type: "real", nullable: true),
Date = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
Passed = table.Column<bool>(type: "boolean", nullable: false),
EmployeeId = table.Column<int>(type: "integer", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Salaries", x => x.Id);
table.ForeignKey(
name: "FK_Salaries_Employees_EmployeeId",
column: x => x.EmployeeId,
principalTable: "Employees",
principalColumn: "Id");
});
migrationBuilder.CreateTable(
name: "Vacations",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
StartData = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
EndData = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
Passed = table.Column<bool>(type: "boolean", nullable: false),
EmployeeId = table.Column<int>(type: "integer", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Vacations", x => x.Id);
table.ForeignKey(
name: "FK_Vacations_Employees_EmployeeId",
column: x => x.EmployeeId,
principalTable: "Employees",
principalColumn: "Id");
});
migrationBuilder.CreateIndex(
name: "IX_Employees_PhysicalPersonsId",
table: "Employees",
column: "PhysicalPersonsId");
migrationBuilder.CreateIndex(
name: "IX_Salaries_EmployeeId",
table: "Salaries",
column: "EmployeeId");
migrationBuilder.CreateIndex(
name: "IX_Vacations_EmployeeId",
table: "Vacations",
column: "EmployeeId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Salaries");
migrationBuilder.DropTable(
name: "Vacations");
migrationBuilder.DropTable(
name: "Employees");
migrationBuilder.DropTable(
name: "PhysicalPersons");
}
}
}

View File

@ -0,0 +1,200 @@
// <auto-generated />
using System;
using EmployeeManager.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace EmployeeManager.Migrations
{
[DbContext(typeof(ApplicationConext))]
partial class ApplicationConextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.10")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("EmployeeManager.Model.Employee", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<float>("Bid")
.HasColumnType("real");
b.Property<DateTime?>("EndJob")
.HasColumnType("timestamp with time zone");
b.Property<string>("NameJob")
.IsRequired()
.HasColumnType("text");
b.Property<string>("PartTimeJob")
.HasColumnType("text");
b.Property<int?>("PhysicalPersonsId")
.HasColumnType("integer");
b.Property<DateTime>("StartJob")
.HasColumnType("timestamp with time zone");
b.HasKey("Id");
b.HasIndex("PhysicalPersonsId");
b.ToTable("Employees");
});
modelBuilder.Entity("EmployeeManager.Model.PhysicalPerson", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Address")
.IsRequired()
.HasColumnType("text");
b.Property<DateTime>("Birthday")
.HasColumnType("timestamp with time zone");
b.Property<string>("Gender")
.IsRequired()
.HasColumnType("text");
b.Property<string>("NamePhysicalPersons")
.IsRequired()
.HasColumnType("text");
b.Property<string>("PatronomicPhysicalPersons")
.IsRequired()
.HasColumnType("text");
b.Property<string>("SurnamePhysicalPersons")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Telephone")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("PhysicalPersons");
});
modelBuilder.Entity("EmployeeManager.Model.Salary", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("CountHours")
.HasColumnType("integer");
b.Property<DateTime?>("Date")
.HasColumnType("timestamp with time zone");
b.Property<int?>("EmployeeId")
.HasColumnType("integer");
b.Property<bool>("Passed")
.HasColumnType("boolean");
b.Property<float?>("Premium")
.HasColumnType("real");
b.Property<float>("PriceHour")
.HasColumnType("real");
b.HasKey("Id");
b.HasIndex("EmployeeId");
b.ToTable("Salaries");
});
modelBuilder.Entity("EmployeeManager.Model.Vacation", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int?>("EmployeeId")
.HasColumnType("integer");
b.Property<DateTime>("EndData")
.HasColumnType("timestamp with time zone");
b.Property<bool>("Passed")
.HasColumnType("boolean");
b.Property<DateTime>("StartData")
.HasColumnType("timestamp with time zone");
b.HasKey("Id");
b.HasIndex("EmployeeId");
b.ToTable("Vacations");
});
modelBuilder.Entity("EmployeeManager.Model.Employee", b =>
{
b.HasOne("EmployeeManager.Model.PhysicalPerson", "PhysicalPersons")
.WithMany("Employees")
.HasForeignKey("PhysicalPersonsId");
b.Navigation("PhysicalPersons");
});
modelBuilder.Entity("EmployeeManager.Model.Salary", b =>
{
b.HasOne("EmployeeManager.Model.Employee", "Employees")
.WithMany("Salarys")
.HasForeignKey("EmployeeId");
b.Navigation("Employees");
});
modelBuilder.Entity("EmployeeManager.Model.Vacation", b =>
{
b.HasOne("EmployeeManager.Model.Employee", "Employees")
.WithMany("Vacations")
.HasForeignKey("EmployeeId");
b.Navigation("Employees");
});
modelBuilder.Entity("EmployeeManager.Model.Employee", b =>
{
b.Navigation("Salarys");
b.Navigation("Vacations");
});
modelBuilder.Entity("EmployeeManager.Model.PhysicalPerson", b =>
{
b.Navigation("Employees");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -6,13 +6,13 @@ namespace EmployeeManager.Model
public class Employee
{
public int Id { get; set; }
public string NameJob { get; set; }
public string NameJob { get; set; } = string.Empty;
public DateTime StartJob { get; set; }
public DateTime EndJob { get; set; }
public string PartTimeJob { get; set; }
public DateTime? EndJob { get; set; }
public string? PartTimeJob { get; set; }
public float Bid { get; set; }
public int PhisicalPersonsId { get; set; }
public virtual PhysicalPerson PhisicalPersons { get; set; }
public int? PhysicalPersonsId { get; set; }
public virtual PhysicalPerson? PhysicalPersons { get; set; }
public List<Salary> Salarys { get; set; }
public List<Vacation> Vacations { get; set; }

View File

@ -9,13 +9,13 @@ namespace EmployeeManager.Model
public class PhysicalPerson
{
public int Id { get; set; }
public string Name { get; set; }
public string Surname { get; set; }
public string Patronomic { get; set; }
public string NamePhysicalPersons { get; set; } = string.Empty;
public string SurnamePhysicalPersons { get; set; } = string.Empty;
public string PatronomicPhysicalPersons { get; set; } = string.Empty;
public DateTime Birthday { get; set; }
public string Gender { get; set; }
public string Address { get; set; }
public string Telephone { get; set; }
public string Gender { get; set; } = string.Empty;
public string Address { get; set; } = string.Empty;
public string Telephone { get; set; } = string.Empty;
public List<Employee> Employees { get; set; }
}
}

View File

@ -11,10 +11,10 @@ namespace EmployeeManager.Model
public int Id { get; set; }
public int CountHours { get; set; }
public float PriceHour { get; set; }
public float Premium { get; set; }
public DateTime Date { get; set; }
public float? Premium { get; set; }
public DateTime? Date { get; set; }
public bool Passed { get; set; }
public int EmployeeId { get; set; }
public virtual Employee Employee { get; set; }
public int? EmployeeId { get; set; }
public virtual Employee? Employees { get; set; }
}
}

View File

@ -12,7 +12,7 @@ namespace EmployeeManager.Model
public DateTime StartData { get; set; }
public DateTime EndData { get; set; }
public bool Passed { get; set; }
public int EmployeeId { get; set; }
public virtual Employee Employee { get; set; }
public int? EmployeeId { get; set; }
public virtual Employee? Employees { get; set; }
}
}