This commit is contained in:
RavilGismatullin 2024-08-28 13:09:28 +03:00
parent c13a1b2a71
commit f0cb77a254
7 changed files with 524 additions and 25 deletions

View File

@ -8,13 +8,14 @@ namespace ServiceStationsDataBaseImplement
{
public class Database : DbContext
{
//RavilPC
//DESKTOP-E2VPEN3
//WIN-4HUIDGH3G02
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if (optionsBuilder.IsConfigured == false)
{
optionsBuilder.UseSqlServer(@"Data Source=WIN-4HUIDGH3G02\SQLEXPRESS;Initial Catalog=ServiceStationDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
optionsBuilder.UseSqlServer(@"Data Source=RavilPC\SQLEXPRESS;Initial Catalog=ServiceStationDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
}
base.OnConfiguring(optionsBuilder);
}

View File

@ -0,0 +1,214 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using ServiceStationsDataBaseImplement;
#nullable disable
namespace ServiceStationsDataBaseImplement.Migrations
{
[DbContext(typeof(Database))]
[Migration("20240828095947_migration05")]
partial class migration05
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.18")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("ServiceStationsDataBaseImplement.Models.Client", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("FIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Clients");
});
modelBuilder.Entity("ServiceStationsDataBaseImplement.Models.Executor", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Email")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("FIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Executors");
});
modelBuilder.Entity("ServiceStationsDataBaseImplement.Models.TaskByWork", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Price")
.HasColumnType("float");
b.Property<int?>("TaskByWorkId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("TaskByWorkId")
.IsUnique()
.HasFilter("[TaskByWorkId] IS NOT NULL");
b.ToTable("Tasks");
});
modelBuilder.Entity("ServiceStationsDataBaseImplement.Models.Work", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("Date")
.HasColumnType("datetime2");
b.Property<int>("ExecutorId")
.HasColumnType("int");
b.Property<double>("Price")
.HasColumnType("float");
b.Property<int>("TaskByWorkId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ExecutorId");
b.HasIndex("TaskByWorkId");
b.ToTable("Works");
});
modelBuilder.Entity("ServiceStationsDataBaseImplement.Models.WorkClient", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ClientId")
.HasColumnType("int");
b.Property<int>("PointCount")
.HasColumnType("int");
b.Property<int>("WorkId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ClientId");
b.HasIndex("WorkId");
b.ToTable("WorksClients");
});
modelBuilder.Entity("ServiceStationsDataBaseImplement.Models.TaskByWork", b =>
{
b.HasOne("ServiceStationsDataBaseImplement.Models.Work", "work")
.WithOne()
.HasForeignKey("ServiceStationsDataBaseImplement.Models.TaskByWork", "TaskByWorkId");
b.Navigation("work");
});
modelBuilder.Entity("ServiceStationsDataBaseImplement.Models.Work", b =>
{
b.HasOne("ServiceStationsDataBaseImplement.Models.Executor", null)
.WithMany("Works")
.HasForeignKey("ExecutorId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ServiceStationsDataBaseImplement.Models.TaskByWork", "_task")
.WithMany()
.HasForeignKey("TaskByWorkId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("_task");
});
modelBuilder.Entity("ServiceStationsDataBaseImplement.Models.WorkClient", b =>
{
b.HasOne("ServiceStationsDataBaseImplement.Models.Client", "_client")
.WithMany("WorkClients")
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ServiceStationsDataBaseImplement.Models.Work", "_work")
.WithMany("WorkClients")
.HasForeignKey("WorkId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("_client");
b.Navigation("_work");
});
modelBuilder.Entity("ServiceStationsDataBaseImplement.Models.Client", b =>
{
b.Navigation("WorkClients");
});
modelBuilder.Entity("ServiceStationsDataBaseImplement.Models.Executor", b =>
{
b.Navigation("Works");
});
modelBuilder.Entity("ServiceStationsDataBaseImplement.Models.Work", b =>
{
b.Navigation("WorkClients");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,50 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace ServiceStationsDataBaseImplement.Migrations
{
/// <inheritdoc />
public partial class migration05 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "TotalPoints",
table: "Clients");
migrationBuilder.CreateIndex(
name: "IX_Works_TaskByWorkId",
table: "Works",
column: "TaskByWorkId");
migrationBuilder.AddForeignKey(
name: "FK_Works_Tasks_TaskByWorkId",
table: "Works",
column: "TaskByWorkId",
principalTable: "Tasks",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Works_Tasks_TaskByWorkId",
table: "Works");
migrationBuilder.DropIndex(
name: "IX_Works_TaskByWorkId",
table: "Works");
migrationBuilder.AddColumn<int>(
name: "TotalPoints",
table: "Clients",
type: "int",
nullable: false,
defaultValue: 0);
}
}
}

View File

@ -0,0 +1,198 @@
// <auto-generated />
using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using ServiceStationsDataBaseImplement;
#nullable disable
namespace ServiceStationsDataBaseImplement.Migrations
{
[DbContext(typeof(Database))]
[Migration("20240828100845_migration06")]
partial class migration06
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.18")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("ServiceStationsDataBaseImplement.Models.Client", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("FIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Clients");
});
modelBuilder.Entity("ServiceStationsDataBaseImplement.Models.Executor", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Email")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("FIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Password")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Executors");
});
modelBuilder.Entity("ServiceStationsDataBaseImplement.Models.TaskByWork", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("Price")
.HasColumnType("float");
b.HasKey("Id");
b.ToTable("Tasks");
});
modelBuilder.Entity("ServiceStationsDataBaseImplement.Models.Work", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<DateTime>("Date")
.HasColumnType("datetime2");
b.Property<int>("ExecutorId")
.HasColumnType("int");
b.Property<double>("Price")
.HasColumnType("float");
b.Property<int>("TaskByWorkId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ExecutorId");
b.HasIndex("TaskByWorkId");
b.ToTable("Works");
});
modelBuilder.Entity("ServiceStationsDataBaseImplement.Models.WorkClient", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ClientId")
.HasColumnType("int");
b.Property<int>("PointCount")
.HasColumnType("int");
b.Property<int>("WorkId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ClientId");
b.HasIndex("WorkId");
b.ToTable("WorksClients");
});
modelBuilder.Entity("ServiceStationsDataBaseImplement.Models.Work", b =>
{
b.HasOne("ServiceStationsDataBaseImplement.Models.Executor", null)
.WithMany("Works")
.HasForeignKey("ExecutorId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ServiceStationsDataBaseImplement.Models.TaskByWork", "_task")
.WithMany()
.HasForeignKey("TaskByWorkId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("_task");
});
modelBuilder.Entity("ServiceStationsDataBaseImplement.Models.WorkClient", b =>
{
b.HasOne("ServiceStationsDataBaseImplement.Models.Client", "_client")
.WithMany("WorkClients")
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ServiceStationsDataBaseImplement.Models.Work", "_work")
.WithMany("WorkClients")
.HasForeignKey("WorkId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("_client");
b.Navigation("_work");
});
modelBuilder.Entity("ServiceStationsDataBaseImplement.Models.Client", b =>
{
b.Navigation("WorkClients");
});
modelBuilder.Entity("ServiceStationsDataBaseImplement.Models.Executor", b =>
{
b.Navigation("Works");
});
modelBuilder.Entity("ServiceStationsDataBaseImplement.Models.Work", b =>
{
b.Navigation("WorkClients");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,50 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace ServiceStationsDataBaseImplement.Migrations
{
/// <inheritdoc />
public partial class migration06 : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropForeignKey(
name: "FK_Tasks_Works_TaskByWorkId",
table: "Tasks");
migrationBuilder.DropIndex(
name: "IX_Tasks_TaskByWorkId",
table: "Tasks");
migrationBuilder.DropColumn(
name: "TaskByWorkId",
table: "Tasks");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<int>(
name: "TaskByWorkId",
table: "Tasks",
type: "int",
nullable: true);
migrationBuilder.CreateIndex(
name: "IX_Tasks_TaskByWorkId",
table: "Tasks",
column: "TaskByWorkId",
unique: true,
filter: "[TaskByWorkId] IS NOT NULL");
migrationBuilder.AddForeignKey(
name: "FK_Tasks_Works_TaskByWorkId",
table: "Tasks",
column: "TaskByWorkId",
principalTable: "Works",
principalColumn: "Id");
}
}
}

View File

@ -34,9 +34,6 @@ namespace ServiceStationsDataBaseImplement.Migrations
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("TotalPoints")
.HasColumnType("int");
b.HasKey("Id");
b.ToTable("Clients");
@ -82,15 +79,8 @@ namespace ServiceStationsDataBaseImplement.Migrations
b.Property<double>("Price")
.HasColumnType("float");
b.Property<int?>("TaskByWorkId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("TaskByWorkId")
.IsUnique()
.HasFilter("[TaskByWorkId] IS NOT NULL");
b.ToTable("Tasks");
});
@ -118,6 +108,8 @@ namespace ServiceStationsDataBaseImplement.Migrations
b.HasIndex("ExecutorId");
b.HasIndex("TaskByWorkId");
b.ToTable("Works");
});
@ -147,15 +139,6 @@ namespace ServiceStationsDataBaseImplement.Migrations
b.ToTable("WorksClients");
});
modelBuilder.Entity("ServiceStationsDataBaseImplement.Models.TaskByWork", b =>
{
b.HasOne("ServiceStationsDataBaseImplement.Models.Work", "work")
.WithOne("_task")
.HasForeignKey("ServiceStationsDataBaseImplement.Models.TaskByWork", "TaskByWorkId");
b.Navigation("work");
});
modelBuilder.Entity("ServiceStationsDataBaseImplement.Models.Work", b =>
{
b.HasOne("ServiceStationsDataBaseImplement.Models.Executor", null)
@ -163,6 +146,14 @@ namespace ServiceStationsDataBaseImplement.Migrations
.HasForeignKey("ExecutorId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("ServiceStationsDataBaseImplement.Models.TaskByWork", "_task")
.WithMany()
.HasForeignKey("TaskByWorkId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("_task");
});
modelBuilder.Entity("ServiceStationsDataBaseImplement.Models.WorkClient", b =>
@ -197,8 +188,6 @@ namespace ServiceStationsDataBaseImplement.Migrations
modelBuilder.Entity("ServiceStationsDataBaseImplement.Models.Work", b =>
{
b.Navigation("WorkClients");
b.Navigation("_task");
});
#pragma warning restore 612, 618
}

View File

@ -19,9 +19,6 @@ namespace ServiceStationsDataBaseImplement.Models {
[Required]
public double Price { get; set; }
[ForeignKey("TaskByWorkId")]
public virtual Work? work { get; set; }
public static TaskByWork? Create(TaskBindingModel? model) {
if (model == null) {
return null;