diff --git a/git/JurasicZoo/ZooContracts/BindingModels/RouteBindingModel.cs b/git/JurasicZoo/ZooContracts/BindingModels/RouteBindingModel.cs index 9851953..f6f6021 100644 --- a/git/JurasicZoo/ZooContracts/BindingModels/RouteBindingModel.cs +++ b/git/JurasicZoo/ZooContracts/BindingModels/RouteBindingModel.cs @@ -12,6 +12,7 @@ namespace ZooContracts.BindingModels { public int Id { get; set; } public int ClientId { get; set; } + public int CostId { get; set; } public string RouteName { get; set; } = string.Empty; public double RoutePrice { get; set; } public RouteStatus Status { get; set; } = RouteStatus.Неоплачен; diff --git a/git/JurasicZoo/ZooContracts/ViewModels/RouteViewModel.cs b/git/JurasicZoo/ZooContracts/ViewModels/RouteViewModel.cs index 670176f..8c7f45a 100644 --- a/git/JurasicZoo/ZooContracts/ViewModels/RouteViewModel.cs +++ b/git/JurasicZoo/ZooContracts/ViewModels/RouteViewModel.cs @@ -15,6 +15,7 @@ namespace ZooContracts.ViewModels [DisplayName("Номер")] public int Id { get; set; } public int ClientId { get; set; } + public int CostId { get; set; } [DisplayName("ФИО клиента")] public string ClientFIO { get; set; } = string.Empty; diff --git a/git/JurasicZoo/ZooDataBaseImplement/Migrations/20240531115435_initialcreate.Designer.cs b/git/JurasicZoo/ZooDataBaseImplement/Migrations/20240531220930_InitialCreate.Designer.cs similarity index 94% rename from git/JurasicZoo/ZooDataBaseImplement/Migrations/20240531115435_initialcreate.Designer.cs rename to git/JurasicZoo/ZooDataBaseImplement/Migrations/20240531220930_InitialCreate.Designer.cs index ef1e606..75087f1 100644 --- a/git/JurasicZoo/ZooDataBaseImplement/Migrations/20240531115435_initialcreate.Designer.cs +++ b/git/JurasicZoo/ZooDataBaseImplement/Migrations/20240531220930_InitialCreate.Designer.cs @@ -12,15 +12,15 @@ using ZooDataBaseImplement; namespace ZooDataBaseImplement.Migrations { [DbContext(typeof(ZooDatabase))] - [Migration("20240531115435_initialcreate")] - partial class initialcreate + [Migration("20240531220930_InitialCreate")] + partial class InitialCreate { /// protected override void BuildTargetModel(ModelBuilder modelBuilder) { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "7.0.3") + .HasAnnotation("ProductVersion", "7.0.18") .HasAnnotation("Relational:MaxIdentifierLength", 63); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); @@ -65,6 +65,9 @@ namespace ZooDataBaseImplement.Migrations b.Property("CostPrice") .HasColumnType("double precision"); + b.Property("EmployeeId") + .HasColumnType("integer"); + b.HasKey("Id"); b.ToTable("Costs"); @@ -131,7 +134,7 @@ namespace ZooDataBaseImplement.Migrations b.Property("ClientId") .HasColumnType("integer"); - b.Property("CostID") + b.Property("CostId") .HasColumnType("integer"); b.Property("DateFinish") @@ -154,7 +157,7 @@ namespace ZooDataBaseImplement.Migrations b.HasIndex("ClientId"); - b.HasIndex("CostID"); + b.HasIndex("CostId"); b.ToTable("Routes"); }); @@ -201,7 +204,9 @@ namespace ZooDataBaseImplement.Migrations b.HasOne("ZooDataBaseImplement.Models.Cost", null) .WithMany("Routes") - .HasForeignKey("CostID"); + .HasForeignKey("CostId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); b.Navigation("Client"); }); diff --git a/git/JurasicZoo/ZooDataBaseImplement/Migrations/20240531115435_initialcreate.cs b/git/JurasicZoo/ZooDataBaseImplement/Migrations/20240531220930_InitialCreate.cs similarity index 93% rename from git/JurasicZoo/ZooDataBaseImplement/Migrations/20240531115435_initialcreate.cs rename to git/JurasicZoo/ZooDataBaseImplement/Migrations/20240531220930_InitialCreate.cs index fd540c1..a582b5c 100644 --- a/git/JurasicZoo/ZooDataBaseImplement/Migrations/20240531115435_initialcreate.cs +++ b/git/JurasicZoo/ZooDataBaseImplement/Migrations/20240531220930_InitialCreate.cs @@ -7,7 +7,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; namespace ZooDataBaseImplement.Migrations { /// - public partial class initialcreate : Migration + public partial class InitialCreate : Migration { /// protected override void Up(MigrationBuilder migrationBuilder) @@ -33,6 +33,7 @@ namespace ZooDataBaseImplement.Migrations { Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + EmployeeId = table.Column(type: "integer", nullable: false), CostName = table.Column(type: "text", nullable: false), CostPrice = table.Column(type: "double precision", nullable: false) }, @@ -63,12 +64,12 @@ namespace ZooDataBaseImplement.Migrations Id = table.Column(type: "integer", nullable: false) .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), ClientId = table.Column(type: "integer", nullable: false), + CostId = table.Column(type: "integer", nullable: false), RouteName = table.Column(type: "text", nullable: false), RoutePrice = table.Column(type: "double precision", nullable: false), Status = table.Column(type: "integer", nullable: false), DateStart = table.Column(type: "timestamp with time zone", nullable: false), - DateFinish = table.Column(type: "timestamp with time zone", nullable: false), - CostID = table.Column(type: "integer", nullable: true) + DateFinish = table.Column(type: "timestamp with time zone", nullable: false) }, constraints: table => { @@ -80,10 +81,11 @@ namespace ZooDataBaseImplement.Migrations principalColumn: "Id", onDelete: ReferentialAction.Cascade); table.ForeignKey( - name: "FK_Routes_Costs_CostID", - column: x => x.CostID, + name: "FK_Routes_Costs_CostId", + column: x => x.CostId, principalTable: "Costs", - principalColumn: "Id"); + principalColumn: "Id", + onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateTable( @@ -154,9 +156,9 @@ namespace ZooDataBaseImplement.Migrations column: "ClientId"); migrationBuilder.CreateIndex( - name: "IX_Routes_CostID", + name: "IX_Routes_CostId", table: "Routes", - column: "CostID"); + column: "CostId"); } /// diff --git a/git/JurasicZoo/ZooDataBaseImplement/Migrations/ZooDatabaseModelSnapshot.cs b/git/JurasicZoo/ZooDataBaseImplement/Migrations/ZooDatabaseModelSnapshot.cs index a9d08b5..20a6334 100644 --- a/git/JurasicZoo/ZooDataBaseImplement/Migrations/ZooDatabaseModelSnapshot.cs +++ b/git/JurasicZoo/ZooDataBaseImplement/Migrations/ZooDatabaseModelSnapshot.cs @@ -17,7 +17,7 @@ namespace ZooDataBaseImplement.Migrations { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "7.0.3") + .HasAnnotation("ProductVersion", "7.0.18") .HasAnnotation("Relational:MaxIdentifierLength", 63); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); @@ -62,6 +62,9 @@ namespace ZooDataBaseImplement.Migrations b.Property("CostPrice") .HasColumnType("double precision"); + b.Property("EmployeeId") + .HasColumnType("integer"); + b.HasKey("Id"); b.ToTable("Costs"); @@ -128,7 +131,7 @@ namespace ZooDataBaseImplement.Migrations b.Property("ClientId") .HasColumnType("integer"); - b.Property("CostID") + b.Property("CostId") .HasColumnType("integer"); b.Property("DateFinish") @@ -151,7 +154,7 @@ namespace ZooDataBaseImplement.Migrations b.HasIndex("ClientId"); - b.HasIndex("CostID"); + b.HasIndex("CostId"); b.ToTable("Routes"); }); @@ -198,7 +201,9 @@ namespace ZooDataBaseImplement.Migrations b.HasOne("ZooDataBaseImplement.Models.Cost", null) .WithMany("Routes") - .HasForeignKey("CostID"); + .HasForeignKey("CostId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); b.Navigation("Client"); }); diff --git a/git/JurasicZoo/ZooDataBaseImplement/Models/Cost.cs b/git/JurasicZoo/ZooDataBaseImplement/Models/Cost.cs index 5bc7564..65ab53e 100644 --- a/git/JurasicZoo/ZooDataBaseImplement/Models/Cost.cs +++ b/git/JurasicZoo/ZooDataBaseImplement/Models/Cost.cs @@ -21,8 +21,9 @@ namespace ZooDataBaseImplement.Models public string CostName { get; set; } = string.Empty; [Required] public double CostPrice { get; set; } - - public static Cost? Create(CostBindingModel model) + [ForeignKey("CostId")] + public virtual List Routes { get; set; } = new(); + public static Cost? Create(CostBindingModel model) { if (model == null) { diff --git a/git/JurasicZoo/ZooDataBaseImplement/Models/Route.cs b/git/JurasicZoo/ZooDataBaseImplement/Models/Route.cs index 8787746..77c27a2 100644 --- a/git/JurasicZoo/ZooDataBaseImplement/Models/Route.cs +++ b/git/JurasicZoo/ZooDataBaseImplement/Models/Route.cs @@ -13,6 +13,7 @@ namespace ZooDataBaseImplement.Models public int Id { get; private set; } [Required] public int ClientId { get; private set; } + public int CostId { get; private set; } public virtual Client Client { get; private set; } = new(); [Required] public string RouteName { get; set; } = string.Empty; @@ -48,6 +49,7 @@ namespace ZooDataBaseImplement.Models { Id = model.Id, ClientId = model.ClientId, + CostId = model.CostId, Client = context.Clients.First(x => x.Id == model.ClientId), RouteName = model.RouteName, RoutePrice = model.RoutePrice, @@ -77,6 +79,7 @@ namespace ZooDataBaseImplement.Models { Id = Id, ClientId = ClientId, + CostId = CostId, ClientFIO = Client.ClientFIO, RouteName = RouteName, RoutePrice = RoutePrice, diff --git a/git/JurasicZoo/ZooDataBaseImplement/ZooDataBaseImplement.csproj b/git/JurasicZoo/ZooDataBaseImplement/ZooDataBaseImplement.csproj index b6badad..1b28028 100644 --- a/git/JurasicZoo/ZooDataBaseImplement/ZooDataBaseImplement.csproj +++ b/git/JurasicZoo/ZooDataBaseImplement/ZooDataBaseImplement.csproj @@ -19,4 +19,8 @@ + + + + diff --git a/git/JurasicZoo/ZooDataModels/Models/IRouteModel.cs b/git/JurasicZoo/ZooDataModels/Models/IRouteModel.cs index 18ddc39..d247606 100644 --- a/git/JurasicZoo/ZooDataModels/Models/IRouteModel.cs +++ b/git/JurasicZoo/ZooDataModels/Models/IRouteModel.cs @@ -10,6 +10,7 @@ namespace ZooDataModels.Models public interface IRouteModel : IId { int ClientId { get; } + int CostId { get; } string RouteName { get; } double RoutePrice { get; } RouteStatus Status { get; }