Some fixes + db migration done

This commit is contained in:
Никита Волков 2024-05-04 13:50:48 +04:00
parent af940199a2
commit 6ceaafd33c
8 changed files with 1425 additions and 35 deletions

View File

@ -35,6 +35,6 @@ namespace BeautyStudioContracts.ViewModels
public DateTime DateCreate { get; set; }
[DisplayName("Дата выполнения")]
public DateTime DateComplete { get; set; }
public DateTime? DateComplete { get; set; }
}
}

View File

@ -20,8 +20,6 @@ namespace BeautyStudioDatabaseImplement.Implements
using var context = new BeautyStudioDatabase();
var element = context.Orders
.Include(x => x.Services)
.Include(x => x.Procedures)
.Include(x => x.Cosmetics)
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
@ -42,10 +40,6 @@ namespace BeautyStudioDatabaseImplement.Implements
return context.Orders
.Include(x => x.Services)
.ThenInclude(x => x.Service)
.Include(x => x.Procedures)
.ThenInclude(x => x.Procedure)
.Include(x => x.Cosmetics)
.ThenInclude(x => x.Cosmetic)
.FirstOrDefault(x => x.Id == model.Id)
?.GetViewModel;
}
@ -57,17 +51,13 @@ namespace BeautyStudioDatabaseImplement.Implements
return new();
}
using var context = new BeautyStudioDatabase();
if (model.ClientId.HasValue && model.OrderDate.HasValue)
if (model.ClientId.HasValue && model.DateCreate.HasValue)
{
return context.Orders
.Include(x => x.Services)
.ThenInclude(x => x.Service)
.Include(x => x.Procedures)
.ThenInclude(x => x.Procedure)
.Include(x => x.Cosmetics)
.ThenInclude(x => x.Cosmetic)
.Where(x => x.ClientId == model.ClientId &&
x.OrderDate == model.OrderDate).ToList()
x.DateCreate == model.DateCreate).ToList()
.Select(x => x.GetViewModel)
.ToList();
}
@ -89,10 +79,6 @@ namespace BeautyStudioDatabaseImplement.Implements
return context.Orders
.Include(x => x.Services)
.ThenInclude(x => x.Service)
.Include(x => x.Procedures)
.ThenInclude(x => x.Procedure)
.Include(x => x.Cosmetics)
.ThenInclude(x => x.Cosmetic)
.ToList()
.Select(x => x.GetViewModel)
.ToList();
@ -101,7 +87,7 @@ namespace BeautyStudioDatabaseImplement.Implements
public OrderViewModel? Insert(OrderBindingModel model)
{
using var context = new BeautyStudioDatabase();
var newOrder = Order_.Create(context, model);
var newOrder = Order.Create(context, model);
if (newOrder == null)
{
return null;
@ -124,9 +110,6 @@ namespace BeautyStudioDatabaseImplement.Implements
}
order.Update(model);
context.SaveChanges();
order.UpdateServices(context, model);
order.UpdateProcedures(context, model);
order.UpdateCosmetics(context, model);
transaction.Commit();
return order.GetViewModel;
}

View File

