diff --git a/Data/ApplicationConext.cs b/Data/ApplicationConext.cs new file mode 100644 index 0000000..45fb27c --- /dev/null +++ b/Data/ApplicationConext.cs @@ -0,0 +1,26 @@ +using EmployeeManager.Model; +using Microsoft.EntityFrameworkCore; + +namespace EmployeeManager.Data +{ + public class ApplicationConext : DbContext + { + public DbSet Employees { get; set; } + public DbSet PhysicalPersons { get; set; } + public DbSet Salaries { get; set; } + public DbSet 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); + } + } +} diff --git a/EmployeeManager.csproj b/EmployeeManager.csproj index e3e33e3..be33c80 100644 --- a/EmployeeManager.csproj +++ b/EmployeeManager.csproj @@ -8,4 +8,23 @@ true + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + diff --git a/Migrations/20241126112638_InitDB.Designer.cs b/Migrations/20241126112638_InitDB.Designer.cs new file mode 100644 index 0000000..e07b64e --- /dev/null +++ b/Migrations/20241126112638_InitDB.Designer.cs @@ -0,0 +1,203 @@ +// +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 + { + /// + 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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Bid") + .HasColumnType("real"); + + b.Property("EndJob") + .HasColumnType("timestamp with time zone"); + + b.Property("NameJob") + .IsRequired() + .HasColumnType("text"); + + b.Property("PartTimeJob") + .HasColumnType("text"); + + b.Property("PhysicalPersonsId") + .HasColumnType("integer"); + + b.Property("StartJob") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("PhysicalPersonsId"); + + b.ToTable("Employees"); + }); + + modelBuilder.Entity("EmployeeManager.Model.PhysicalPerson", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("text"); + + b.Property("Birthday") + .HasColumnType("timestamp with time zone"); + + b.Property("Gender") + .IsRequired() + .HasColumnType("text"); + + b.Property("NamePhysicalPersons") + .IsRequired() + .HasColumnType("text"); + + b.Property("PatronomicPhysicalPersons") + .IsRequired() + .HasColumnType("text"); + + b.Property("SurnamePhysicalPersons") + .IsRequired() + .HasColumnType("text"); + + b.Property("Telephone") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("PhysicalPersons"); + }); + + modelBuilder.Entity("EmployeeManager.Model.Salary", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CountHours") + .HasColumnType("integer"); + + b.Property("Date") + .HasColumnType("timestamp with time zone"); + + b.Property("EmployeeId") + .HasColumnType("integer"); + + b.Property("Passed") + .HasColumnType("boolean"); + + b.Property("Premium") + .HasColumnType("real"); + + b.Property("PriceHour") + .HasColumnType("real"); + + b.HasKey("Id"); + + b.HasIndex("EmployeeId"); + + b.ToTable("Salaries"); + }); + + modelBuilder.Entity("EmployeeManager.Model.Vacation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("EmployeeId") + .HasColumnType("integer"); + + b.Property("EndData") + .HasColumnType("timestamp with time zone"); + + b.Property("Passed") + .HasColumnType("boolean"); + + b.Property("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 + } + } +} diff --git a/Migrations/20241126112638_InitDB.cs b/Migrations/20241126112638_InitDB.cs new file mode 100644 index 0000000..9fb0730 --- /dev/null +++ b/Migrations/20241126112638_InitDB.cs @@ -0,0 +1,133 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace EmployeeManager.Migrations +{ + /// + public partial class InitDB : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "PhysicalPersons", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + NamePhysicalPersons = table.Column(type: "text", nullable: false), + SurnamePhysicalPersons = table.Column(type: "text", nullable: false), + PatronomicPhysicalPersons = table.Column(type: "text", nullable: false), + Birthday = table.Column(type: "timestamp with time zone", nullable: false), + Gender = table.Column(type: "text", nullable: false), + Address = table.Column(type: "text", nullable: false), + Telephone = table.Column(type: "text", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_PhysicalPersons", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Employees", + columns: table => new + { + Id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + NameJob = table.Column(type: "text", nullable: false), + StartJob = table.Column(type: "timestamp with time zone", nullable: false), + EndJob = table.Column(type: "timestamp with time zone", nullable: true), + PartTimeJob = table.Column(type: "text", nullable: true), + Bid = table.Column(type: "real", nullable: false), + PhysicalPersonsId = table.Column(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(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + CountHours = table.Column(type: "integer", nullable: false), + PriceHour = table.Column(type: "real", nullable: false), + Premium = table.Column(type: "real", nullable: true), + Date = table.Column(type: "timestamp with time zone", nullable: true), + Passed = table.Column(type: "boolean", nullable: false), + EmployeeId = table.Column(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(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + StartData = table.Column(type: "timestamp with time zone", nullable: false), + EndData = table.Column(type: "timestamp with time zone", nullable: false), + Passed = table.Column(type: "boolean", nullable: false), + EmployeeId = table.Column(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"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "Salaries"); + + migrationBuilder.DropTable( + name: "Vacations"); + + migrationBuilder.DropTable( + name: "Employees"); + + migrationBuilder.DropTable( + name: "PhysicalPersons"); + } + } +} diff --git a/Migrations/ApplicationConextModelSnapshot.cs b/Migrations/ApplicationConextModelSnapshot.cs new file mode 100644 index 0000000..c0a298e --- /dev/null +++ b/Migrations/ApplicationConextModelSnapshot.cs @@ -0,0 +1,200 @@ +// +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("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Bid") + .HasColumnType("real"); + + b.Property("EndJob") + .HasColumnType("timestamp with time zone"); + + b.Property("NameJob") + .IsRequired() + .HasColumnType("text"); + + b.Property("PartTimeJob") + .HasColumnType("text"); + + b.Property("PhysicalPersonsId") + .HasColumnType("integer"); + + b.Property("StartJob") + .HasColumnType("timestamp with time zone"); + + b.HasKey("Id"); + + b.HasIndex("PhysicalPersonsId"); + + b.ToTable("Employees"); + }); + + modelBuilder.Entity("EmployeeManager.Model.PhysicalPerson", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("Address") + .IsRequired() + .HasColumnType("text"); + + b.Property("Birthday") + .HasColumnType("timestamp with time zone"); + + b.Property("Gender") + .IsRequired() + .HasColumnType("text"); + + b.Property("NamePhysicalPersons") + .IsRequired() + .HasColumnType("text"); + + b.Property("PatronomicPhysicalPersons") + .IsRequired() + .HasColumnType("text"); + + b.Property("SurnamePhysicalPersons") + .IsRequired() + .HasColumnType("text"); + + b.Property("Telephone") + .IsRequired() + .HasColumnType("text"); + + b.HasKey("Id"); + + b.ToTable("PhysicalPersons"); + }); + + modelBuilder.Entity("EmployeeManager.Model.Salary", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("CountHours") + .HasColumnType("integer"); + + b.Property("Date") + .HasColumnType("timestamp with time zone"); + + b.Property("EmployeeId") + .HasColumnType("integer"); + + b.Property("Passed") + .HasColumnType("boolean"); + + b.Property("Premium") + .HasColumnType("real"); + + b.Property("PriceHour") + .HasColumnType("real"); + + b.HasKey("Id"); + + b.HasIndex("EmployeeId"); + + b.ToTable("Salaries"); + }); + + modelBuilder.Entity("EmployeeManager.Model.Vacation", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("EmployeeId") + .HasColumnType("integer"); + + b.Property("EndData") + .HasColumnType("timestamp with time zone"); + + b.Property("Passed") + .HasColumnType("boolean"); + + b.Property("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 + } + } +} diff --git a/Model/Employee.cs b/Model/Employee.cs index 836cb4e..4049531 100644 --- a/Model/Employee.cs +++ b/Model/Employee.cs @@ -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 Salarys { get; set; } public List Vacations { get; set; } diff --git a/Model/PhysicalPerson.cs b/Model/PhysicalPerson.cs index 4fd1425..fd28c0b 100644 --- a/Model/PhysicalPerson.cs +++ b/Model/PhysicalPerson.cs @@ -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 Employees { get; set; } } } diff --git a/Model/Salary.cs b/Model/Salary.cs index 45ef52e..bf7bdc3 100644 --- a/Model/Salary.cs +++ b/Model/Salary.cs @@ -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; } } } diff --git a/Model/Vacation.cs b/Model/Vacation.cs index ad82e86..ac299bb 100644 --- a/Model/Vacation.cs +++ b/Model/Vacation.cs @@ -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; } } }