diff --git a/BeautySalon/BeautySalon.csproj b/BeautySalon/BeautySalon.csproj
index b57c89e..2440d79 100644
--- a/BeautySalon/BeautySalon.csproj
+++ b/BeautySalon/BeautySalon.csproj
@@ -8,4 +8,17 @@
enable
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/BeautySalonDatabaseImplement/BeautySalonDatabaseImplement.csproj b/BeautySalonDatabaseImplement/BeautySalonDatabaseImplement.csproj
index 4c545f6..4caae15 100644
--- a/BeautySalonDatabaseImplement/BeautySalonDatabaseImplement.csproj
+++ b/BeautySalonDatabaseImplement/BeautySalonDatabaseImplement.csproj
@@ -6,12 +6,13 @@
enable
-
-
-
-
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
diff --git a/BeautySalonDatabaseImplement/Implements/ClientStorage.cs b/BeautySalonDatabaseImplement/Implements/ClientStorage.cs
new file mode 100644
index 0000000..a5d3b61
--- /dev/null
+++ b/BeautySalonDatabaseImplement/Implements/ClientStorage.cs
@@ -0,0 +1,82 @@
+using BeautySalonContracts.BindingModels;
+using BeautySalonContracts.SearchModels;
+using BeautySalonContracts.StoragesContracts;
+using BeautySalonContracts.ViewModels;
+using BeautySalonDatabaseImplement.Models;
+
+namespace BeautySalonDatabaseImplement.Implements
+{
+ public class ClientStorage : IClientStorage
+ {
+ public ClientViewModel? Delete(ClientBindingModel model)
+ {
+ using var context = new BeautySalonDatabase();
+ var element = context.Clients.FirstOrDefault(rec => rec.Id == model.Id);
+ if (element != null)
+ {
+ context.Clients.Remove(element);
+ context.SaveChanges();
+ return element.GetViewModel;
+ }
+ return null;
+ }
+
+ public ClientViewModel? GetElement(ClientSearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.PhoneNumber) && !model.Id.HasValue)
+ {
+ return null;
+ }
+ using var context = new BeautySalonDatabase();
+ return context.Clients.FirstOrDefault(x => (!string.IsNullOrEmpty(model.PhoneNumber) && x.PhoneNumber == model.PhoneNumber) ||
+ (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
+ }
+
+ public List GetFilteredList(ClientSearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.PhoneNumber))
+ {
+ return new();
+ }
+ using var context = new BeautySalonDatabase();
+ return context.Clients
+ .Where(x => x.PhoneNumber.Equals(model.PhoneNumber))
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+
+ public List GetFullList()
+ {
+ using var context = new BeautySalonDatabase();
+ return context.Clients
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+
+ public ClientViewModel? Insert(ClientBindingModel model)
+ {
+ var newClient = Client.Create(model);
+ if (newClient == null)
+ {
+ return null;
+ }
+ using var context = new BeautySalonDatabase();
+ context.Clients.Add(newClient);
+ context.SaveChanges();
+ return newClient.GetViewModel;
+ }
+
+ public ClientViewModel? Update(ClientBindingModel model)
+ {
+ using var context = new BeautySalonDatabase();
+ var client = context.Clients.FirstOrDefault(x => x.Id == model.Id);
+ if (client == null)
+ {
+ return null;
+ }
+ client.Update(model);
+ context.SaveChanges();
+ return client.GetViewModel;
+ }
+ }
+}
diff --git a/BeautySalonDatabaseImplement/Implements/MasterStorage.cs b/BeautySalonDatabaseImplement/Implements/MasterStorage.cs
new file mode 100644
index 0000000..0d57c0a
--- /dev/null
+++ b/BeautySalonDatabaseImplement/Implements/MasterStorage.cs
@@ -0,0 +1,104 @@
+using BeautySalonContracts.BindingModels;
+using BeautySalonContracts.SearchModels;
+using BeautySalonContracts.StoragesContracts;
+using BeautySalonContracts.ViewModels;
+using BeautySalonDatabaseImplement.Models;
+using Microsoft.EntityFrameworkCore;
+
+namespace BeautySalonDatabaseImplement.Implements
+{
+ public class MasterStorage : IMasterStorage
+ {
+ public List GetFullList()
+ {
+ using var context = new BeautySalonDatabase();
+ return context.Masters
+ .Include(x => x.Services)
+ .ThenInclude(x => x.Service)
+ .ToList()
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+ public List GetFilteredList(MasterSearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.MasterFIO))
+ {
+ return new();
+ }
+ using var context = new BeautySalonDatabase();
+ return context.Masters
+ .Include(x => x.Services)
+ .ThenInclude(x => x.Service)
+ .Where(x => x.MasterFIO.Contains(model.MasterFIO))
+ .ToList()
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+ public MasterViewModel? GetElement(MasterSearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.MasterFIO) &&
+ !model.Id.HasValue)
+ {
+ return null;
+ }
+ using var context = new BeautySalonDatabase();
+ return context.Masters
+ .Include(x => x.Services)
+ .ThenInclude(x => x.Service)
+ .FirstOrDefault(x => (!string.IsNullOrEmpty(model.MasterFIO) &&
+ x.MasterFIO == model.MasterFIO) ||
+ (model.Id.HasValue && x.Id == model.Id))
+ ?.GetViewModel;
+ }
+ public MasterViewModel? Insert(MasterBindingModel model)
+ {
+ using var context = new BeautySalonDatabase();
+ var newMaster = Master.Create(context, model);
+ if (newMaster == null)
+ {
+ return null;
+ }
+ context.Masters.Add(newMaster);
+ context.SaveChanges();
+ return newMaster.GetViewModel;
+ }
+ public MasterViewModel? Update(MasterBindingModel model)
+ {
+ using var context = new BeautySalonDatabase();
+ using var transaction = context.Database.BeginTransaction();
+ try
+ {
+ var engine = context.Masters.FirstOrDefault(rec =>
+ rec.Id == model.Id);
+ if (engine == null)
+ {
+ return null;
+ }
+ engine.Update(model);
+ context.SaveChanges();
+ engine.UpdateServices(context, model);
+ transaction.Commit();
+ return engine.GetViewModel;
+ }
+ catch
+ {
+ transaction.Rollback();
+ throw;
+ }
+ }
+ public MasterViewModel? Delete(MasterBindingModel model)
+ {
+ using var context = new BeautySalonDatabase();
+ var element = context.Masters
+ .Include(x => x.Services)
+ .FirstOrDefault(rec => rec.Id == model.Id);
+ if (element != null)
+ {
+ context.Masters.Remove(element);
+ context.SaveChanges();
+ return element.GetViewModel;
+ }
+ return null;
+ }
+ }
+}
diff --git a/BeautySalonDatabaseImplement/Implements/ServiceStorage.cs b/BeautySalonDatabaseImplement/Implements/ServiceStorage.cs
new file mode 100644
index 0000000..a3967df
--- /dev/null
+++ b/BeautySalonDatabaseImplement/Implements/ServiceStorage.cs
@@ -0,0 +1,82 @@
+using BeautySalonContracts.BindingModels;
+using BeautySalonContracts.SearchModels;
+using BeautySalonContracts.StoragesContracts;
+using BeautySalonContracts.ViewModels;
+using BeautySalonDatabaseImplement.Models;
+using System.ServiceModel;
+
+namespace BeautySalonDatabaseImplement.Implements
+{
+ public class ServiceStorage : IServiceStorage
+ {
+ public List GetFullList()
+ {
+ using var context = new BeautySalonDatabase();
+ return context.Services
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+ public List GetFilteredList(ServiceSearchModel
+ model)
+ {
+ if (string.IsNullOrEmpty(model.ServiceName))
+ {
+ return new();
+ }
+ using var context = new BeautySalonDatabase();
+ return context.Services
+ .Where(x => x.ServiceName.Contains(model.ServiceName))
+ .Select(x => x.GetViewModel)
+ .ToList();
+ }
+ public ServiceViewModel? GetElement(ServiceSearchModel model)
+ {
+ if (string.IsNullOrEmpty(model.ServiceName) && !model.Id.HasValue)
+ {
+ return null;
+ }
+ using var context = new BeautySalonDatabase();
+ return context.Services
+ .FirstOrDefault(x =>
+ (!string.IsNullOrEmpty(model.ServiceName) && x.ServiceName ==
+ model.ServiceName) || (model.Id.HasValue && x.Id == model.Id))
+ ?.GetViewModel;
+ }
+ public ServiceViewModel? Insert(ServiceBindingModel model)
+ {
+ var newService = Service.Create(model);
+ if (newService == null)
+ {
+ return null;
+ }
+ using var context = new BeautySalonDatabase();
+ context.Services.Add(newService);
+ context.SaveChanges();
+ return newService.GetViewModel;
+ }
+ public ServiceViewModel? Update(ServiceBindingModel model)
+ {
+ using var context = new BeautySalonDatabase();
+ var component = context.Services.FirstOrDefault(x => x.Id == model.Id);
+ if (component == null)
+ {
+ return null;
+ }
+ component.Update(model);
+ context.SaveChanges();
+ return component.GetViewModel;
+ }
+ public ServiceViewModel? Delete(ServiceBindingModel model)
+ {
+ using var context = new BeautySalonDatabase();
+ var element = context.Services.FirstOrDefault(rec => rec.Id == model.Id);
+ if (element != null)
+ {
+ context.Services.Remove(element);
+ context.SaveChanges();
+ return element.GetViewModel;
+ }
+ return null;
+ }
+ }
+}
diff --git a/BeautySalonDatabaseImplement/Implements/VisitStorage.cs b/BeautySalonDatabaseImplement/Implements/VisitStorage.cs
new file mode 100644
index 0000000..bd1641b
--- /dev/null
+++ b/BeautySalonDatabaseImplement/Implements/VisitStorage.cs
@@ -0,0 +1,77 @@
+using BeautySalonContracts.BindingModels;
+using BeautySalonContracts.SearchModels;
+using BeautySalonContracts.StoragesContracts;
+using BeautySalonContracts.ViewModels;
+using BeautySalonDatabaseImplement.Models;
+using Microsoft.EntityFrameworkCore;
+
+namespace BeautySalonDatabaseImplement.Implements
+{
+ public class VisitStorage : IVisitStorage
+ {
+ public VisitViewModel? Delete(VisitBindingModel model)
+ {
+ using var context = new BeautySalonDatabase();
+ var element = context.Visits.FirstOrDefault(rec => rec.Id == model.Id);
+ if (element != null)
+ {
+ context.Visits.Remove(element);
+ context.SaveChanges();
+ return element.GetViewModel;
+ }
+ return null;
+ }
+
+ public VisitViewModel? GetElement(VisitSearchModel model)
+ {
+ if (!model.Id.HasValue)
+ {
+ return null;
+ }
+ using var context = new BeautySalonDatabase();
+ return context.Visits.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
+ }
+
+ public List GetFilteredList(VisitSearchModel model)
+ {
+ if (!model.Id.HasValue)
+ {
+ return new();
+ }
+ using var context = new BeautySalonDatabase();
+ return context.Visits.Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList();
+ }
+
+ public List GetFullList()
+ {
+ using var context = new BeautySalonDatabase();
+ return context.Visits.Select(x => x.GetViewModel).ToList();
+ }
+
+ public VisitViewModel? Insert(VisitBindingModel model)
+ {
+ var newVisit = Visit.Create(model);
+ if (newVisit == null)
+ {
+ return null;
+ }
+ using var context = new BeautySalonDatabase();
+ context.Visits.Add(newVisit);
+ context.SaveChanges();
+ return newVisit.GetViewModel;
+ }
+
+ public VisitViewModel? Update(VisitBindingModel model)
+ {
+ using var context = new BeautySalonDatabase();
+ var order = context.Visits.FirstOrDefault(x => x.Id == model.Id);
+ if (order == null)
+ {
+ return null;
+ }
+ order.Update(model);
+ context.SaveChanges();
+ return order.GetViewModel;
+ }
+ }
+}
diff --git a/BeautySalonDatabaseImplement/Migrations/20230513120245_InitialCreate.Designer.cs b/BeautySalonDatabaseImplement/Migrations/20230513120245_InitialCreate.Designer.cs
new file mode 100644
index 0000000..f343eb6
--- /dev/null
+++ b/BeautySalonDatabaseImplement/Migrations/20230513120245_InitialCreate.Designer.cs
@@ -0,0 +1,225 @@
+//
+using System;
+using BeautySalonDatabaseImplement;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Metadata;
+using Microsoft.EntityFrameworkCore.Migrations;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+
+#nullable disable
+
+namespace BeautySalonDatabaseImplement.Migrations
+{
+ [DbContext(typeof(BeautySalonDatabase))]
+ [Migration("20230513120245_InitialCreate")]
+ partial class InitialCreate
+ {
+ ///
+ protected override void BuildTargetModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("ProductVersion", "7.0.5")
+ .HasAnnotation("Relational:MaxIdentifierLength", 128);
+
+ SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
+
+ modelBuilder.Entity("BeautySalonDatabaseImplement.Models.Client", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("ClientFIO")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("PhoneNumber")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.HasKey("Id");
+
+ b.ToTable("Clients");
+ });
+
+ modelBuilder.Entity("BeautySalonDatabaseImplement.Models.Master", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("MasterFIO")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Specialization")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.HasKey("Id");
+
+ b.ToTable("Masters");
+ });
+
+ modelBuilder.Entity("BeautySalonDatabaseImplement.Models.MasterService", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("Count")
+ .HasColumnType("int");
+
+ b.Property("MasterId")
+ .HasColumnType("int");
+
+ b.Property("ServiceId")
+ .HasColumnType("int");
+
+ b.HasKey("Id");
+
+ b.HasIndex("MasterId");
+
+ b.HasIndex("ServiceId");
+
+ b.ToTable("MasterServices");
+ });
+
+ modelBuilder.Entity("BeautySalonDatabaseImplement.Models.Service", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("Cost")
+ .HasColumnType("float");
+
+ b.Property("ServiceName")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.HasKey("Id");
+
+ b.ToTable("Services");
+ });
+
+ modelBuilder.Entity("BeautySalonDatabaseImplement.Models.Visit", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("ClientFIO")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("ClientId")
+ .HasColumnType("int");
+
+ b.Property("Count")
+ .HasColumnType("int");
+
+ b.Property("DateOfVisit")
+ .HasColumnType("datetime2");
+
+ b.Property("MasterFIO")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("MasterId")
+ .HasColumnType("int");
+
+ b.Property("ServiceId")
+ .HasColumnType("int");
+
+ b.Property("ServiceName")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Sum")
+ .HasColumnType("float");
+
+ b.HasKey("Id");
+
+ b.HasIndex("ClientId");
+
+ b.HasIndex("MasterId");
+
+ b.HasIndex("ServiceId");
+
+ b.ToTable("Visits");
+ });
+
+ modelBuilder.Entity("BeautySalonDatabaseImplement.Models.MasterService", b =>
+ {
+ b.HasOne("BeautySalonDatabaseImplement.Models.Master", "Master")
+ .WithMany("Services")
+ .HasForeignKey("MasterId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("BeautySalonDatabaseImplement.Models.Service", "Service")
+ .WithMany("MasterServices")
+ .HasForeignKey("ServiceId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Master");
+
+ b.Navigation("Service");
+ });
+
+ modelBuilder.Entity("BeautySalonDatabaseImplement.Models.Visit", b =>
+ {
+ b.HasOne("BeautySalonDatabaseImplement.Models.Client", "Client")
+ .WithMany()
+ .HasForeignKey("ClientId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("BeautySalonDatabaseImplement.Models.Master", "Master")
+ .WithMany("Visits")
+ .HasForeignKey("MasterId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("BeautySalonDatabaseImplement.Models.Service", "Service")
+ .WithMany()
+ .HasForeignKey("ServiceId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Client");
+
+ b.Navigation("Master");
+
+ b.Navigation("Service");
+ });
+
+ modelBuilder.Entity("BeautySalonDatabaseImplement.Models.Master", b =>
+ {
+ b.Navigation("Services");
+
+ b.Navigation("Visits");
+ });
+
+ modelBuilder.Entity("BeautySalonDatabaseImplement.Models.Service", b =>
+ {
+ b.Navigation("MasterServices");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/BeautySalonDatabaseImplement/Migrations/20230513120245_InitialCreate.cs b/BeautySalonDatabaseImplement/Migrations/20230513120245_InitialCreate.cs
new file mode 100644
index 0000000..bb58afe
--- /dev/null
+++ b/BeautySalonDatabaseImplement/Migrations/20230513120245_InitialCreate.cs
@@ -0,0 +1,167 @@
+using System;
+using Microsoft.EntityFrameworkCore.Migrations;
+
+#nullable disable
+
+namespace BeautySalonDatabaseImplement.Migrations
+{
+ ///
+ public partial class InitialCreate : Migration
+ {
+ ///
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.CreateTable(
+ name: "Clients",
+ columns: table => new
+ {
+ Id = table.Column(type: "int", nullable: false)
+ .Annotation("SqlServer:Identity", "1, 1"),
+ ClientFIO = table.Column(type: "nvarchar(max)", nullable: false),
+ PhoneNumber = table.Column(type: "nvarchar(max)", nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_Clients", x => x.Id);
+ });
+
+ migrationBuilder.CreateTable(
+ name: "Masters",
+ columns: table => new
+ {
+ Id = table.Column(type: "int", nullable: false)
+ .Annotation("SqlServer:Identity", "1, 1"),
+ MasterFIO = table.Column(type: "nvarchar(max)", nullable: false),
+ Specialization = table.Column(type: "nvarchar(max)", nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_Masters", x => x.Id);
+ });
+
+ migrationBuilder.CreateTable(
+ name: "Services",
+ columns: table => new
+ {
+ Id = table.Column(type: "int", nullable: false)
+ .Annotation("SqlServer:Identity", "1, 1"),
+ ServiceName = table.Column(type: "nvarchar(max)", nullable: false),
+ Cost = table.Column(type: "float", nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_Services", x => x.Id);
+ });
+
+ migrationBuilder.CreateTable(
+ name: "MasterServices",
+ columns: table => new
+ {
+ Id = table.Column(type: "int", nullable: false)
+ .Annotation("SqlServer:Identity", "1, 1"),
+ MasterId = table.Column(type: "int", nullable: false),
+ ServiceId = table.Column(type: "int", nullable: false),
+ Count = table.Column(type: "int", nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_MasterServices", x => x.Id);
+ table.ForeignKey(
+ name: "FK_MasterServices_Masters_MasterId",
+ column: x => x.MasterId,
+ principalTable: "Masters",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+ table.ForeignKey(
+ name: "FK_MasterServices_Services_ServiceId",
+ column: x => x.ServiceId,
+ principalTable: "Services",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+ });
+
+ migrationBuilder.CreateTable(
+ name: "Visits",
+ columns: table => new
+ {
+ Id = table.Column(type: "int", nullable: false)
+ .Annotation("SqlServer:Identity", "1, 1"),
+ DateOfVisit = table.Column(type: "datetime2", nullable: false),
+ ClientId = table.Column(type: "int", nullable: false),
+ MasterId = table.Column(type: "int", nullable: false),
+ ServiceId = table.Column(type: "int", nullable: false),
+ ClientFIO = table.Column(type: "nvarchar(max)", nullable: false),
+ MasterFIO = table.Column(type: "nvarchar(max)", nullable: false),
+ ServiceName = table.Column(type: "nvarchar(max)", nullable: false),
+ Sum = table.Column(type: "float", nullable: false),
+ Count = table.Column(type: "int", nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_Visits", x => x.Id);
+ table.ForeignKey(
+ name: "FK_Visits_Clients_ClientId",
+ column: x => x.ClientId,
+ principalTable: "Clients",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+ table.ForeignKey(
+ name: "FK_Visits_Masters_MasterId",
+ column: x => x.MasterId,
+ principalTable: "Masters",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+ table.ForeignKey(
+ name: "FK_Visits_Services_ServiceId",
+ column: x => x.ServiceId,
+ principalTable: "Services",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+ });
+
+ migrationBuilder.CreateIndex(
+ name: "IX_MasterServices_MasterId",
+ table: "MasterServices",
+ column: "MasterId");
+
+ migrationBuilder.CreateIndex(
+ name: "IX_MasterServices_ServiceId",
+ table: "MasterServices",
+ column: "ServiceId");
+
+ migrationBuilder.CreateIndex(
+ name: "IX_Visits_ClientId",
+ table: "Visits",
+ column: "ClientId");
+
+ migrationBuilder.CreateIndex(
+ name: "IX_Visits_MasterId",
+ table: "Visits",
+ column: "MasterId");
+
+ migrationBuilder.CreateIndex(
+ name: "IX_Visits_ServiceId",
+ table: "Visits",
+ column: "ServiceId");
+ }
+
+ ///
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropTable(
+ name: "MasterServices");
+
+ migrationBuilder.DropTable(
+ name: "Visits");
+
+ migrationBuilder.DropTable(
+ name: "Clients");
+
+ migrationBuilder.DropTable(
+ name: "Masters");
+
+ migrationBuilder.DropTable(
+ name: "Services");
+ }
+ }
+}
diff --git a/BeautySalonDatabaseImplement/Migrations/BeautySalonDatabaseModelSnapshot.cs b/BeautySalonDatabaseImplement/Migrations/BeautySalonDatabaseModelSnapshot.cs
new file mode 100644
index 0000000..7b07540
--- /dev/null
+++ b/BeautySalonDatabaseImplement/Migrations/BeautySalonDatabaseModelSnapshot.cs
@@ -0,0 +1,222 @@
+//
+using System;
+using BeautySalonDatabaseImplement;
+using Microsoft.EntityFrameworkCore;
+using Microsoft.EntityFrameworkCore.Infrastructure;
+using Microsoft.EntityFrameworkCore.Metadata;
+using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
+
+#nullable disable
+
+namespace BeautySalonDatabaseImplement.Migrations
+{
+ [DbContext(typeof(BeautySalonDatabase))]
+ partial class BeautySalonDatabaseModelSnapshot : ModelSnapshot
+ {
+ protected override void BuildModel(ModelBuilder modelBuilder)
+ {
+#pragma warning disable 612, 618
+ modelBuilder
+ .HasAnnotation("ProductVersion", "7.0.5")
+ .HasAnnotation("Relational:MaxIdentifierLength", 128);
+
+ SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
+
+ modelBuilder.Entity("BeautySalonDatabaseImplement.Models.Client", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("ClientFIO")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("PhoneNumber")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.HasKey("Id");
+
+ b.ToTable("Clients");
+ });
+
+ modelBuilder.Entity("BeautySalonDatabaseImplement.Models.Master", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("MasterFIO")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Specialization")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.HasKey("Id");
+
+ b.ToTable("Masters");
+ });
+
+ modelBuilder.Entity("BeautySalonDatabaseImplement.Models.MasterService", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("Count")
+ .HasColumnType("int");
+
+ b.Property("MasterId")
+ .HasColumnType("int");
+
+ b.Property("ServiceId")
+ .HasColumnType("int");
+
+ b.HasKey("Id");
+
+ b.HasIndex("MasterId");
+
+ b.HasIndex("ServiceId");
+
+ b.ToTable("MasterServices");
+ });
+
+ modelBuilder.Entity("BeautySalonDatabaseImplement.Models.Service", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("Cost")
+ .HasColumnType("float");
+
+ b.Property("ServiceName")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.HasKey("Id");
+
+ b.ToTable("Services");
+ });
+
+ modelBuilder.Entity("BeautySalonDatabaseImplement.Models.Visit", b =>
+ {
+ b.Property("Id")
+ .ValueGeneratedOnAdd()
+ .HasColumnType("int");
+
+ SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id"));
+
+ b.Property("ClientFIO")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("ClientId")
+ .HasColumnType("int");
+
+ b.Property("Count")
+ .HasColumnType("int");
+
+ b.Property("DateOfVisit")
+ .HasColumnType("datetime2");
+
+ b.Property("MasterFIO")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("MasterId")
+ .HasColumnType("int");
+
+ b.Property("ServiceId")
+ .HasColumnType("int");
+
+ b.Property("ServiceName")
+ .IsRequired()
+ .HasColumnType("nvarchar(max)");
+
+ b.Property("Sum")
+ .HasColumnType("float");
+
+ b.HasKey("Id");
+
+ b.HasIndex("ClientId");
+
+ b.HasIndex("MasterId");
+
+ b.HasIndex("ServiceId");
+
+ b.ToTable("Visits");
+ });
+
+ modelBuilder.Entity("BeautySalonDatabaseImplement.Models.MasterService", b =>
+ {
+ b.HasOne("BeautySalonDatabaseImplement.Models.Master", "Master")
+ .WithMany("Services")
+ .HasForeignKey("MasterId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("BeautySalonDatabaseImplement.Models.Service", "Service")
+ .WithMany("MasterServices")
+ .HasForeignKey("ServiceId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Master");
+
+ b.Navigation("Service");
+ });
+
+ modelBuilder.Entity("BeautySalonDatabaseImplement.Models.Visit", b =>
+ {
+ b.HasOne("BeautySalonDatabaseImplement.Models.Client", "Client")
+ .WithMany()
+ .HasForeignKey("ClientId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("BeautySalonDatabaseImplement.Models.Master", "Master")
+ .WithMany("Visits")
+ .HasForeignKey("MasterId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.HasOne("BeautySalonDatabaseImplement.Models.Service", "Service")
+ .WithMany()
+ .HasForeignKey("ServiceId")
+ .OnDelete(DeleteBehavior.Cascade)
+ .IsRequired();
+
+ b.Navigation("Client");
+
+ b.Navigation("Master");
+
+ b.Navigation("Service");
+ });
+
+ modelBuilder.Entity("BeautySalonDatabaseImplement.Models.Master", b =>
+ {
+ b.Navigation("Services");
+
+ b.Navigation("Visits");
+ });
+
+ modelBuilder.Entity("BeautySalonDatabaseImplement.Models.Service", b =>
+ {
+ b.Navigation("MasterServices");
+ });
+#pragma warning restore 612, 618
+ }
+ }
+}
diff --git a/BeautySalonDatabaseImplement/Models/Visit.cs b/BeautySalonDatabaseImplement/Models/Visit.cs
index 26e323b..7d22df3 100644
--- a/BeautySalonDatabaseImplement/Models/Visit.cs
+++ b/BeautySalonDatabaseImplement/Models/Visit.cs
@@ -1,4 +1,5 @@
using BeautySalonContracts.BindingModels;
+using BeautySalonContracts.ViewModels;
using BeautySalonDataModels.Models;
using System.ComponentModel.DataAnnotations;
@@ -34,16 +35,48 @@ namespace BeautySalonDatabaseImplement.Models
return new Visit()
{
Id = model.Id,
- MasterId = model.MasterId,
ClientId = model.ClientId,
- ServiceId = model.ServiceId,
- MasterFIO = model.MasterFIO,
ClientFIO = model.ClientFIO,
+ MasterId = model.MasterId,
+ MasterFIO = model.MasterFIO,
+ ServiceId = model.ServiceId,
ServiceName = model.ServiceName,
Count = model.Count,
Sum = model.Sum,
DateOfVisit = model.DateOfVisit
};
}
+
+ public void Update(VisitBindingModel? model)
+ {
+ if (model == null)
+ {
+ return;
+ }
+
+ ClientId = model.ClientId;
+ ClientFIO = model.ClientFIO;
+ MasterId = model.MasterId;
+ MasterFIO = model.MasterFIO;
+ ServiceId = model.ServiceId;
+ ServiceName = model.ServiceName;
+ Count = model.Count;
+ Sum = model.Sum;
+ DateOfVisit = model.DateOfVisit;
+ }
+
+ public VisitViewModel GetViewModel => new()
+ {
+ Id = Id,
+ ClientId = ClientId,
+ ClientFIO = ClientFIO,
+ MasterId = MasterId,
+ MasterFIO = MasterFIO,
+ ServiceId = ServiceId,
+ ServiceName = ServiceName,
+ Count = Count,
+ Sum = Sum,
+ DateOfVisit = DateOfVisit
+ };
}
}
diff --git a/BeauySalonContracts/ViewModels/VisitViewModel.cs b/BeauySalonContracts/ViewModels/VisitViewModel.cs
index cab63b9..bfeef3a 100644
--- a/BeauySalonContracts/ViewModels/VisitViewModel.cs
+++ b/BeauySalonContracts/ViewModels/VisitViewModel.cs
@@ -9,8 +9,14 @@ namespace BeautySalonContracts.ViewModels
[DisplayName("Дата посещения")]
public DateTime DateOfVisit { get; set; }
public int ClientId { get; set; }
+ [DisplayName("Клиент")]
+ public string ClientFIO { get; set; } = string.Empty;
public int MasterId { get; set; }
+ [DisplayName("Мастер")]
+ public string MasterFIO { get; set; } = string.Empty;
public int ServiceId { get; set; }
+ [DisplayName("Услуга")]
+ public string ServiceName { get; set; } = string.Empty;
[DisplayName("Сумма")]
public double Sum { get; set; }
[DisplayName("Количество")]