@ -19,7 +19,6 @@ namespace BeautyStudioDatabaseImplement.Implements
using var context = new BeautyStudioDatabase();
var element = context.Services
.Include(x => x.Procedures)
.Include(x => x.Cosmetics)
.FirstOrDefault(rec => rec.Id == model.Id);
if (element != null)
{
@ -40,8 +39,6 @@ namespace BeautyStudioDatabaseImplement.Implements
return context.Services
.Include(x => x.Procedures)
.ThenInclude(x => x.Procedure)
.Include(x => x.Cosmetics)
.ThenInclude(x => x.Cosmetic)
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ServiceName) && x.ServiceName == model.ServiceName) ||
(model.Id.HasValue && x.Id == model.Id))
?.GetViewModel;
@ -59,8 +56,6 @@ namespace BeautyStudioDatabaseImplement.Implements
return context.Services
.Include(x => x.Procedures)
.ThenInclude(x => x.Procedure)
.Include(x => x.Cosmetics)
.ThenInclude(x => x.Cosmetic)
.Where(x => x.Id == model.Id)
.ToList()
.Select(x => x.GetViewModel)
@ -71,8 +66,6 @@ namespace BeautyStudioDatabaseImplement.Implements
return context.Services
.Include(x => x.Procedures)
.ThenInclude(x => x.Procedure)
.Include(x => x.Cosmetics)
.ThenInclude(x => x.Cosmetic)
.Where(x => x.StaffId == model.StaffId)
.ToList()
.Select(x => x.GetViewModel)
@ -87,8 +80,6 @@ namespace BeautyStudioDatabaseImplement.Implements
return context.Services
.Include(x => x.Procedures)
.ThenInclude(x => x.Procedure)
.Include(x => x.Cosmetics)
.ThenInclude(x => x.Cosmetic)
.Select(x => x.GetViewModel)
.ToList();
}
@ -119,8 +110,6 @@ namespace BeautyStudioDatabaseImplement.Implements
}
service.Update(model);
context.SaveChanges();
service.UpdateCosmetics(context, model);
service.UpdateProcedures(context, model);
transaction.Commit();
return service.GetViewModel;
}

View File

