From a4e186c78fde6225cb2c66c4c1393bec349b9a4d Mon Sep 17 00:00:00 2001 From: m1aksim1 Date: Mon, 13 Mar 2023 20:53:28 +0400 Subject: [PATCH] =?UTF-8?q?=D0=93=D0=B5=D0=BD=D0=B5=D1=80=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=BA=D0=BE=D0=B4=D0=B0=20=D0=BD=D0=B0=20=D0=BE?= =?UTF-8?q?=D1=81=D0=BD=D0=BE=D0=B2=D0=B5=20=D1=81=D1=83=D1=89=D0=B5=D1=81?= =?UTF-8?q?=D1=82=D0=B2=D1=83=D1=8E=D1=89=D0=B5=D0=B9=20=D0=B1=D0=B0=D0=B7?= =?UTF-8?q?=D1=8B=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WorkTime/WorkTime/ConfigConnection.txt | 5 + WorkTime/WorkTime/CourseContext.cs | 209 ++++++++++++++++++ WorkTime/WorkTime/Models/Allowance.cs | 13 ++ WorkTime/WorkTime/Models/AllowanceWorker.cs | 11 + WorkTime/WorkTime/Models/Customer.cs | 13 ++ WorkTime/WorkTime/Models/Post.cs | 15 ++ WorkTime/WorkTime/Models/Project.cs | 27 +++ .../Models/Views/GetSalaryOnCurrentMonth.cs | 15 ++ .../Models/Views/SalaryWithAllowance.cs | 15 ++ WorkTime/WorkTime/Models/Worker.cs | 23 ++ WorkTime/WorkTime/Models/WorkingDay.cs | 17 ++ WorkTime/WorkTime/Program.cs | 18 +- WorkTime/WorkTime/WorkTime.csproj | 12 +- 13 files changed, 389 insertions(+), 4 deletions(-) create mode 100644 WorkTime/WorkTime/ConfigConnection.txt create mode 100644 WorkTime/WorkTime/CourseContext.cs create mode 100644 WorkTime/WorkTime/Models/Allowance.cs create mode 100644 WorkTime/WorkTime/Models/AllowanceWorker.cs create mode 100644 WorkTime/WorkTime/Models/Customer.cs create mode 100644 WorkTime/WorkTime/Models/Post.cs create mode 100644 WorkTime/WorkTime/Models/Project.cs create mode 100644 WorkTime/WorkTime/Models/Views/GetSalaryOnCurrentMonth.cs create mode 100644 WorkTime/WorkTime/Models/Views/SalaryWithAllowance.cs create mode 100644 WorkTime/WorkTime/Models/Worker.cs create mode 100644 WorkTime/WorkTime/Models/WorkingDay.cs diff --git a/WorkTime/WorkTime/ConfigConnection.txt b/WorkTime/WorkTime/ConfigConnection.txt new file mode 100644 index 0000000..695706c --- /dev/null +++ b/WorkTime/WorkTime/ConfigConnection.txt @@ -0,0 +1,5 @@ +Host=169.254.89.101; +Port=5432; +Database=course; +Username=postgres; +Password=root; \ No newline at end of file diff --git a/WorkTime/WorkTime/CourseContext.cs b/WorkTime/WorkTime/CourseContext.cs new file mode 100644 index 0000000..ecf15c9 --- /dev/null +++ b/WorkTime/WorkTime/CourseContext.cs @@ -0,0 +1,209 @@ +using System; +using System.Collections.Generic; +using Microsoft.EntityFrameworkCore; +using WorkTime.Models; +using WorkTime.Models.Views; + +namespace WorkTime; + +public partial class CourseContext : DbContext +{ + public CourseContext() + { + } + + public CourseContext(DbContextOptions options) + : base(options) + { + } + + public virtual DbSet Allowances { get; set; } + + public virtual DbSet AllowanceWorkers { get; set; } + + public virtual DbSet Customers { get; set; } + + public virtual DbSet GetSalaryOnCurrentMonths { get; set; } + + public virtual DbSet Posts { get; set; } + + public virtual DbSet Projects { get; set; } + + public virtual DbSet SalaryWithAllowances { get; set; } + + public virtual DbSet Workers { get; set; } + + public virtual DbSet WorkingDays { get; set; } + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) +#warning To protect potentially sensitive information in your connection string, you should move it out of source code. You can avoid scaffolding the connection string by using the Name= syntax to read it from configuration - see https://go.microsoft.com/fwlink/?linkid=2131148. For more guidance on storing connection strings, see http://go.microsoft.com/fwlink/?LinkId=723263. + => optionsBuilder.UseNpgsql("Host=169.254.89.101;Port=5432;Database=course;Username=postgres;Password=root"); + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.Id).HasName("allowance_pkey"); + + entity.ToTable("allowance"); + + entity.Property(e => e.Id) + .ValueGeneratedNever() + .HasColumnName("id"); + entity.Property(e => e.Name) + .HasMaxLength(64) + .HasColumnName("name"); + entity.Property(e => e.Percent) + .HasPrecision(6, 5) + .HasColumnName("percent"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => new { e.AllowanceId, e.WorkerId }).HasName("allowance_worker_pkey"); + + entity.ToTable("allowance_worker"); + + entity.Property(e => e.AllowanceId).HasColumnName("allowance_id"); + entity.Property(e => e.WorkerId).HasColumnName("worker_id"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.Id).HasName("customer_pkey"); + + entity.ToTable("customer"); + + entity.Property(e => e.Id).HasColumnName("id"); + entity.Property(e => e.Name) + .HasMaxLength(64) + .HasColumnName("name"); + }); + + modelBuilder.Entity(entity => + { + entity + .HasNoKey() + .ToView("get_salary_on_current_month"); + + entity.Property(e => e.Hours).HasColumnName("hours"); + entity.Property(e => e.Name) + .HasColumnType("character varying") + .HasColumnName("name"); + entity.Property(e => e.Salary).HasColumnName("salary"); + entity.Property(e => e.WorkerId).HasColumnName("worker_id"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.Id).HasName("post_pkey"); + + entity.ToTable("post"); + + entity.Property(e => e.Id) + .ValueGeneratedNever() + .HasColumnName("id"); + entity.Property(e => e.Name) + .HasMaxLength(64) + .HasColumnName("name"); + entity.Property(e => e.Salary) + .HasPrecision(10, 2) + .HasColumnName("salary"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.Id).HasName("project_pkey"); + + entity.ToTable("project"); + + entity.Property(e => e.Id).HasColumnName("id"); + entity.Property(e => e.Description).HasColumnName("description"); + entity.Property(e => e.IdCustomer).HasColumnName("id_customer"); + entity.Property(e => e.IdDeveloper).HasColumnName("id_developer"); + entity.Property(e => e.IdManager).HasColumnName("id_manager"); + entity.Property(e => e.Name) + .HasColumnType("character varying") + .HasColumnName("name"); + entity.Property(e => e.Ready).HasColumnName("ready"); + + entity.HasOne(d => d.IdCustomerNavigation).WithMany(p => p.Projects) + .HasForeignKey(d => d.IdCustomer) + .HasConstraintName("project_id_customer_fkey"); + + entity.HasOne(d => d.IdDeveloperNavigation).WithMany(p => p.ProjectIdDeveloperNavigations) + .HasForeignKey(d => d.IdDeveloper) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("project_id_developer_fkey"); + + entity.HasOne(d => d.IdManagerNavigation).WithMany(p => p.ProjectIdManagerNavigations) + .HasForeignKey(d => d.IdManager) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("project_id_manager_fkey"); + }); + + modelBuilder.Entity(entity => + { + entity + .HasNoKey() + .ToView("salary_with_allowance"); + + entity.Property(e => e.CalcSalary).HasColumnName("calc_salary"); + entity.Property(e => e.Id).HasColumnName("id"); + entity.Property(e => e.Name) + .HasMaxLength(64) + .HasColumnName("name"); + entity.Property(e => e.Должность) + .HasMaxLength(64) + .HasColumnName("должность"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.Id).HasName("worker_pkey"); + + entity.ToTable("worker"); + + entity.Property(e => e.Id).HasColumnName("id"); + entity.Property(e => e.DateEmployment) + .HasColumnType("timestamp without time zone") + .HasColumnName("date_employment"); + entity.Property(e => e.Name) + .HasMaxLength(64) + .HasColumnName("name"); + entity.Property(e => e.PostId).HasColumnName("post_id"); + + entity.HasOne(d => d.Post).WithMany(p => p.Workers) + .HasForeignKey(d => d.PostId) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("worker_id_post_fkey"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.Id).HasName("working_day_pkey"); + + entity.ToTable("working_day"); + + entity.Property(e => e.Id) + .ValueGeneratedNever() + .HasColumnName("id"); + entity.Property(e => e.DateEnd) + .HasColumnType("timestamp without time zone") + .HasColumnName("date_end"); + entity.Property(e => e.DateStart) + .HasColumnType("timestamp without time zone") + .HasColumnName("date_start"); + entity.Property(e => e.WorkerId).HasColumnName("worker_id"); + + entity.HasOne(d => d.Worker).WithMany(p => p.WorkingDays) + .HasForeignKey(d => d.WorkerId) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("working_day_worker_id_fkey"); + }); + + OnModelCreatingPartial(modelBuilder); + } + + partial void OnModelCreatingPartial(ModelBuilder modelBuilder); +} diff --git a/WorkTime/WorkTime/Models/Allowance.cs b/WorkTime/WorkTime/Models/Allowance.cs new file mode 100644 index 0000000..90e70a9 --- /dev/null +++ b/WorkTime/WorkTime/Models/Allowance.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; + +namespace WorkTime.Models; + +public partial class Allowance +{ + public int Id { get; set; } + + public string Name { get; set; } = null!; + + public decimal Percent { get; set; } +} diff --git a/WorkTime/WorkTime/Models/AllowanceWorker.cs b/WorkTime/WorkTime/Models/AllowanceWorker.cs new file mode 100644 index 0000000..cc16362 --- /dev/null +++ b/WorkTime/WorkTime/Models/AllowanceWorker.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; + +namespace WorkTime.Models; + +public partial class AllowanceWorker +{ + public int AllowanceId { get; set; } + + public int WorkerId { get; set; } +} diff --git a/WorkTime/WorkTime/Models/Customer.cs b/WorkTime/WorkTime/Models/Customer.cs new file mode 100644 index 0000000..ebc201a --- /dev/null +++ b/WorkTime/WorkTime/Models/Customer.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; + +namespace WorkTime.Models; + +public partial class Customer +{ + public int Id { get; set; } + + public string Name { get; set; } = null!; + + public virtual ICollection Projects { get; } = new List(); +} diff --git a/WorkTime/WorkTime/Models/Post.cs b/WorkTime/WorkTime/Models/Post.cs new file mode 100644 index 0000000..9bfa154 --- /dev/null +++ b/WorkTime/WorkTime/Models/Post.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; + +namespace WorkTime.Models; + +public partial class Post +{ + public int Id { get; set; } + + public string Name { get; set; } = null!; + + public decimal Salary { get; set; } + + public virtual ICollection Workers { get; } = new List(); +} diff --git a/WorkTime/WorkTime/Models/Project.cs b/WorkTime/WorkTime/Models/Project.cs new file mode 100644 index 0000000..a21725d --- /dev/null +++ b/WorkTime/WorkTime/Models/Project.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; + +namespace WorkTime.Models; + +public partial class Project +{ + public int Id { get; set; } + + public string Name { get; set; } = null!; + + public int? IdCustomer { get; set; } + + public int IdManager { get; set; } + + public bool Ready { get; set; } + + public int IdDeveloper { get; set; } + + public string Description { get; set; } = null!; + + public virtual Customer? IdCustomerNavigation { get; set; } + + public virtual Worker IdDeveloperNavigation { get; set; } = null!; + + public virtual Worker IdManagerNavigation { get; set; } = null!; +} diff --git a/WorkTime/WorkTime/Models/Views/GetSalaryOnCurrentMonth.cs b/WorkTime/WorkTime/Models/Views/GetSalaryOnCurrentMonth.cs new file mode 100644 index 0000000..1e447ad --- /dev/null +++ b/WorkTime/WorkTime/Models/Views/GetSalaryOnCurrentMonth.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; + +namespace WorkTime.Models.Views; + +public partial class GetSalaryOnCurrentMonth +{ + public int? WorkerId { get; set; } + + public string? Name { get; set; } + + public decimal? Hours { get; set; } + + public decimal? Salary { get; set; } +} diff --git a/WorkTime/WorkTime/Models/Views/SalaryWithAllowance.cs b/WorkTime/WorkTime/Models/Views/SalaryWithAllowance.cs new file mode 100644 index 0000000..7320ff7 --- /dev/null +++ b/WorkTime/WorkTime/Models/Views/SalaryWithAllowance.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; + +namespace WorkTime.Models.Views; + +public partial class SalaryWithAllowance +{ + public int? Id { get; set; } + + public string? Name { get; set; } + + public string? Должность { get; set; } + + public decimal? CalcSalary { get; set; } +} diff --git a/WorkTime/WorkTime/Models/Worker.cs b/WorkTime/WorkTime/Models/Worker.cs new file mode 100644 index 0000000..a8c7731 --- /dev/null +++ b/WorkTime/WorkTime/Models/Worker.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; + +namespace WorkTime.Models; + +public partial class Worker +{ + public int Id { get; set; } + + public string Name { get; set; } = null!; + + public int PostId { get; set; } + + public DateTime DateEmployment { get; set; } + + public virtual Post Post { get; set; } = null!; + + public virtual ICollection ProjectIdDeveloperNavigations { get; } = new List(); + + public virtual ICollection ProjectIdManagerNavigations { get; } = new List(); + + public virtual ICollection WorkingDays { get; } = new List(); +} diff --git a/WorkTime/WorkTime/Models/WorkingDay.cs b/WorkTime/WorkTime/Models/WorkingDay.cs new file mode 100644 index 0000000..75a3377 --- /dev/null +++ b/WorkTime/WorkTime/Models/WorkingDay.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; + +namespace WorkTime.Models; + +public partial class WorkingDay +{ + public int Id { get; set; } + + public int WorkerId { get; set; } + + public DateTime DateStart { get; set; } + + public DateTime DateEnd { get; set; } + + public virtual Worker Worker { get; set; } = null!; +} diff --git a/WorkTime/WorkTime/Program.cs b/WorkTime/WorkTime/Program.cs index 3751555..f6e3454 100644 --- a/WorkTime/WorkTime/Program.cs +++ b/WorkTime/WorkTime/Program.cs @@ -1,2 +1,16 @@ -// See https://aka.ms/new-console-template for more information -Console.WriteLine("Hello, World!"); +namespace WorkTime +{ + class Program + { + public static void Main(string[] args) + { + using (var context = new CourseContext()) + { + foreach (var salary in context.SalaryWithAllowances) + { + Console.WriteLine($"{salary.Name} {salary.CalcSalary}"); + } + } + } + } +} \ No newline at end of file diff --git a/WorkTime/WorkTime/WorkTime.csproj b/WorkTime/WorkTime/WorkTime.csproj index 74abf5c..e5eaa66 100644 --- a/WorkTime/WorkTime/WorkTime.csproj +++ b/WorkTime/WorkTime/WorkTime.csproj @@ -1,4 +1,4 @@ - + Exe @@ -7,4 +7,12 @@ enable - + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + \ No newline at end of file