добавлена бд

This commit is contained in:
Татьяна Артамонова 2023-05-13 16:10:51 +04:00
parent 1698a08f96
commit 9577664444
11 changed files with 1019 additions and 7 deletions

View File

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

View File

@ -6,12 +6,13 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<Folder Include="Implements\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>

View File

@ -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<ClientViewModel> 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<ClientViewModel> 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;
}
}
}

View File

@ -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<MasterViewModel> 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<MasterViewModel> 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;
}
}
}

View File

@ -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<ServiceViewModel> GetFullList()
{
using var context = new BeautySalonDatabase();
return context.Services
.Select(x => x.GetViewModel)
.ToList();
}
public List<ServiceViewModel> 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;
}
}
}

View File

@ -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<VisitViewModel> 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<VisitViewModel> 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;
}
}
}

View File

@ -0,0 +1,225 @@
// <auto-generated />
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
{
/// <inheritdoc />
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<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("ClientFIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("PhoneNumber")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Clients");
});
modelBuilder.Entity("BeautySalonDatabaseImplement.Models.Master", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("MasterFIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Specialization")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Masters");
});
modelBuilder.Entity("BeautySalonDatabaseImplement.Models.MasterService", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("MasterId")
.HasColumnType("int");
b.Property<int>("ServiceId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("MasterId");
b.HasIndex("ServiceId");
b.ToTable("MasterServices");
});
modelBuilder.Entity("BeautySalonDatabaseImplement.Models.Service", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<double>("Cost")
.HasColumnType("float");
b.Property<string>("ServiceName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Services");
});
modelBuilder.Entity("BeautySalonDatabaseImplement.Models.Visit", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("ClientFIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("ClientId")
.HasColumnType("int");
b.Property<int>("Count")
.HasColumnType("int");
b.Property<DateTime>("DateOfVisit")
.HasColumnType("datetime2");
b.Property<string>("MasterFIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("MasterId")
.HasColumnType("int");
b.Property<int>("ServiceId")
.HasColumnType("int");
b.Property<string>("ServiceName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("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
}
}
}

View File

@ -0,0 +1,167 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace BeautySalonDatabaseImplement.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: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ClientFIO = table.Column<string>(type: "nvarchar(max)", nullable: false),
PhoneNumber = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Clients", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Masters",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
MasterFIO = table.Column<string>(type: "nvarchar(max)", nullable: false),
Specialization = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Masters", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Services",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
ServiceName = table.Column<string>(type: "nvarchar(max)", nullable: false),
Cost = table.Column<double>(type: "float", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Services", x => x.Id);
});
migrationBuilder.CreateTable(
name: "MasterServices",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
MasterId = table.Column<int>(type: "int", nullable: false),
ServiceId = table.Column<int>(type: "int", nullable: false),
Count = table.Column<int>(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<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
DateOfVisit = table.Column<DateTime>(type: "datetime2", nullable: false),
ClientId = table.Column<int>(type: "int", nullable: false),
MasterId = table.Column<int>(type: "int", nullable: false),
ServiceId = table.Column<int>(type: "int", nullable: false),
ClientFIO = table.Column<string>(type: "nvarchar(max)", nullable: false),
MasterFIO = table.Column<string>(type: "nvarchar(max)", nullable: false),
ServiceName = table.Column<string>(type: "nvarchar(max)", nullable: false),
Sum = table.Column<double>(type: "float", nullable: false),
Count = table.Column<int>(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");
}
/// <inheritdoc />
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");
}
}
}

View File

@ -0,0 +1,222 @@
// <auto-generated />
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<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("ClientFIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("PhoneNumber")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Clients");
});
modelBuilder.Entity("BeautySalonDatabaseImplement.Models.Master", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("MasterFIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("Specialization")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Masters");
});
modelBuilder.Entity("BeautySalonDatabaseImplement.Models.MasterService", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("Count")
.HasColumnType("int");
b.Property<int>("MasterId")
.HasColumnType("int");
b.Property<int>("ServiceId")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("MasterId");
b.HasIndex("ServiceId");
b.ToTable("MasterServices");
});
modelBuilder.Entity("BeautySalonDatabaseImplement.Models.Service", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<double>("Cost")
.HasColumnType("float");
b.Property<string>("ServiceName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.HasKey("Id");
b.ToTable("Services");
});
modelBuilder.Entity("BeautySalonDatabaseImplement.Models.Visit", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("ClientFIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("ClientId")
.HasColumnType("int");
b.Property<int>("Count")
.HasColumnType("int");
b.Property<DateTime>("DateOfVisit")
.HasColumnType("datetime2");
b.Property<string>("MasterFIO")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("MasterId")
.HasColumnType("int");
b.Property<int>("ServiceId")
.HasColumnType("int");
b.Property<string>("ServiceName")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<double>("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
}
}
}

View File

@ -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
};
}
}

View File

@ -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("Количество")]