@ -0,0 +1,519 @@
// <auto-generated />
using System;
using BeautyStudioDatabaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace BeautyStudioDatabaseImplement.Migrations
{
[DbContext(typeof(BeautyStudioDatabase))]
[Migration("20240504094925_InitialCreate")]
partial class InitialCreate
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.4")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Client", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClientEmail")
.IsRequired()
.HasColumnType("text");
b.Property<string>("ClientFIO")
.IsRequired()
.HasColumnType("text");
b.Property<string>("ClientLogin")
.IsRequired()
.HasColumnType("text");
b.Property<string>("ClientPassword")
.IsRequired()
.HasColumnType("text");
b.Property<string>("ClientPhone")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Clients");
});
modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Cosmetic", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("CosmeticName")
.IsRequired()
.HasColumnType("text");
b.Property<double>("CosmeticPrice")
.HasColumnType("double precision");
b.Property<int>("LaborCostId")
.HasColumnType("integer");
b.Property<int>("StoreKeeperId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("LaborCostId");
b.HasIndex("StoreKeeperId");
b.ToTable("Cosmetics");
});
modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.LaborCost", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Difficulty")
.IsRequired()
.HasColumnType("text");
b.Property<int>("StaffId")
.HasColumnType("integer");
b.Property<int>("TimeSpent")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("StaffId");
b.ToTable("LaborCost");
});
modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Order", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("ClientId")
.HasColumnType("integer");
b.Property<DateTime?>("DateComplete")
.HasColumnType("timestamp with time zone");
b.Property<DateTime>("DateCreate")
.HasColumnType("timestamp with time zone");
b.Property<int>("ServiceId")
.HasColumnType("integer");
b.Property<int?>("StaffId")
.IsRequired()
.HasColumnType("integer");
b.Property<int>("Status")
.HasColumnType("integer");
b.Property<double>("Sum")
.HasColumnType("double precision");
b.HasKey("Id");
b.HasIndex("ClientId");
b.HasIndex("StaffId");
b.ToTable("Orders");
});
modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.OrderService", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("OrderId")
.HasColumnType("integer");
b.Property<int>("ServiceId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("OrderId");
b.HasIndex("ServiceId");
b.ToTable("OrderService");
});
modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Procedure", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("ClientId")
.HasColumnType("integer");
b.Property<double>("ProcedureCost")
.HasColumnType("double precision");
b.Property<string>("ProcedureDescription")
.IsRequired()
.HasColumnType("text");
b.Property<string>("ProcedureName")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("ClientId");
b.ToTable("Procedures");
});
modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.ProcedureCosmetics", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("CosmeticId")
.HasColumnType("integer");
b.Property<int>("ProcedureCosmeticCount")
.HasColumnType("integer");
b.Property<int>("ProcedureId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("CosmeticId");
b.HasIndex("ProcedureId");
b.ToTable("ProcedureCosmetics");
});
modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Service", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ServiceName")
.IsRequired()
.HasColumnType("text");
b.Property<int>("StaffId")
.HasColumnType("integer");
b.Property<double>("Sum")
.HasColumnType("double precision");
b.HasKey("Id");
b.HasIndex("StaffId");
b.ToTable("Services");
});
modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.ServiceProcedure", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("ProcedureId")
.HasColumnType("integer");
b.Property<int>("ServiceId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("ProcedureId");
b.HasIndex("ServiceId");
b.ToTable("ServiceProcedures");
});
modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Staff", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("StaffEmail")
.IsRequired()
.HasColumnType("text");
b.Property<string>("StaffFIO")
.IsRequired()
.HasColumnType("text");
b.Property<string>("StaffLogin")
.IsRequired()
.HasColumnType("text");
b.Property<string>("StaffPassword")
.IsRequired()
.HasColumnType("text");
b.Property<string>("StaffPhone")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Staffs");
});
modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.StoreKeeper", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("StoreKeeperEmail")
.IsRequired()
.HasColumnType("text");
b.Property<string>("StoreKeeperFIO")
.IsRequired()
.HasColumnType("text");
b.Property<string>("StoreKeeperLogin")
.IsRequired()
.HasColumnType("text");
b.Property<string>("StoreKeeperPassword")
.IsRequired()
.HasColumnType("text");
b.Property<string>("StoreKeeperPhone")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("StoreKeepers");
});
modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Cosmetic", b =>
{
b.HasOne("BeautyStudioDatabaseImplement.Models.LaborCost", "LaborCost")
.WithMany("Cosmetics")
.HasForeignKey("LaborCostId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("BeautyStudioDatabaseImplement.Models.StoreKeeper", null)
.WithMany("Cosmetics")
.HasForeignKey("StoreKeeperId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("LaborCost");
});
modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.LaborCost", b =>
{
b.HasOne("BeautyStudioDatabaseImplement.Models.Staff", "Staff")
.WithMany("LaborCost")
.HasForeignKey("StaffId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Staff");
});
modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Order", b =>
{
b.HasOne("BeautyStudioDatabaseImplement.Models.Client", null)
.WithMany("Orders")
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("BeautyStudioDatabaseImplement.Models.Staff", null)
.WithMany("Orders")
.HasForeignKey("StaffId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.OrderService", b =>
{
b.HasOne("BeautyStudioDatabaseImplement.Models.Order", "Order")
.WithMany("Services")
.HasForeignKey("OrderId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("BeautyStudioDatabaseImplement.Models.Service", "Service")
.WithMany("Orders")
.HasForeignKey("ServiceId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Order");
b.Navigation("Service");
});
modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Procedure", b =>
{
b.HasOne("BeautyStudioDatabaseImplement.Models.Client", "Client")
.WithMany()
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Client");
});
modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.ProcedureCosmetics", b =>
{
b.HasOne("BeautyStudioDatabaseImplement.Models.Cosmetic", "Cosmetic")
.WithMany("Procedures")
.HasForeignKey("CosmeticId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("BeautyStudioDatabaseImplement.Models.Procedure", "Procedure")
.WithMany("Cosmetics")
.HasForeignKey("ProcedureId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Cosmetic");
b.Navigation("Procedure");
});
modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Service", b =>
{
b.HasOne("BeautyStudioDatabaseImplement.Models.Staff", "Staff")
.WithMany("Services")
.HasForeignKey("StaffId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Staff");
});
modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.ServiceProcedure", b =>
{
b.HasOne("BeautyStudioDatabaseImplement.Models.Procedure", "Procedure")
.WithMany("Services")
.HasForeignKey("ProcedureId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("BeautyStudioDatabaseImplement.Models.Service", "Service")
.WithMany("Procedures")
.HasForeignKey("ServiceId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Procedure");
b.Navigation("Service");
});
modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Client", b =>
{
b.Navigation("Orders");
});
modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Cosmetic", b =>
{
b.Navigation("Procedures");
});
modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.LaborCost", b =>
{
b.Navigation("Cosmetics");
});
modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Order", b =>
{
b.Navigation("Services");
});
modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Procedure", b =>
{
b.Navigation("Cosmetics");
b.Navigation("Services");
});
modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Service", b =>
{
b.Navigation("Orders");
b.Navigation("Procedures");
});
modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Staff", b =>
{
b.Navigation("LaborCost");
b.Navigation("Orders");
b.Navigation("Services");
});
modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.StoreKeeper", b =>
{
b.Navigation("Cosmetics");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,371 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace BeautyStudioDatabaseImplement.Migrations
{
/// <inheritdoc />
public partial class InitialCreate : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "Clients",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ClientLogin = table.Column<string>(type: "text", nullable: false),
ClientFIO = table.Column<string>(type: "text", nullable: false),
ClientEmail = table.Column<string>(type: "text", nullable: false),
ClientPhone = table.Column<string>(type: "text", nullable: false),
ClientPassword = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Clients", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Staffs",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
StaffFIO = table.Column<string>(type: "text", nullable: false),
StaffEmail = table.Column<string>(type: "text", nullable: false),
StaffLogin = table.Column<string>(type: "text", nullable: false),
StaffPassword = table.Column<string>(type: "text", nullable: false),
StaffPhone = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Staffs", x => x.Id);
});
migrationBuilder.CreateTable(
name: "StoreKeepers",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
StoreKeeperFIO = table.Column<string>(type: "text", nullable: false),
StoreKeeperEmail = table.Column<string>(type: "text", nullable: false),
StoreKeeperLogin = table.Column<string>(type: "text", nullable: false),
StoreKeeperPassword = table.Column<string>(type: "text", nullable: false),
StoreKeeperPhone = table.Column<string>(type: "text", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_StoreKeepers", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Procedures",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ProcedureName = table.Column<string>(type: "text", nullable: false),
ProcedureCost = table.Column<double>(type: "double precision", nullable: false),
ProcedureDescription = table.Column<string>(type: "text", nullable: false),
ClientId = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Procedures", x => x.Id);
table.ForeignKey(
name: "FK_Procedures_Clients_ClientId",
column: x => x.ClientId,
principalTable: "Clients",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "LaborCost",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
TimeSpent = table.Column<int>(type: "integer", nullable: false),
Difficulty = table.Column<string>(type: "text", nullable: false),
StaffId = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_LaborCost", x => x.Id);
table.ForeignKey(
name: "FK_LaborCost_Staffs_StaffId",
column: x => x.StaffId,
principalTable: "Staffs",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Orders",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
DateCreate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
DateComplete = table.Column<DateTime>(type: "timestamp with time zone", nullable: true),
Status = table.Column<int>(type: "integer", nullable: false),
Sum = table.Column<double>(type: "double precision", nullable: false),
ClientId = table.Column<int>(type: "integer", nullable: false),
StaffId = table.Column<int>(type: "integer", nullable: false),
ServiceId = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Orders", x => x.Id);
table.ForeignKey(
name: "FK_Orders_Clients_ClientId",
column: x => x.ClientId,
principalTable: "Clients",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Orders_Staffs_StaffId",
column: x => x.StaffId,
principalTable: "Staffs",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Services",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ServiceName = table.Column<string>(type: "text", nullable: false),
Sum = table.Column<double>(type: "double precision", nullable: false),
StaffId = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Services", x => x.Id);
table.ForeignKey(
name: "FK_Services_Staffs_StaffId",
column: x => x.StaffId,
principalTable: "Staffs",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "Cosmetics",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
CosmeticName = table.Column<string>(type: "text", nullable: false),
CosmeticPrice = table.Column<double>(type: "double precision", nullable: false),
StoreKeeperId = table.Column<int>(type: "integer", nullable: false),
LaborCostId = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Cosmetics", x => x.Id);
table.ForeignKey(
name: "FK_Cosmetics_LaborCost_LaborCostId",
column: x => x.LaborCostId,
principalTable: "LaborCost",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Cosmetics_StoreKeepers_StoreKeeperId",
column: x => x.StoreKeeperId,
principalTable: "StoreKeepers",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "OrderService",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
OrderId = table.Column<int>(type: "integer", nullable: false),
ServiceId = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_OrderService", x => x.Id);
table.ForeignKey(
name: "FK_OrderService_Orders_OrderId",
column: x => x.OrderId,
principalTable: "Orders",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_OrderService_Services_ServiceId",
column: x => x.ServiceId,
principalTable: "Services",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "ServiceProcedures",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ServiceId = table.Column<int>(type: "integer", nullable: false),
ProcedureId = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ServiceProcedures", x => x.Id);
table.ForeignKey(
name: "FK_ServiceProcedures_Procedures_ProcedureId",
column: x => x.ProcedureId,
principalTable: "Procedures",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_ServiceProcedures_Services_ServiceId",
column: x => x.ServiceId,
principalTable: "Services",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "ProcedureCosmetics",
columns: table => new
{
Id = table.Column<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
ProcedureId = table.Column<int>(type: "integer", nullable: false),
CosmeticId = table.Column<int>(type: "integer", nullable: false),
ProcedureCosmeticCount = table.Column<int>(type: "integer", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_ProcedureCosmetics", x => x.Id);
table.ForeignKey(
name: "FK_ProcedureCosmetics_Cosmetics_CosmeticId",
column: x => x.CosmeticId,
principalTable: "Cosmetics",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_ProcedureCosmetics_Procedures_ProcedureId",
column: x => x.ProcedureId,
principalTable: "Procedures",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_Cosmetics_LaborCostId",
table: "Cosmetics",
column: "LaborCostId");
migrationBuilder.CreateIndex(
name: "IX_Cosmetics_StoreKeeperId",
table: "Cosmetics",
column: "StoreKeeperId");
migrationBuilder.CreateIndex(
name: "IX_LaborCost_StaffId",
table: "LaborCost",
column: "StaffId");
migrationBuilder.CreateIndex(
name: "IX_Orders_ClientId",
table: "Orders",
column: "ClientId");
migrationBuilder.CreateIndex(
name: "IX_Orders_StaffId",
table: "Orders",
column: "StaffId");
migrationBuilder.CreateIndex(
name: "IX_OrderService_OrderId",
table: "OrderService",
column: "OrderId");
migrationBuilder.CreateIndex(
name: "IX_OrderService_ServiceId",
table: "OrderService",
column: "ServiceId");
migrationBuilder.CreateIndex(
name: "IX_ProcedureCosmetics_CosmeticId",
table: "ProcedureCosmetics",
column: "CosmeticId");
migrationBuilder.CreateIndex(
name: "IX_ProcedureCosmetics_ProcedureId",
table: "ProcedureCosmetics",
column: "ProcedureId");
migrationBuilder.CreateIndex(
name: "IX_Procedures_ClientId",
table: "Procedures",
column: "ClientId");
migrationBuilder.CreateIndex(
name: "IX_ServiceProcedures_ProcedureId",
table: "ServiceProcedures",
column: "ProcedureId");
migrationBuilder.CreateIndex(
name: "IX_ServiceProcedures_ServiceId",
table: "ServiceProcedures",
column: "ServiceId");
migrationBuilder.CreateIndex(
name: "IX_Services_StaffId",
table: "Services",
column: "StaffId");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "OrderService");
migrationBuilder.DropTable(
name: "ProcedureCosmetics");
migrationBuilder.DropTable(
name: "ServiceProcedures");
migrationBuilder.DropTable(
name: "Orders");
migrationBuilder.DropTable(
name: "Cosmetics");
migrationBuilder.DropTable(
name: "Procedures");
migrationBuilder.DropTable(
name: "Services");
migrationBuilder.DropTable(
name: "LaborCost");
migrationBuilder.DropTable(
name: "StoreKeepers");
migrationBuilder.DropTable(
name: "Clients");
migrationBuilder.DropTable(
name: "Staffs");
}
}
}

View File

@ -0,0 +1,516 @@
// <auto-generated />
using System;
using BeautyStudioDatabaseImplement;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace BeautyStudioDatabaseImplement.Migrations
{
[DbContext(typeof(BeautyStudioDatabase))]
partial class BeautyStudioDatabaseModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.4")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Client", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClientEmail")
.IsRequired()
.HasColumnType("text");
b.Property<string>("ClientFIO")
.IsRequired()
.HasColumnType("text");
b.Property<string>("ClientLogin")
.IsRequired()
.HasColumnType("text");
b.Property<string>("ClientPassword")
.IsRequired()
.HasColumnType("text");
b.Property<string>("ClientPhone")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Clients");
});
modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Cosmetic", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("CosmeticName")
.IsRequired()
.HasColumnType("text");
b.Property<double>("CosmeticPrice")
.HasColumnType("double precision");
b.Property<int>("LaborCostId")
.HasColumnType("integer");
b.Property<int>("StoreKeeperId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("LaborCostId");
b.HasIndex("StoreKeeperId");
b.ToTable("Cosmetics");
});
modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.LaborCost", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("Difficulty")
.IsRequired()
.HasColumnType("text");
b.Property<int>("StaffId")
.HasColumnType("integer");
b.Property<int>("TimeSpent")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("StaffId");
b.ToTable("LaborCost");
});
modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Order", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("ClientId")
.HasColumnType("integer");
b.Property<DateTime?>("DateComplete")
.HasColumnType("timestamp with time zone");
b.Property<DateTime>("DateCreate")
.HasColumnType("timestamp with time zone");
b.Property<int>("ServiceId")
.HasColumnType("integer");
b.Property<int?>("StaffId")
.IsRequired()
.HasColumnType("integer");
b.Property<int>("Status")
.HasColumnType("integer");
b.Property<double>("Sum")
.HasColumnType("double precision");
b.HasKey("Id");
b.HasIndex("ClientId");
b.HasIndex("StaffId");
b.ToTable("Orders");
});
modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.OrderService", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("OrderId")
.HasColumnType("integer");
b.Property<int>("ServiceId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("OrderId");
b.HasIndex("ServiceId");
b.ToTable("OrderService");
});
modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Procedure", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("ClientId")
.HasColumnType("integer");
b.Property<double>("ProcedureCost")
.HasColumnType("double precision");
b.Property<string>("ProcedureDescription")
.IsRequired()
.HasColumnType("text");
b.Property<string>("ProcedureName")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.HasIndex("ClientId");
b.ToTable("Procedures");
});
modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.ProcedureCosmetics", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("CosmeticId")
.HasColumnType("integer");
b.Property<int>("ProcedureCosmeticCount")
.HasColumnType("integer");
b.Property<int>("ProcedureId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("CosmeticId");
b.HasIndex("ProcedureId");
b.ToTable("ProcedureCosmetics");
});
modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Service", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ServiceName")
.IsRequired()
.HasColumnType("text");
b.Property<int>("StaffId")
.HasColumnType("integer");
b.Property<double>("Sum")
.HasColumnType("double precision");
b.HasKey("Id");
b.HasIndex("StaffId");
b.ToTable("Services");
});
modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.ServiceProcedure", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<int>("ProcedureId")
.HasColumnType("integer");
b.Property<int>("ServiceId")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("ProcedureId");
b.HasIndex("ServiceId");
b.ToTable("ServiceProcedures");
});
modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Staff", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("StaffEmail")
.IsRequired()
.HasColumnType("text");
b.Property<string>("StaffFIO")
.IsRequired()
.HasColumnType("text");
b.Property<string>("StaffLogin")
.IsRequired()
.HasColumnType("text");
b.Property<string>("StaffPassword")
.IsRequired()
.HasColumnType("text");
b.Property<string>("StaffPhone")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("Staffs");
});
modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.StoreKeeper", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("StoreKeeperEmail")
.IsRequired()
.HasColumnType("text");
b.Property<string>("StoreKeeperFIO")
.IsRequired()
.HasColumnType("text");
b.Property<string>("StoreKeeperLogin")
.IsRequired()
.HasColumnType("text");
b.Property<string>("StoreKeeperPassword")
.IsRequired()
.HasColumnType("text");
b.Property<string>("StoreKeeperPhone")
.IsRequired()
.HasColumnType("text");
b.HasKey("Id");
b.ToTable("StoreKeepers");
});
modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Cosmetic", b =>
{
b.HasOne("BeautyStudioDatabaseImplement.Models.LaborCost", "LaborCost")
.WithMany("Cosmetics")
.HasForeignKey("LaborCostId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("BeautyStudioDatabaseImplement.Models.StoreKeeper", null)
.WithMany("Cosmetics")
.HasForeignKey("StoreKeeperId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("LaborCost");
});
modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.LaborCost", b =>
{
b.HasOne("BeautyStudioDatabaseImplement.Models.Staff", "Staff")
.WithMany("LaborCost")
.HasForeignKey("StaffId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Staff");
});
modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Order", b =>
{
b.HasOne("BeautyStudioDatabaseImplement.Models.Client", null)
.WithMany("Orders")
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("BeautyStudioDatabaseImplement.Models.Staff", null)
.WithMany("Orders")
.HasForeignKey("StaffId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.OrderService", b =>
{
b.HasOne("BeautyStudioDatabaseImplement.Models.Order", "Order")
.WithMany("Services")
.HasForeignKey("OrderId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("BeautyStudioDatabaseImplement.Models.Service", "Service")
.WithMany("Orders")
.HasForeignKey("ServiceId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Order");
b.Navigation("Service");
});
modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Procedure", b =>
{
b.HasOne("BeautyStudioDatabaseImplement.Models.Client", "Client")
.WithMany()
.HasForeignKey("ClientId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Client");
});
modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.ProcedureCosmetics", b =>
{
b.HasOne("BeautyStudioDatabaseImplement.Models.Cosmetic", "Cosmetic")
.WithMany("Procedures")
.HasForeignKey("CosmeticId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("BeautyStudioDatabaseImplement.Models.Procedure", "Procedure")
.WithMany("Cosmetics")
.HasForeignKey("ProcedureId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Cosmetic");
b.Navigation("Procedure");
});
modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Service", b =>
{
b.HasOne("BeautyStudioDatabaseImplement.Models.Staff", "Staff")
.WithMany("Services")
.HasForeignKey("StaffId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Staff");
});
modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.ServiceProcedure", b =>
{
b.HasOne("BeautyStudioDatabaseImplement.Models.Procedure", "Procedure")
.WithMany("Services")
.HasForeignKey("ProcedureId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("BeautyStudioDatabaseImplement.Models.Service", "Service")
.WithMany("Procedures")
.HasForeignKey("ServiceId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Procedure");
b.Navigation("Service");
});
modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Client", b =>
{
b.Navigation("Orders");
});
modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Cosmetic", b =>
{
b.Navigation("Procedures");
});
modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.LaborCost", b =>
{
b.Navigation("Cosmetics");
});
modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Order", b =>
{
b.Navigation("Services");
});
modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Procedure", b =>
{
b.Navigation("Cosmetics");
b.Navigation("Services");
});
modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Service", b =>
{
b.Navigation("Orders");
b.Navigation("Procedures");
});
modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.Staff", b =>
{
b.Navigation("LaborCost");
b.Navigation("Orders");
b.Navigation("Services");
});
modelBuilder.Entity("BeautyStudioDatabaseImplement.Models.StoreKeeper", b =>
{
b.Navigation("Cosmetics");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -36,9 +36,9 @@ namespace BeautyStudioDatabaseImplement.Models
[Required]
public int ServiceId { get; set; }
[ForeignKey("ClientId")]
public virtual Client? Client { get; set; }
public virtual Staff? Staff { get; set; }
// связь заказов и услуги многие-ко-многим
[ForeignKey("OrderId")]
public virtual List<OrderService> Services { get; set; } = new();
public static Order Create(BeautyStudioDatabase context, OrderBindingModel model)
{

View File

@ -8,4 +8,16 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.4">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BeautyStudioContracts\BeautyStudioContracts.csproj" />
<ProjectReference Include="..\BeautyStudioDatabaseImplement\BeautyStudioDatabaseImplement.csproj" />
</ItemGroup>
</Project>