КРУДЫЫ РАБОТАЮТ
This commit is contained in:
parent
2dfdf5d21d
commit
231063ed16
@ -7,11 +7,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BeautySaloonView", "BeautyS
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BeautySaloonDataModels", "BeautySaloonDataModels\BeautySaloonDataModels.csproj", "{A83AC6FD-F6BD-4BD2-AC69-3BB5BA30FF7D}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BeautySaloonContracts", "BeautySaloonContracts\BeautySaloonContracts.csproj", "{7494D3AF-2581-4128-9183-BB87A9DC4B10}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BeautySaloonContracts", "BeautySaloonContracts\BeautySaloonContracts.csproj", "{7494D3AF-2581-4128-9183-BB87A9DC4B10}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BeautySaloonBusinessLogic", "BeautySaloonBusinessLogic\BeautySaloonBusinessLogic.csproj", "{E43A1394-BC9A-430B-B984-BCCD828FFF45}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BeautySaloonBusinessLogic", "BeautySaloonBusinessLogic\BeautySaloonBusinessLogic.csproj", "{E43A1394-BC9A-430B-B984-BCCD828FFF45}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BeautySaloonDatabaseImplement", "BeautySaloonDatabaseImplement\BeautySaloonDatabaseImplement.csproj", "{BB7AD640-FF4A-415B-A09B-BB802D64CE27}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BeautySaloonDatabaseImplement", "BeautySaloonDatabaseImplement\BeautySaloonDatabaseImplement.csproj", "{BB7AD640-FF4A-415B-A09B-BB802D64CE27}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
|
@ -6,6 +6,14 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.4">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\BeautySaloonContracts\BeautySaloonContracts.csproj" />
|
||||
</ItemGroup>
|
||||
|
@ -6,6 +6,14 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.4">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\BeautySaloonDataModels\BeautySaloonDataModels.csproj" />
|
||||
</ItemGroup>
|
||||
|
@ -6,4 +6,12 @@
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.4">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@ -2,6 +2,7 @@
|
||||
using BeautySaloonContracts.SearchModels;
|
||||
using BeautySaloonContracts.StoragesContracts;
|
||||
using BeautySaloonContracts.ViewModels;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace BeautySaloonDatabaseImplement.Implements
|
||||
{
|
||||
@ -11,6 +12,8 @@ namespace BeautySaloonDatabaseImplement.Implements
|
||||
{
|
||||
using var context = new NewdbContext();
|
||||
var element = context.Orders
|
||||
.Include(x => x.Employee)
|
||||
.Include(x => x.Client)
|
||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (element != null)
|
||||
{
|
||||
@ -26,6 +29,8 @@ namespace BeautySaloonDatabaseImplement.Implements
|
||||
using var context = new NewdbContext();
|
||||
if (model.Id.HasValue)
|
||||
return context.Orders
|
||||
.Include(x => x.Employee)
|
||||
.Include(x => x.Client)
|
||||
.FirstOrDefault(x => x.Id == model.Id)?
|
||||
.GetViewModel;
|
||||
return null;
|
||||
@ -36,16 +41,22 @@ namespace BeautySaloonDatabaseImplement.Implements
|
||||
using var context = new NewdbContext();
|
||||
if (model.ClientId.HasValue)
|
||||
return context.Orders
|
||||
.Include(x => x.Employee)
|
||||
.Include(x => x.Client)
|
||||
.Where(x => x.ClientId == model.ClientId)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
if (model.EmployeeId.HasValue)
|
||||
return context.Orders
|
||||
.Include(x => x.Employee)
|
||||
.Include(x => x.Client)
|
||||
.Where(x => x.EmployeeId == model.EmployeeId)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
if (model.Date.HasValue)
|
||||
return context.Orders
|
||||
.Include(x => x.Employee)
|
||||
.Include(x => x.Client)
|
||||
.Where(x => x.Date == model.Date)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
@ -56,6 +67,8 @@ namespace BeautySaloonDatabaseImplement.Implements
|
||||
{
|
||||
using var context = new NewdbContext();
|
||||
return context.Orders
|
||||
.Include(x => x.Employee)
|
||||
.Include(x => x.Client)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
@ -64,6 +77,8 @@ namespace BeautySaloonDatabaseImplement.Implements
|
||||
{
|
||||
using var context = new NewdbContext();
|
||||
model.Id = context.Orders
|
||||
.Include(x => x.Employee)
|
||||
.Include(x => x.Client)
|
||||
.Count() > 0 ? context.Orders.Max(x => x.Id) + 1 : 1;
|
||||
var newOrder = Order.Create(context, model);
|
||||
if (newOrder == null)
|
||||
@ -72,7 +87,10 @@ namespace BeautySaloonDatabaseImplement.Implements
|
||||
}
|
||||
context.Orders.Add(newOrder);
|
||||
context.SaveChanges();
|
||||
return newOrder.GetViewModel;
|
||||
return context.Orders
|
||||
.Include(x => x.Employee)
|
||||
.Include(x => x.Client).FirstOrDefault(x => x.Id == newOrder.Id)
|
||||
?.GetViewModel;
|
||||
}
|
||||
|
||||
public OrderViewModel? Update(OrderBindingModel model)
|
||||
@ -81,7 +99,8 @@ namespace BeautySaloonDatabaseImplement.Implements
|
||||
using var transaction = context.Database.BeginTransaction();
|
||||
try
|
||||
{
|
||||
var order = context.Orders.FirstOrDefault(rec => rec.Id == model.Id);
|
||||
var order = context.Orders.Include(x => x.Employee)
|
||||
.Include(x => x.Client).FirstOrDefault(rec => rec.Id == model.Id);
|
||||
if (order == null)
|
||||
{
|
||||
return null;
|
||||
|
@ -174,10 +174,6 @@ public partial class NewdbContext : DbContext
|
||||
|
||||
entity.ToTable("service_order", tb => tb.HasComment("Сущность-связь услуги с заказом"));
|
||||
|
||||
entity.HasIndex(e => e.OrderId, "service_order_orderid_key").IsUnique();
|
||||
|
||||
entity.HasIndex(e => e.ServiceId, "service_order_serviceid_key").IsUnique();
|
||||
|
||||
entity.Property(e => e.ServiceId)
|
||||
.HasComment("Составной первичный ключ: идентификатор услуги")
|
||||
.HasColumnName("service_id");
|
||||
@ -194,18 +190,18 @@ public partial class NewdbContext : DbContext
|
||||
|
||||
entity.HasOne(d => d.Employee).WithMany(p => p.ServiceOrders)
|
||||
.HasForeignKey(d => d.EmployeeId)
|
||||
.OnDelete(DeleteBehavior.ClientSetNull)
|
||||
.HasConstraintName("employee_fk");
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.HasConstraintName("service_order_employee_id_fkey");
|
||||
|
||||
entity.HasOne(d => d.Order).WithOne(p => p.ServiceOrder)
|
||||
.HasForeignKey<ServiceOrder>(d => d.OrderId)
|
||||
.OnDelete(DeleteBehavior.ClientSetNull)
|
||||
.HasConstraintName("order_fk");
|
||||
entity.HasOne(d => d.Order).WithMany(p => p.ServiceOrders)
|
||||
.HasForeignKey(d => d.OrderId)
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.HasConstraintName("service_order_order_id_fkey");
|
||||
|
||||
entity.HasOne(d => d.Service).WithOne(p => p.ServiceOrder)
|
||||
.HasForeignKey<ServiceOrder>(d => d.ServiceId)
|
||||
.OnDelete(DeleteBehavior.ClientSetNull)
|
||||
.HasConstraintName("service_fk");
|
||||
entity.HasOne(d => d.Service).WithMany(p => p.ServiceOrders)
|
||||
.HasForeignKey(d => d.ServiceId)
|
||||
.OnDelete(DeleteBehavior.Restrict)
|
||||
.HasConstraintName("service_order_service_id_fkey");
|
||||
});
|
||||
|
||||
OnModelCreatingPartial(modelBuilder);
|
||||
|
@ -1,6 +1,7 @@
|
||||
using BeautySaloonContracts.BindingModels;
|
||||
using BeautySaloonContracts.ViewModels;
|
||||
using BeautySaloonDataModels;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace BeautySaloonDatabaseImplement;
|
||||
|
||||
@ -38,23 +39,19 @@ public partial class Order : IOrderModel
|
||||
|
||||
public virtual Employee Employee { get; set; } = null!;
|
||||
|
||||
public virtual ServiceOrder? ServiceOrder { get; set; }
|
||||
|
||||
public virtual List<ServiceOrder> ServiceOrders { get; set; } = new List<ServiceOrder>();
|
||||
|
||||
public Dictionary<int, (TimeOnly, IServiceModel, int)> _orderServices = null;
|
||||
|
||||
public virtual List<ServiceOrder> Services { get; set; } = new();
|
||||
|
||||
public Dictionary<int, (TimeOnly, IServiceModel, int)> OrderServices
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_orderServices == null)
|
||||
{
|
||||
_orderServices = Services
|
||||
.ToDictionary(serviceOrd => serviceOrd.ServiceId,
|
||||
serviceOrd => (serviceOrd.Date, serviceOrd.Service as IServiceModel,
|
||||
serviceOrd.EmployeeId));
|
||||
_orderServices = ServiceOrders
|
||||
.ToDictionary(recPC => recPC.ServiceId,
|
||||
recPC => (recPC.Date, recPC.Service as IServiceModel, recPC.EmployeeId));
|
||||
}
|
||||
return _orderServices;
|
||||
}
|
||||
@ -73,7 +70,7 @@ public partial class Order : IOrderModel
|
||||
Sum = model.Sum,
|
||||
ClientId = model.ClientId,
|
||||
EmployeeId = model.EmployeeId,
|
||||
Services = model.OrderServices.Select(x => new ServiceOrder
|
||||
ServiceOrders = model.OrderServices.Select(x => new ServiceOrder
|
||||
{
|
||||
Service = context.Services.First(y => y.Id == x.Key),
|
||||
Date = x.Value.Item1,
|
||||
|
@ -25,8 +25,7 @@ public partial class Service : IServiceModel
|
||||
/// Цена
|
||||
/// </summary>
|
||||
public decimal Price { get; set; }
|
||||
|
||||
public virtual ServiceOrder? ServiceOrder { get; set; }
|
||||
public virtual ICollection<ServiceOrder> ServiceOrders { get; } = new List<ServiceOrder>();
|
||||
|
||||
public static Service Create(ServiceBindingModel model)
|
||||
{
|
||||
|
@ -13,7 +13,12 @@
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.4">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
|
||||
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
@ -1,7 +1,6 @@
|
||||
using BeautySaloonContracts.BindingModels;
|
||||
using BeautySaloonContracts.BusinessLogicsContracts;
|
||||
using BeautySaloonContracts.SearchModels;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
|
||||
namespace BeautySaloonView
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user