From 6c835fd8e5017290bc848c0e213c8863ab7da85d Mon Sep 17 00:00:00 2001 From: kotcheshir73 Date: Sat, 3 Apr 2021 09:45:22 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=BE=D1=82=D1=80=D1=83=D0=B4=D0=BD?= =?UTF-8?q?=D0=B8=D0=BA=D0=B8=20=D0=B2=20=D0=91=D0=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Common/DatabaseCore/DatabaseContext.cs | 16 +- .../20210403054350_AddEmployee.Designer.cs | 379 ++++++++++++++++++ .../Migrations/20210403054350_AddEmployee.cs | 178 ++++++++ .../DatabaseContextModelSnapshot.cs | 167 +++++++- .../Models/Department/Employee.cs | 89 ++++ .../Models/Department/EmployeeEmployeePost.cs | 49 +++ .../Models/Department/EmployeePost.cs | 36 ++ 7 files changed, 910 insertions(+), 4 deletions(-) create mode 100644 DepartmentPortal/Common/DatabaseCore/Migrations/20210403054350_AddEmployee.Designer.cs create mode 100644 DepartmentPortal/Common/DatabaseCore/Migrations/20210403054350_AddEmployee.cs create mode 100644 DepartmentPortal/Common/DatabaseCore/Models/Department/Employee.cs create mode 100644 DepartmentPortal/Common/DatabaseCore/Models/Department/EmployeeEmployeePost.cs create mode 100644 DepartmentPortal/Common/DatabaseCore/Models/Department/EmployeePost.cs diff --git a/DepartmentPortal/Common/DatabaseCore/DatabaseContext.cs b/DepartmentPortal/Common/DatabaseCore/DatabaseContext.cs index 30bbab1..c4adc76 100644 --- a/DepartmentPortal/Common/DatabaseCore/DatabaseContext.cs +++ b/DepartmentPortal/Common/DatabaseCore/DatabaseContext.cs @@ -1,4 +1,5 @@ -using DatabaseCore.Models.Security; +using DatabaseCore.Models.Department; +using DatabaseCore.Models.Security; using Microsoft.EntityFrameworkCore; namespace DatabaseCore @@ -30,13 +31,24 @@ namespace DatabaseCore modelBuilder.Entity().HasIndex(s => s.RoleName).IsUnique(); modelBuilder.Entity().HasIndex(s => s.UserName).IsUnique(); + + modelBuilder.Entity().HasIndex(s => s.EmployeePostName).IsUnique(); + + modelBuilder.Entity().HasIndex(p => new { p.FirstName, p.LastName, p.Patronymic }).IsUnique(); } - + #region Security public virtual DbSet Accesses { set; get; } public virtual DbSet EnviromentSettings { set; get; } public virtual DbSet Roles { set; get; } public virtual DbSet Users { set; get; } public virtual DbSet UserRoles { set; get; } + #endregion + + #region Department + public virtual DbSet EmployeePosts { set; get; } + public virtual DbSet Employees { set; get; } + public virtual DbSet EmployeeEmployeePosts { set; get; } + #endregion } } \ No newline at end of file diff --git a/DepartmentPortal/Common/DatabaseCore/Migrations/20210403054350_AddEmployee.Designer.cs b/DepartmentPortal/Common/DatabaseCore/Migrations/20210403054350_AddEmployee.Designer.cs new file mode 100644 index 0000000..5e186e6 --- /dev/null +++ b/DepartmentPortal/Common/DatabaseCore/Migrations/20210403054350_AddEmployee.Designer.cs @@ -0,0 +1,379 @@ +// +using System; +using DatabaseCore; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +namespace DatabaseCore.Migrations +{ + [DbContext(typeof(DatabaseContext))] + [Migration("20210403054350_AddEmployee")] + partial class AddEmployee + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("Relational:MaxIdentifierLength", 128) + .HasAnnotation("ProductVersion", "5.0.4") + .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + + modelBuilder.Entity("DatabaseCore.Models.Department.Employee", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("Address") + .HasColumnType("nvarchar(max)"); + + b.Property("DateBirth") + .HasColumnType("datetime2"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateDelete") + .HasColumnType("datetime2"); + + b.Property("Description") + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .HasColumnType("nvarchar(max)"); + + b.Property("FirstName") + .HasColumnType("nvarchar(450)"); + + b.Property("GroupElectricalSafety") + .HasColumnType("nvarchar(max)"); + + b.Property("HomeNumber") + .HasColumnType("nvarchar(max)"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("LastName") + .HasColumnType("nvarchar(450)"); + + b.Property("MobileNumber") + .HasColumnType("nvarchar(max)"); + + b.Property("Patronymic") + .HasColumnType("nvarchar(450)"); + + b.Property("Photo") + .HasColumnType("varbinary(max)"); + + b.Property("UserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("FirstName", "LastName", "Patronymic") + .IsUnique() + .HasFilter("[FirstName] IS NOT NULL AND [LastName] IS NOT NULL AND [Patronymic] IS NOT NULL"); + + b.ToTable("Employees"); + }); + + modelBuilder.Entity("DatabaseCore.Models.Department.EmployeeEmployeePost", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateDelete") + .HasColumnType("datetime2"); + + b.Property("EmployeeId") + .HasColumnType("uniqueidentifier"); + + b.Property("EmployeePostId") + .HasColumnType("uniqueidentifier"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("IsExternalCombination") + .HasColumnType("bit"); + + b.Property("IsInternalCombination") + .HasColumnType("bit"); + + b.Property("Rate") + .HasColumnType("decimal(18,2)"); + + b.HasKey("Id"); + + b.HasIndex("EmployeeId"); + + b.HasIndex("EmployeePostId"); + + b.ToTable("EmployeeEmployeePosts"); + }); + + modelBuilder.Entity("DatabaseCore.Models.Department.EmployeePost", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateDelete") + .HasColumnType("datetime2"); + + b.Property("EmployeePostName") + .HasColumnType("nvarchar(450)"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("Order") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("EmployeePostName") + .IsUnique() + .HasFilter("[EmployeePostName] IS NOT NULL"); + + b.ToTable("EmployeePosts"); + }); + + modelBuilder.Entity("DatabaseCore.Models.Security.Access", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("AccessOperation") + .HasColumnType("int"); + + b.Property("AccessType") + .HasColumnType("int"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateDelete") + .HasColumnType("datetime2"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("RoleId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.ToTable("Accesses"); + }); + + modelBuilder.Entity("DatabaseCore.Models.Security.EnviromentSetting", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("Description") + .HasColumnType("nvarchar(max)"); + + b.Property("Key") + .IsRequired() + .HasColumnType("nvarchar(450)"); + + b.Property("Value") + .IsRequired() + .HasColumnType("nvarchar(max)"); + + b.HasKey("Id"); + + b.HasIndex("Key") + .IsUnique(); + + b.ToTable("EnviromentSettings"); + }); + + modelBuilder.Entity("DatabaseCore.Models.Security.Role", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateDelete") + .HasColumnType("datetime2"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("RoleName") + .HasColumnType("nvarchar(450)"); + + b.Property("RolePriority") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("RoleName") + .IsUnique() + .HasFilter("[RoleName] IS NOT NULL"); + + b.ToTable("Roles"); + }); + + modelBuilder.Entity("DatabaseCore.Models.Security.User", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("Avatar") + .HasColumnType("varbinary(max)"); + + b.Property("CountAttempt") + .HasColumnType("int"); + + b.Property("DateBanned") + .HasColumnType("datetime2"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateDelete") + .HasColumnType("datetime2"); + + b.Property("DateLastVisit") + .HasColumnType("datetime2"); + + b.Property("IsBanned") + .HasColumnType("bit"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("PasswordHash") + .HasColumnType("nvarchar(max)"); + + b.Property("UserName") + .HasColumnType("nvarchar(450)"); + + b.HasKey("Id"); + + b.HasIndex("UserName") + .IsUnique() + .HasFilter("[UserName] IS NOT NULL"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("DatabaseCore.Models.Security.UserRole", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateDelete") + .HasColumnType("datetime2"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("RoleId") + .HasColumnType("uniqueidentifier"); + + b.Property("UserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("RoleId"); + + b.HasIndex("UserId"); + + b.ToTable("UserRoles"); + }); + + modelBuilder.Entity("DatabaseCore.Models.Department.EmployeeEmployeePost", b => + { + b.HasOne("DatabaseCore.Models.Department.Employee", "Employee") + .WithMany("EmployeeEmployeePosts") + .HasForeignKey("EmployeeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DatabaseCore.Models.Department.EmployeePost", "EmployeePost") + .WithMany("EmployeeEmployeePosts") + .HasForeignKey("EmployeePostId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Employee"); + + b.Navigation("EmployeePost"); + }); + + modelBuilder.Entity("DatabaseCore.Models.Security.Access", b => + { + b.HasOne("DatabaseCore.Models.Security.Role", "Role") + .WithMany("Access") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Role"); + }); + + modelBuilder.Entity("DatabaseCore.Models.Security.UserRole", b => + { + b.HasOne("DatabaseCore.Models.Security.Role", "Role") + .WithMany("UserRoles") + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DatabaseCore.Models.Security.User", "User") + .WithMany("UserRoles") + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Role"); + + b.Navigation("User"); + }); + + modelBuilder.Entity("DatabaseCore.Models.Department.Employee", b => + { + b.Navigation("EmployeeEmployeePosts"); + }); + + modelBuilder.Entity("DatabaseCore.Models.Department.EmployeePost", b => + { + b.Navigation("EmployeeEmployeePosts"); + }); + + modelBuilder.Entity("DatabaseCore.Models.Security.Role", b => + { + b.Navigation("Access"); + + b.Navigation("UserRoles"); + }); + + modelBuilder.Entity("DatabaseCore.Models.Security.User", b => + { + b.Navigation("UserRoles"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/DepartmentPortal/Common/DatabaseCore/Migrations/20210403054350_AddEmployee.cs b/DepartmentPortal/Common/DatabaseCore/Migrations/20210403054350_AddEmployee.cs new file mode 100644 index 0000000..6687b27 --- /dev/null +++ b/DepartmentPortal/Common/DatabaseCore/Migrations/20210403054350_AddEmployee.cs @@ -0,0 +1,178 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +namespace DatabaseCore.Migrations +{ + public partial class AddEmployee : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "UserName", + table: "Users", + type: "nvarchar(450)", + nullable: true, + oldClrType: typeof(string), + oldType: "nvarchar(max)", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "RoleName", + table: "Roles", + type: "nvarchar(450)", + nullable: true, + oldClrType: typeof(string), + oldType: "nvarchar(max)", + oldNullable: true); + + migrationBuilder.CreateTable( + name: "EmployeePosts", + columns: table => new + { + Id = table.Column(type: "uniqueidentifier", nullable: false), + EmployeePostName = table.Column(type: "nvarchar(450)", nullable: true), + Order = table.Column(type: "int", nullable: false), + DateCreate = table.Column(type: "datetime2", nullable: false), + DateDelete = table.Column(type: "datetime2", nullable: true), + IsDeleted = table.Column(type: "bit", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_EmployeePosts", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "Employees", + columns: table => new + { + Id = table.Column(type: "uniqueidentifier", nullable: false), + UserId = table.Column(type: "uniqueidentifier", nullable: false), + FirstName = table.Column(type: "nvarchar(450)", nullable: true), + LastName = table.Column(type: "nvarchar(450)", nullable: true), + Patronymic = table.Column(type: "nvarchar(450)", nullable: true), + DateBirth = table.Column(type: "datetime2", nullable: false), + Address = table.Column(type: "nvarchar(max)", nullable: true), + Email = table.Column(type: "nvarchar(max)", nullable: true), + MobileNumber = table.Column(type: "nvarchar(max)", nullable: true), + HomeNumber = table.Column(type: "nvarchar(max)", nullable: true), + Description = table.Column(type: "nvarchar(max)", nullable: true), + Photo = table.Column(type: "varbinary(max)", nullable: true), + GroupElectricalSafety = table.Column(type: "nvarchar(max)", nullable: true), + DateCreate = table.Column(type: "datetime2", nullable: false), + DateDelete = table.Column(type: "datetime2", nullable: true), + IsDeleted = table.Column(type: "bit", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_Employees", x => x.Id); + }); + + migrationBuilder.CreateTable( + name: "EmployeeEmployeePosts", + columns: table => new + { + Id = table.Column(type: "uniqueidentifier", nullable: false), + EmployeeId = table.Column(type: "uniqueidentifier", nullable: false), + EmployeePostId = table.Column(type: "uniqueidentifier", nullable: false), + Rate = table.Column(type: "decimal(18,2)", nullable: false), + IsInternalCombination = table.Column(type: "bit", nullable: false), + IsExternalCombination = table.Column(type: "bit", nullable: false), + DateCreate = table.Column(type: "datetime2", nullable: false), + DateDelete = table.Column(type: "datetime2", nullable: true), + IsDeleted = table.Column(type: "bit", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("PK_EmployeeEmployeePosts", x => x.Id); + table.ForeignKey( + name: "FK_EmployeeEmployeePosts_EmployeePosts_EmployeePostId", + column: x => x.EmployeePostId, + principalTable: "EmployeePosts", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "FK_EmployeeEmployeePosts_Employees_EmployeeId", + column: x => x.EmployeeId, + principalTable: "Employees", + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "IX_Users_UserName", + table: "Users", + column: "UserName", + unique: true, + filter: "[UserName] IS NOT NULL"); + + migrationBuilder.CreateIndex( + name: "IX_Roles_RoleName", + table: "Roles", + column: "RoleName", + unique: true, + filter: "[RoleName] IS NOT NULL"); + + migrationBuilder.CreateIndex( + name: "IX_EmployeeEmployeePosts_EmployeeId", + table: "EmployeeEmployeePosts", + column: "EmployeeId"); + + migrationBuilder.CreateIndex( + name: "IX_EmployeeEmployeePosts_EmployeePostId", + table: "EmployeeEmployeePosts", + column: "EmployeePostId"); + + migrationBuilder.CreateIndex( + name: "IX_EmployeePosts_EmployeePostName", + table: "EmployeePosts", + column: "EmployeePostName", + unique: true, + filter: "[EmployeePostName] IS NOT NULL"); + + migrationBuilder.CreateIndex( + name: "IX_Employees_FirstName_LastName_Patronymic", + table: "Employees", + columns: new[] { "FirstName", "LastName", "Patronymic" }, + unique: true, + filter: "[FirstName] IS NOT NULL AND [LastName] IS NOT NULL AND [Patronymic] IS NOT NULL"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "EmployeeEmployeePosts"); + + migrationBuilder.DropTable( + name: "EmployeePosts"); + + migrationBuilder.DropTable( + name: "Employees"); + + migrationBuilder.DropIndex( + name: "IX_Users_UserName", + table: "Users"); + + migrationBuilder.DropIndex( + name: "IX_Roles_RoleName", + table: "Roles"); + + migrationBuilder.AlterColumn( + name: "UserName", + table: "Users", + type: "nvarchar(max)", + nullable: true, + oldClrType: typeof(string), + oldType: "nvarchar(450)", + oldNullable: true); + + migrationBuilder.AlterColumn( + name: "RoleName", + table: "Roles", + type: "nvarchar(max)", + nullable: true, + oldClrType: typeof(string), + oldType: "nvarchar(450)", + oldNullable: true); + } + } +} diff --git a/DepartmentPortal/Common/DatabaseCore/Migrations/DatabaseContextModelSnapshot.cs b/DepartmentPortal/Common/DatabaseCore/Migrations/DatabaseContextModelSnapshot.cs index fa00fee..a5e420b 100644 --- a/DepartmentPortal/Common/DatabaseCore/Migrations/DatabaseContextModelSnapshot.cs +++ b/DepartmentPortal/Common/DatabaseCore/Migrations/DatabaseContextModelSnapshot.cs @@ -19,6 +19,132 @@ namespace DatabaseCore.Migrations .HasAnnotation("ProductVersion", "5.0.4") .HasAnnotation("SqlServer:ValueGenerationStrategy", SqlServerValueGenerationStrategy.IdentityColumn); + modelBuilder.Entity("DatabaseCore.Models.Department.Employee", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("Address") + .HasColumnType("nvarchar(max)"); + + b.Property("DateBirth") + .HasColumnType("datetime2"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateDelete") + .HasColumnType("datetime2"); + + b.Property("Description") + .HasColumnType("nvarchar(max)"); + + b.Property("Email") + .HasColumnType("nvarchar(max)"); + + b.Property("FirstName") + .HasColumnType("nvarchar(450)"); + + b.Property("GroupElectricalSafety") + .HasColumnType("nvarchar(max)"); + + b.Property("HomeNumber") + .HasColumnType("nvarchar(max)"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("LastName") + .HasColumnType("nvarchar(450)"); + + b.Property("MobileNumber") + .HasColumnType("nvarchar(max)"); + + b.Property("Patronymic") + .HasColumnType("nvarchar(450)"); + + b.Property("Photo") + .HasColumnType("varbinary(max)"); + + b.Property("UserId") + .HasColumnType("uniqueidentifier"); + + b.HasKey("Id"); + + b.HasIndex("FirstName", "LastName", "Patronymic") + .IsUnique() + .HasFilter("[FirstName] IS NOT NULL AND [LastName] IS NOT NULL AND [Patronymic] IS NOT NULL"); + + b.ToTable("Employees"); + }); + + modelBuilder.Entity("DatabaseCore.Models.Department.EmployeeEmployeePost", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateDelete") + .HasColumnType("datetime2"); + + b.Property("EmployeeId") + .HasColumnType("uniqueidentifier"); + + b.Property("EmployeePostId") + .HasColumnType("uniqueidentifier"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("IsExternalCombination") + .HasColumnType("bit"); + + b.Property("IsInternalCombination") + .HasColumnType("bit"); + + b.Property("Rate") + .HasColumnType("decimal(18,2)"); + + b.HasKey("Id"); + + b.HasIndex("EmployeeId"); + + b.HasIndex("EmployeePostId"); + + b.ToTable("EmployeeEmployeePosts"); + }); + + modelBuilder.Entity("DatabaseCore.Models.Department.EmployeePost", b => + { + b.Property("Id") + .HasColumnType("uniqueidentifier"); + + b.Property("DateCreate") + .HasColumnType("datetime2"); + + b.Property("DateDelete") + .HasColumnType("datetime2"); + + b.Property("EmployeePostName") + .HasColumnType("nvarchar(450)"); + + b.Property("IsDeleted") + .HasColumnType("bit"); + + b.Property("Order") + .HasColumnType("int"); + + b.HasKey("Id"); + + b.HasIndex("EmployeePostName") + .IsUnique() + .HasFilter("[EmployeePostName] IS NOT NULL"); + + b.ToTable("EmployeePosts"); + }); + modelBuilder.Entity("DatabaseCore.Models.Security.Access", b => { b.Property("Id") @@ -88,13 +214,17 @@ namespace DatabaseCore.Migrations .HasColumnType("bit"); b.Property("RoleName") - .HasColumnType("nvarchar(max)"); + .HasColumnType("nvarchar(450)"); b.Property("RolePriority") .HasColumnType("int"); b.HasKey("Id"); + b.HasIndex("RoleName") + .IsUnique() + .HasFilter("[RoleName] IS NOT NULL"); + b.ToTable("Roles"); }); @@ -131,10 +261,14 @@ namespace DatabaseCore.Migrations .HasColumnType("nvarchar(max)"); b.Property("UserName") - .HasColumnType("nvarchar(max)"); + .HasColumnType("nvarchar(450)"); b.HasKey("Id"); + b.HasIndex("UserName") + .IsUnique() + .HasFilter("[UserName] IS NOT NULL"); + b.ToTable("Users"); }); @@ -167,6 +301,25 @@ namespace DatabaseCore.Migrations b.ToTable("UserRoles"); }); + modelBuilder.Entity("DatabaseCore.Models.Department.EmployeeEmployeePost", b => + { + b.HasOne("DatabaseCore.Models.Department.Employee", "Employee") + .WithMany("EmployeeEmployeePosts") + .HasForeignKey("EmployeeId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("DatabaseCore.Models.Department.EmployeePost", "EmployeePost") + .WithMany("EmployeeEmployeePosts") + .HasForeignKey("EmployeePostId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Employee"); + + b.Navigation("EmployeePost"); + }); + modelBuilder.Entity("DatabaseCore.Models.Security.Access", b => { b.HasOne("DatabaseCore.Models.Security.Role", "Role") @@ -197,6 +350,16 @@ namespace DatabaseCore.Migrations b.Navigation("User"); }); + modelBuilder.Entity("DatabaseCore.Models.Department.Employee", b => + { + b.Navigation("EmployeeEmployeePosts"); + }); + + modelBuilder.Entity("DatabaseCore.Models.Department.EmployeePost", b => + { + b.Navigation("EmployeeEmployeePosts"); + }); + modelBuilder.Entity("DatabaseCore.Models.Security.Role", b => { b.Navigation("Access"); diff --git a/DepartmentPortal/Common/DatabaseCore/Models/Department/Employee.cs b/DepartmentPortal/Common/DatabaseCore/Models/Department/Employee.cs new file mode 100644 index 0000000..eac2217 --- /dev/null +++ b/DepartmentPortal/Common/DatabaseCore/Models/Department/Employee.cs @@ -0,0 +1,89 @@ +using ModuleTools.Attributes; +using ModuleTools.Interfaces; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; + +namespace DatabaseCore.Models.Department +{ + /// + /// Класс, описывающий сотрудника в системе + /// + [DataContract] + [EntityDescription("Employee", "Сотрудника в системе")] + public class Employee : BaseEntity, IEntitySecurityExtenstion + { + [DataMember] + [MapConfiguration("UserId")] + public Guid UserId { get; set; } + + [DataMember] + [MapConfiguration("FirstName")] + public string FirstName { get; set; } + + [DataMember] + [MapConfiguration("LastName")] + public string LastName { get; set; } + + [DataMember] + [MapConfiguration("Patronymic")] + public string Patronymic { get; set; } + + [DataMember] + [MapConfiguration("DateBirth")] + public DateTime DateBirth { get; set; } + + [DataMember] + [MapConfiguration("Address")] + public string Address { get; set; } + + [DataMember] + [MapConfiguration("Email")] + public string Email { get; set; } + + [DataMember] + [MapConfiguration("MobileNumber")] + public string MobileNumber { get; set; } + + [DataMember] + [MapConfiguration("HomeNumber")] + public string HomeNumber { get; set; } + + [DataMember] + [MapConfiguration("Description")] + public string Description { get; set; } + + [DataMember] + [MapConfiguration("Photo")] + public byte[] Photo { get; set; } + + [DataMember] + [MapConfiguration("GroupElectricalSafety")] + public string GroupElectricalSafety { get; set; } + + //------------------------------------------------------------------------- + + //------------------------------------------------------------------------- + + [ForeignKey("EmployeeId")] + public virtual List EmployeeEmployeePosts { get; set; } + + //------------------------------------------------------------------------- + + public Employee SecurityCheck(Employee entity, bool allowFullData) + { + if (!allowFullData) + { + entity.DateBirth = DateTime.Now; + entity.Address = "скрыто"; + entity.Email = "скрыто"; + entity.MobileNumber = "скрыто"; + entity.HomeNumber = "скрыто"; + entity.Photo = null; + } + + return entity; + } + } +} diff --git a/DepartmentPortal/Common/DatabaseCore/Models/Department/EmployeeEmployeePost.cs b/DepartmentPortal/Common/DatabaseCore/Models/Department/EmployeeEmployeePost.cs new file mode 100644 index 0000000..2ce86c2 --- /dev/null +++ b/DepartmentPortal/Common/DatabaseCore/Models/Department/EmployeeEmployeePost.cs @@ -0,0 +1,49 @@ +using ModuleTools.Attributes; +using ModuleTools.Interfaces; +using System; +using System.Runtime.Serialization; + +namespace DatabaseCore.Models.Department +{ + /// + /// Класс, описывающий связь сотрудника и должность в системе + /// + [DataContract] + [EntityDescription("EmployeeEmployeePost", "Связь сотрудника и должность в системе")] + [EntityDependency("EmployeePost", "EmployeePostId", "К какой должности относится сотрудник")] + [EntityDependency("Employee", "EmployeeId", "К какой должности относится сотрудник")] + public class EmployeeEmployeePost : BaseEntity, IEntitySecurityExtenstion + { + [DataMember] + [MapConfiguration("EmployeeId")] + public Guid EmployeeId { get; set; } + + [DataMember] + [MapConfiguration("EmployeePostId")] + public Guid EmployeePostId { get; set; } + + [DataMember] + [MapConfiguration("Rate")] + public decimal Rate { get; set; } + + [DataMember] + [MapConfiguration("IsInternalCombination")] + public bool IsInternalCombination { get; set; } + + [DataMember] + [MapConfiguration("IsExternalCombination")] + public bool IsExternalCombination { get; set; } + + //------------------------------------------------------------------------- + + public virtual EmployeePost EmployeePost { get; set; } + + public virtual Employee Employee { get; set; } + + //------------------------------------------------------------------------- + + //------------------------------------------------------------------------- + + public EmployeeEmployeePost SecurityCheck(EmployeeEmployeePost entity, bool allowFullData) => entity; + } +} diff --git a/DepartmentPortal/Common/DatabaseCore/Models/Department/EmployeePost.cs b/DepartmentPortal/Common/DatabaseCore/Models/Department/EmployeePost.cs new file mode 100644 index 0000000..602235e --- /dev/null +++ b/DepartmentPortal/Common/DatabaseCore/Models/Department/EmployeePost.cs @@ -0,0 +1,36 @@ +using ModuleTools.Attributes; +using ModuleTools.Interfaces; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.Runtime.Serialization; + +namespace DatabaseCore.Models.Department +{ + /// + /// Класс, описывающий должность сотрудника в системе + /// + [DataContract] + [EntityDescription("EmployeePost", "Должность сотрудника в системе")] + public class EmployeePost : BaseEntity, IEntitySecurityExtenstion + { + [DataMember] + [MapConfiguration("EmployeePostName")] + public string EmployeePostName { get; set; } + + + [DataMember] + [MapConfiguration("Order")] + public int Order { get; set; } + + //------------------------------------------------------------------------- + + //------------------------------------------------------------------------- + + [ForeignKey("EmployeePostId")] + public virtual List EmployeeEmployeePosts { get; set; } + + //------------------------------------------------------------------------- + + public EmployeePost SecurityCheck(EmployeePost entity, bool allowFullData) => entity; + } +} \ No newline at end of file