Compare commits
No commits in common. "f1ff090bc19537e4dcbc657f4d2d0cc76984368c" and "55dcc5a9a79b0689e557e16f2241acd5defe32c3" have entirely different histories.
f1ff090bc1
...
55dcc5a9a7
@ -13,9 +13,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PizzeriaBusinessLogic", "Pi
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PizzeriaListImplement", "PizzeriaListImplement\PizzeriaListImplement.csproj", "{138A775B-55CA-4120-918F-6093C0B2B241}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PizzeriaListImplement", "PizzeriaListImplement\PizzeriaListImplement.csproj", "{138A775B-55CA-4120-918F-6093C0B2B241}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PizzeriaFileImplement", "PizzeriaShopFileImplement\PizzeriaFileImplement.csproj", "{44B31B6F-2852-454B-9E7D-E965C9A348ED}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PizzeriaFileImplement", "PizzeriaShopFileImplement\PizzeriaFileImplement.csproj", "{44B31B6F-2852-454B-9E7D-E965C9A348ED}"
|
||||||
EndProject
|
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PizzeriaDatabaseImplement", "PizzeriaDatabaseImplement\PizzeriaDatabaseImplement.csproj", "{37411F99-74EC-476C-BE13-D20015ED52B2}"
|
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@ -47,10 +45,6 @@ Global
|
|||||||
{44B31B6F-2852-454B-9E7D-E965C9A348ED}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{44B31B6F-2852-454B-9E7D-E965C9A348ED}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{44B31B6F-2852-454B-9E7D-E965C9A348ED}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{44B31B6F-2852-454B-9E7D-E965C9A348ED}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{44B31B6F-2852-454B-9E7D-E965C9A348ED}.Release|Any CPU.Build.0 = Release|Any CPU
|
{44B31B6F-2852-454B-9E7D-E965C9A348ED}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
{37411F99-74EC-476C-BE13-D20015ED52B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
|
||||||
{37411F99-74EC-476C-BE13-D20015ED52B2}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
|
||||||
{37411F99-74EC-476C-BE13-D20015ED52B2}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
|
||||||
{37411F99-74EC-476C-BE13-D20015ED52B2}.Release|Any CPU.Build.0 = Release|Any CPU
|
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
@ -81,7 +81,7 @@ namespace Pizzeria
|
|||||||
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
|
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
|
||||||
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
|
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
|
||||||
PizzaId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["PizzaId"].Value.ToString()),
|
PizzaId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["PizzaId"].Value.ToString()),
|
||||||
DateCreate = DateTime.SpecifyKind(DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()), DateTimeKind.Utc),
|
DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
private void ButtonTakeOrderInWork_Click(object sender, EventArgs e)
|
private void ButtonTakeOrderInWork_Click(object sender, EventArgs e)
|
||||||
|
@ -9,10 +9,6 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.3">
|
|
||||||
<PrivateAssets>all</PrivateAssets>
|
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
|
||||||
</PackageReference>
|
|
||||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
||||||
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.1" />
|
<PackageReference Include="NLog.Extensions.Logging" Version="5.2.1" />
|
||||||
@ -20,7 +16,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\PizzeriaBusinessLogic\PizzeriaBusinessLogic.csproj" />
|
<ProjectReference Include="..\PizzeriaBusinessLogic\PizzeriaBusinessLogic.csproj" />
|
||||||
<ProjectReference Include="..\PizzeriaDatabaseImplement\PizzeriaDatabaseImplement.csproj" />
|
<ProjectReference Include="..\PizzeriaContracts\PizzeriaContracts.csproj" />
|
||||||
<ProjectReference Include="..\PizzeriaDataModels\PizzeriaDataModels.csproj" />
|
<ProjectReference Include="..\PizzeriaDataModels\PizzeriaDataModels.csproj" />
|
||||||
<ProjectReference Include="..\PizzeriaShopFileImplement\PizzeriaFileImplement.csproj" />
|
<ProjectReference Include="..\PizzeriaShopFileImplement\PizzeriaFileImplement.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
using PizzeriaBusinessLogic;
|
using PizzeriaBusinessLogic;
|
||||||
using PizzeriaContracts.BusinessLogicsContracts;
|
using PizzeriaContracts.BusinessLogicsContracts;
|
||||||
using PizzeriaContracts.StoragesContracts;
|
using PizzeriaContracts.StoragesContracts;
|
||||||
using PizzeriaDatabaseImplement.Implements;
|
using PizzeriaFileImplement.Implements;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using NLog.Extensions.Logging;
|
using NLog.Extensions.Logging;
|
||||||
|
@ -67,7 +67,7 @@ namespace PizzeriaBusinessLogic
|
|||||||
|
|
||||||
if(newStatus == OrderStatus.Выдан)
|
if(newStatus == OrderStatus.Выдан)
|
||||||
{
|
{
|
||||||
model.DateImplement = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
|
model.DateImplement = DateTime.Now;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newStatus == OrderStatus.Готов)
|
if (newStatus == OrderStatus.Готов)
|
||||||
|
@ -14,7 +14,7 @@ namespace PizzeriaContracts.BindingModels
|
|||||||
public int Count { get; set; }
|
public int Count { get; set; }
|
||||||
public double Sum { get; set; }
|
public double Sum { get; set; }
|
||||||
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
|
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
|
||||||
public DateTime DateCreate { get; set; } = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
|
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||||
public DateTime? DateImplement { get; set; }
|
public DateTime? DateImplement { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,83 +0,0 @@
|
|||||||
using PizzeriaContracts.BindingModels;
|
|
||||||
using PizzeriaContracts.SearchModels;
|
|
||||||
using PizzeriaContracts.StoragesContracts;
|
|
||||||
using PizzeriaContracts.ViewModels;
|
|
||||||
using PizzeriaDatabaseImplement.models;
|
|
||||||
namespace PizzeriaDatabaseImplement.Implements
|
|
||||||
{
|
|
||||||
public class ComponentStorage : IComponentStorage
|
|
||||||
{
|
|
||||||
public List<ComponentViewModel> GetFullList()
|
|
||||||
{
|
|
||||||
using var context = new PizzeriaDatabase();
|
|
||||||
return context.Components
|
|
||||||
.Select(x => x.GetViewModel)
|
|
||||||
.ToList();
|
|
||||||
}
|
|
||||||
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel
|
|
||||||
model)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(model.ComponentName))
|
|
||||||
{
|
|
||||||
return new();
|
|
||||||
}
|
|
||||||
using var context = new PizzeriaDatabase();
|
|
||||||
return context.Components
|
|
||||||
.Where(x => x.ComponentName.Contains(model.ComponentName))
|
|
||||||
.Select(x => x.GetViewModel)
|
|
||||||
.ToList();
|
|
||||||
}
|
|
||||||
public ComponentViewModel? GetElement(ComponentSearchModel model)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(model.ComponentName) && !model.Id.HasValue)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
using var context = new PizzeriaDatabase();
|
|
||||||
return context.Components
|
|
||||||
.FirstOrDefault(x =>
|
|
||||||
(!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName ==
|
|
||||||
model.ComponentName) ||
|
|
||||||
(model.Id.HasValue && x.Id == model.Id))
|
|
||||||
?.GetViewModel;
|
|
||||||
}
|
|
||||||
public ComponentViewModel? Insert(ComponentBindingModel model)
|
|
||||||
{
|
|
||||||
var newComponent = Component.Create(model);
|
|
||||||
if (newComponent == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
using var context = new PizzeriaDatabase();
|
|
||||||
context.Components.Add(newComponent);
|
|
||||||
context.SaveChanges();
|
|
||||||
return newComponent.GetViewModel;
|
|
||||||
}
|
|
||||||
public ComponentViewModel? Update(ComponentBindingModel model)
|
|
||||||
{
|
|
||||||
using var context = new PizzeriaDatabase();
|
|
||||||
var component = context.Components.FirstOrDefault(x => x.Id ==
|
|
||||||
model.Id);
|
|
||||||
if (component == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
component.Update(model);
|
|
||||||
context.SaveChanges();
|
|
||||||
return component.GetViewModel;
|
|
||||||
}
|
|
||||||
public ComponentViewModel? Delete(ComponentBindingModel model)
|
|
||||||
{
|
|
||||||
using var context = new PizzeriaDatabase();
|
|
||||||
var element = context.Components.FirstOrDefault(rec => rec.Id ==
|
|
||||||
model.Id);
|
|
||||||
if (element != null)
|
|
||||||
{
|
|
||||||
context.Components.Remove(element);
|
|
||||||
context.SaveChanges();
|
|
||||||
return element.GetViewModel;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,72 +0,0 @@
|
|||||||
using PizzeriaContracts.BindingModels;
|
|
||||||
using PizzeriaContracts.SearchModels;
|
|
||||||
using PizzeriaContracts.StoragesContracts;
|
|
||||||
using PizzeriaContracts.ViewModels;
|
|
||||||
using PizzeriaDatabaseImplement.models;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
|
|
||||||
namespace PizzeriaDatabaseImplement.Implements
|
|
||||||
{
|
|
||||||
public class OrderStorage : IOrderStorage
|
|
||||||
{
|
|
||||||
public List<OrderViewModel> GetFullList()
|
|
||||||
{
|
|
||||||
using var context = new PizzeriaDatabase();
|
|
||||||
return context.Orders
|
|
||||||
.Include(x => x.Pizza)
|
|
||||||
.Select(x => x.GetViewModel)
|
|
||||||
.ToList();
|
|
||||||
}
|
|
||||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
|
||||||
{
|
|
||||||
using var context = new PizzeriaDatabase();
|
|
||||||
return context.Orders
|
|
||||||
.Where(x => (model.Id.HasValue && x.Id == model.Id))
|
|
||||||
.Select(x => x.GetViewModel)
|
|
||||||
.ToList();
|
|
||||||
}
|
|
||||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
|
||||||
{
|
|
||||||
using var context = new PizzeriaDatabase();
|
|
||||||
return context.Orders
|
|
||||||
.FirstOrDefault(x =>
|
|
||||||
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
|
||||||
}
|
|
||||||
public OrderViewModel? Insert(OrderBindingModel model)
|
|
||||||
{
|
|
||||||
using var context = new PizzeriaDatabase();
|
|
||||||
Order newOrder = Order.Create(context, model);
|
|
||||||
|
|
||||||
context.Orders.Add(newOrder);
|
|
||||||
context.SaveChanges();
|
|
||||||
return newOrder.GetViewModel;
|
|
||||||
|
|
||||||
}
|
|
||||||
public OrderViewModel? Update(OrderBindingModel model)
|
|
||||||
{
|
|
||||||
using var context = new PizzeriaDatabase();
|
|
||||||
var order = context.Orders.FirstOrDefault(x => x.Id == model.Id);
|
|
||||||
if (order == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
order.Update(model);
|
|
||||||
context.SaveChanges();
|
|
||||||
return order.GetViewModel;
|
|
||||||
}
|
|
||||||
public OrderViewModel? Delete(OrderBindingModel model)
|
|
||||||
{
|
|
||||||
using var context = new PizzeriaDatabase();
|
|
||||||
var element = context.Orders.FirstOrDefault(rec => rec.Id == model.Id);
|
|
||||||
if (element != null)
|
|
||||||
{
|
|
||||||
context.Orders.Remove(element);
|
|
||||||
context.SaveChanges();
|
|
||||||
return element.GetViewModel;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,104 +0,0 @@
|
|||||||
using PizzeriaContracts.BindingModels;
|
|
||||||
using PizzeriaContracts.SearchModels;
|
|
||||||
using PizzeriaContracts.StoragesContracts;
|
|
||||||
using PizzeriaContracts.ViewModels;
|
|
||||||
using PizzeriaDatabaseImplement.models;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
namespace PizzeriaDatabaseImplement.Implements
|
|
||||||
{
|
|
||||||
public class PizzaStorage : IPizzaStorage
|
|
||||||
{
|
|
||||||
public List<PizzaViewModel> GetFullList()
|
|
||||||
{
|
|
||||||
using var context = new PizzeriaDatabase();
|
|
||||||
return context.Pizzas
|
|
||||||
.Include(x => x.Components)
|
|
||||||
.ThenInclude(x => x.Component)
|
|
||||||
.ToList()
|
|
||||||
.Select(x => x.GetViewModel)
|
|
||||||
.ToList();
|
|
||||||
}
|
|
||||||
public List<PizzaViewModel> GetFilteredList(PizzaSearchModel model)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(model.PizzaName))
|
|
||||||
{
|
|
||||||
return new();
|
|
||||||
}
|
|
||||||
using var context = new PizzeriaDatabase();
|
|
||||||
return context.Pizzas
|
|
||||||
.Include(x => x.Components)
|
|
||||||
.ThenInclude(x => x.Component)
|
|
||||||
.Where(x => x.PizzaName.Contains(model.PizzaName))
|
|
||||||
.ToList()
|
|
||||||
.Select(x => x.GetViewModel)
|
|
||||||
.ToList();
|
|
||||||
}
|
|
||||||
public PizzaViewModel? GetElement(PizzaSearchModel model)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(model.PizzaName) &&
|
|
||||||
!model.Id.HasValue)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
using var context = new PizzeriaDatabase();
|
|
||||||
return context.Pizzas
|
|
||||||
.Include(x => x.Components)
|
|
||||||
.ThenInclude(x => x.Component)
|
|
||||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.PizzaName) &&
|
|
||||||
x.PizzaName == model.PizzaName) ||
|
|
||||||
(model.Id.HasValue && x.Id ==
|
|
||||||
model.Id))
|
|
||||||
?.GetViewModel;
|
|
||||||
}
|
|
||||||
public PizzaViewModel? Insert(PizzaBindingModel model)
|
|
||||||
{
|
|
||||||
using var context = new PizzeriaDatabase();
|
|
||||||
var newPizza = Pizza.Create(context, model);
|
|
||||||
if (newPizza == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
context.Pizzas.Add(newPizza);
|
|
||||||
context.SaveChanges();
|
|
||||||
return newPizza.GetViewModel;
|
|
||||||
}
|
|
||||||
public PizzaViewModel? Update(PizzaBindingModel model)
|
|
||||||
{
|
|
||||||
using var context = new PizzeriaDatabase();
|
|
||||||
using var transaction = context.Database.BeginTransaction();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var pizza = context.Pizzas.FirstOrDefault(rec =>
|
|
||||||
rec.Id == model.Id);
|
|
||||||
if (pizza == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
pizza.Update(model);
|
|
||||||
context.SaveChanges();
|
|
||||||
pizza.UpdateComponents(context, model);
|
|
||||||
transaction.Commit();
|
|
||||||
return pizza.GetViewModel;
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
transaction.Rollback();
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public PizzaViewModel? Delete(PizzaBindingModel model)
|
|
||||||
{
|
|
||||||
using var context = new PizzeriaDatabase();
|
|
||||||
var element = context.Pizzas
|
|
||||||
.Include(x => x.Components)
|
|
||||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
|
||||||
if (element != null)
|
|
||||||
{
|
|
||||||
context.Pizzas.Remove(element);
|
|
||||||
context.SaveChanges();
|
|
||||||
return element.GetViewModel;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,152 +0,0 @@
|
|||||||
using PizzeriaContracts.BindingModels;
|
|
||||||
using PizzeriaContracts.SearchModels;
|
|
||||||
using PizzeriaContracts.StoragesContracts;
|
|
||||||
using PizzeriaContracts.ViewModels;
|
|
||||||
using PizzeriaDatabaseImplement.models;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using PizzeriaDataModels;
|
|
||||||
|
|
||||||
namespace PizzeriaDatabaseImplement.Implements
|
|
||||||
{
|
|
||||||
public class ShopStorage : IShopStorage
|
|
||||||
{
|
|
||||||
public List<ShopViewModel> GetFullList()
|
|
||||||
{
|
|
||||||
using var context = new PizzeriaDatabase();
|
|
||||||
return context.Shops
|
|
||||||
.Include(x => x.Pizzas)
|
|
||||||
.ThenInclude(x => x.Pizza)
|
|
||||||
.ToList()
|
|
||||||
.Select(x => x.GetViewModel)
|
|
||||||
.ToList();
|
|
||||||
}
|
|
||||||
public List<ShopViewModel> GetFilteredList(ShopSearchModel model)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(model.ShopName))
|
|
||||||
{
|
|
||||||
return new();
|
|
||||||
}
|
|
||||||
using var context = new PizzeriaDatabase();
|
|
||||||
return context.Shops
|
|
||||||
.Include(x => x.Pizzas)
|
|
||||||
.ThenInclude(x => x.Pizza)
|
|
||||||
.Where(x => x.ShopName.Contains(model.ShopName))
|
|
||||||
.ToList()
|
|
||||||
.Select(x => x.GetViewModel)
|
|
||||||
.ToList();
|
|
||||||
}
|
|
||||||
public ShopViewModel? GetElement(ShopSearchModel model)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(model.ShopName) &&
|
|
||||||
!model.Id.HasValue)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
using var context = new PizzeriaDatabase();
|
|
||||||
return context.Shops
|
|
||||||
.Include(x => x.Pizzas)
|
|
||||||
.ThenInclude(x => x.Pizza)
|
|
||||||
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ShopName) &&
|
|
||||||
x.ShopName == model.ShopName) ||
|
|
||||||
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
|
||||||
|
|
||||||
}
|
|
||||||
public ShopViewModel? Insert(ShopBindingModel model)
|
|
||||||
{
|
|
||||||
using var context = new PizzeriaDatabase();
|
|
||||||
var newShop = Shop.Create(context, model);
|
|
||||||
|
|
||||||
if (context.Shops.Any(x => x.ShopName == newShop.ShopName))
|
|
||||||
{
|
|
||||||
throw new Exception("Магазин с таким названием уже существует");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (newShop == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
context.Shops.Add(newShop);
|
|
||||||
context.SaveChanges();
|
|
||||||
return newShop.GetViewModel;
|
|
||||||
}
|
|
||||||
public ShopViewModel? Update(ShopBindingModel model)
|
|
||||||
{
|
|
||||||
using var context = new PizzeriaDatabase();
|
|
||||||
using var transaction = context.Database.BeginTransaction();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var shop = context.Shops.FirstOrDefault(rec =>
|
|
||||||
rec.Id == model.Id);
|
|
||||||
if (shop == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
shop.Update(model);
|
|
||||||
context.SaveChanges();
|
|
||||||
shop.UpdatePizzas(context, model);
|
|
||||||
transaction.Commit();
|
|
||||||
return shop.GetViewModel;
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
transaction.Rollback();
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public ShopViewModel? Delete(ShopBindingModel model)
|
|
||||||
{
|
|
||||||
using var context = new PizzeriaDatabase();
|
|
||||||
var element = context.Shops
|
|
||||||
.Include(x => x.Pizzas)
|
|
||||||
.FirstOrDefault(rec => rec.Id == model.Id);
|
|
||||||
if (element != null)
|
|
||||||
{
|
|
||||||
context.Shops.Remove(element);
|
|
||||||
context.SaveChanges();
|
|
||||||
return element.GetViewModel;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool TrySellPizza(IPizzaModel pizza, int count)
|
|
||||||
{
|
|
||||||
using var context = new PizzeriaDatabase();
|
|
||||||
using var transaction = context.Database.BeginTransaction();
|
|
||||||
|
|
||||||
foreach (var shopPizzas in context.ShopPizzas.Where(x => x.PizzaId == pizza.Id))
|
|
||||||
{
|
|
||||||
var min = Math.Min(count, shopPizzas.Count);
|
|
||||||
shopPizzas.Count -= min;
|
|
||||||
count -= min;
|
|
||||||
|
|
||||||
if (count <= 0)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count == 0)
|
|
||||||
{
|
|
||||||
context.SaveChanges();
|
|
||||||
transaction.Commit();
|
|
||||||
}
|
|
||||||
|
|
||||||
else
|
|
||||||
{
|
|
||||||
transaction.Rollback();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (count > 0)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool TryRestoreShops(IPizzaModel pizza, int count)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,172 +0,0 @@
|
|||||||
// <auto-generated />
|
|
||||||
using System;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
|
||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
|
||||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|
||||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
|
||||||
using PizzeriaDatabaseImplement;
|
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
namespace PizzeriaDatabaseImplement.Migrations
|
|
||||||
{
|
|
||||||
[DbContext(typeof(PizzeriaDatabase))]
|
|
||||||
[Migration("20230228062848_Init")]
|
|
||||||
partial class Init
|
|
||||||
{
|
|
||||||
/// <inheritdoc />
|
|
||||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
|
||||||
{
|
|
||||||
#pragma warning disable 612, 618
|
|
||||||
modelBuilder
|
|
||||||
.HasAnnotation("ProductVersion", "7.0.3")
|
|
||||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
|
||||||
|
|
||||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
|
||||||
|
|
||||||
modelBuilder.Entity("PizzeriaDatabaseImplement.models.Component", b =>
|
|
||||||
{
|
|
||||||
b.Property<int>("Id")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
|
||||||
|
|
||||||
b.Property<string>("ComponentName")
|
|
||||||
.IsRequired()
|
|
||||||
.HasColumnType("text");
|
|
||||||
|
|
||||||
b.Property<double>("Cost")
|
|
||||||
.HasColumnType("double precision");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.ToTable("Components");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("PizzeriaDatabaseImplement.models.Order", b =>
|
|
||||||
{
|
|
||||||
b.Property<int>("Id")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
|
||||||
|
|
||||||
b.Property<int>("Count")
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
b.Property<DateTime>("DateCreate")
|
|
||||||
.HasColumnType("timestamp with time zone");
|
|
||||||
|
|
||||||
b.Property<DateTime?>("DateImplement")
|
|
||||||
.IsRequired()
|
|
||||||
.HasColumnType("timestamp with time zone");
|
|
||||||
|
|
||||||
b.Property<int>("PizzaId")
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
b.Property<int>("Status")
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
b.Property<double>("Sum")
|
|
||||||
.HasColumnType("double precision");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.HasIndex("PizzaId");
|
|
||||||
|
|
||||||
b.ToTable("Orders");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("PizzeriaDatabaseImplement.models.Pizza", b =>
|
|
||||||
{
|
|
||||||
b.Property<int>("Id")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
|
||||||
|
|
||||||
b.Property<string>("PizzaName")
|
|
||||||
.IsRequired()
|
|
||||||
.HasColumnType("text");
|
|
||||||
|
|
||||||
b.Property<double>("Price")
|
|
||||||
.HasColumnType("double precision");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.ToTable("Pizzas");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("PizzeriaDatabaseImplement.models.PizzaComponent", b =>
|
|
||||||
{
|
|
||||||
b.Property<int>("Id")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
|
||||||
|
|
||||||
b.Property<int>("ComponentId")
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
b.Property<int>("Count")
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
b.Property<int>("PizzaId")
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.HasIndex("ComponentId");
|
|
||||||
|
|
||||||
b.HasIndex("PizzaId");
|
|
||||||
|
|
||||||
b.ToTable("PizzaComponents");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("PizzeriaDatabaseImplement.models.Order", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("PizzeriaDatabaseImplement.models.Pizza", "Pizza")
|
|
||||||
.WithMany("Orders")
|
|
||||||
.HasForeignKey("PizzaId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.Navigation("Pizza");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("PizzeriaDatabaseImplement.models.PizzaComponent", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("PizzeriaDatabaseImplement.models.Component", "Component")
|
|
||||||
.WithMany("PizzaComponents")
|
|
||||||
.HasForeignKey("ComponentId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.HasOne("PizzeriaDatabaseImplement.models.Pizza", "Pizza")
|
|
||||||
.WithMany("Components")
|
|
||||||
.HasForeignKey("PizzaId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.Navigation("Component");
|
|
||||||
|
|
||||||
b.Navigation("Pizza");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("PizzeriaDatabaseImplement.models.Component", b =>
|
|
||||||
{
|
|
||||||
b.Navigation("PizzaComponents");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("PizzeriaDatabaseImplement.models.Pizza", b =>
|
|
||||||
{
|
|
||||||
b.Navigation("Components");
|
|
||||||
|
|
||||||
b.Navigation("Orders");
|
|
||||||
});
|
|
||||||
#pragma warning restore 612, 618
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,126 +0,0 @@
|
|||||||
using System;
|
|
||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
|
||||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
namespace PizzeriaDatabaseImplement.Migrations
|
|
||||||
{
|
|
||||||
/// <inheritdoc />
|
|
||||||
public partial class Init : Migration
|
|
||||||
{
|
|
||||||
/// <inheritdoc />
|
|
||||||
protected override void Up(MigrationBuilder migrationBuilder)
|
|
||||||
{
|
|
||||||
migrationBuilder.CreateTable(
|
|
||||||
name: "Components",
|
|
||||||
columns: table => new
|
|
||||||
{
|
|
||||||
Id = table.Column<int>(type: "integer", nullable: false)
|
|
||||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
|
||||||
ComponentName = table.Column<string>(type: "text", nullable: false),
|
|
||||||
Cost = table.Column<double>(type: "double precision", nullable: false)
|
|
||||||
},
|
|
||||||
constraints: table =>
|
|
||||||
{
|
|
||||||
table.PrimaryKey("PK_Components", x => x.Id);
|
|
||||||
});
|
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
|
||||||
name: "Pizzas",
|
|
||||||
columns: table => new
|
|
||||||
{
|
|
||||||
Id = table.Column<int>(type: "integer", nullable: false)
|
|
||||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
|
||||||
PizzaName = table.Column<string>(type: "text", nullable: false),
|
|
||||||
Price = table.Column<double>(type: "double precision", nullable: false)
|
|
||||||
},
|
|
||||||
constraints: table =>
|
|
||||||
{
|
|
||||||
table.PrimaryKey("PK_Pizzas", x => x.Id);
|
|
||||||
});
|
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
|
||||||
name: "Orders",
|
|
||||||
columns: table => new
|
|
||||||
{
|
|
||||||
Id = table.Column<int>(type: "integer", nullable: false)
|
|
||||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
|
||||||
PizzaId = table.Column<int>(type: "integer", nullable: false),
|
|
||||||
Count = table.Column<int>(type: "integer", nullable: false),
|
|
||||||
Sum = table.Column<double>(type: "double precision", nullable: false),
|
|
||||||
Status = table.Column<int>(type: "integer", nullable: false),
|
|
||||||
DateCreate = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
|
|
||||||
DateImplement = table.Column<DateTime>(type: "timestamp with time zone", nullable: false)
|
|
||||||
},
|
|
||||||
constraints: table =>
|
|
||||||
{
|
|
||||||
table.PrimaryKey("PK_Orders", x => x.Id);
|
|
||||||
table.ForeignKey(
|
|
||||||
name: "FK_Orders_Pizzas_PizzaId",
|
|
||||||
column: x => x.PizzaId,
|
|
||||||
principalTable: "Pizzas",
|
|
||||||
principalColumn: "Id",
|
|
||||||
onDelete: ReferentialAction.Cascade);
|
|
||||||
});
|
|
||||||
|
|
||||||
migrationBuilder.CreateTable(
|
|
||||||
name: "PizzaComponents",
|
|
||||||
columns: table => new
|
|
||||||
{
|
|
||||||
Id = table.Column<int>(type: "integer", nullable: false)
|
|
||||||
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
|
|
||||||
PizzaId = table.Column<int>(type: "integer", nullable: false),
|
|
||||||
ComponentId = table.Column<int>(type: "integer", nullable: false),
|
|
||||||
Count = table.Column<int>(type: "integer", nullable: false)
|
|
||||||
},
|
|
||||||
constraints: table =>
|
|
||||||
{
|
|
||||||
table.PrimaryKey("PK_PizzaComponents", x => x.Id);
|
|
||||||
table.ForeignKey(
|
|
||||||
name: "FK_PizzaComponents_Components_ComponentId",
|
|
||||||
column: x => x.ComponentId,
|
|
||||||
principalTable: "Components",
|
|
||||||
principalColumn: "Id",
|
|
||||||
onDelete: ReferentialAction.Cascade);
|
|
||||||
table.ForeignKey(
|
|
||||||
name: "FK_PizzaComponents_Pizzas_PizzaId",
|
|
||||||
column: x => x.PizzaId,
|
|
||||||
principalTable: "Pizzas",
|
|
||||||
principalColumn: "Id",
|
|
||||||
onDelete: ReferentialAction.Cascade);
|
|
||||||
});
|
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
|
||||||
name: "IX_Orders_PizzaId",
|
|
||||||
table: "Orders",
|
|
||||||
column: "PizzaId");
|
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
|
||||||
name: "IX_PizzaComponents_ComponentId",
|
|
||||||
table: "PizzaComponents",
|
|
||||||
column: "ComponentId");
|
|
||||||
|
|
||||||
migrationBuilder.CreateIndex(
|
|
||||||
name: "IX_PizzaComponents_PizzaId",
|
|
||||||
table: "PizzaComponents",
|
|
||||||
column: "PizzaId");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
protected override void Down(MigrationBuilder migrationBuilder)
|
|
||||||
{
|
|
||||||
migrationBuilder.DropTable(
|
|
||||||
name: "Orders");
|
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
|
||||||
name: "PizzaComponents");
|
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
|
||||||
name: "Components");
|
|
||||||
|
|
||||||
migrationBuilder.DropTable(
|
|
||||||
name: "Pizzas");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,171 +0,0 @@
|
|||||||
// <auto-generated />
|
|
||||||
using System;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
|
||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
|
||||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|
||||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
|
||||||
using PizzeriaDatabaseImplement;
|
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
namespace PizzeriaDatabaseImplement.Migrations
|
|
||||||
{
|
|
||||||
[DbContext(typeof(PizzeriaDatabase))]
|
|
||||||
[Migration("20230228065928_Change constraint")]
|
|
||||||
partial class Changeconstraint
|
|
||||||
{
|
|
||||||
/// <inheritdoc />
|
|
||||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
|
||||||
{
|
|
||||||
#pragma warning disable 612, 618
|
|
||||||
modelBuilder
|
|
||||||
.HasAnnotation("ProductVersion", "7.0.3")
|
|
||||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
|
||||||
|
|
||||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
|
||||||
|
|
||||||
modelBuilder.Entity("PizzeriaDatabaseImplement.models.Component", b =>
|
|
||||||
{
|
|
||||||
b.Property<int>("Id")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
|
||||||
|
|
||||||
b.Property<string>("ComponentName")
|
|
||||||
.IsRequired()
|
|
||||||
.HasColumnType("text");
|
|
||||||
|
|
||||||
b.Property<double>("Cost")
|
|
||||||
.HasColumnType("double precision");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.ToTable("Components");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("PizzeriaDatabaseImplement.models.Order", b =>
|
|
||||||
{
|
|
||||||
b.Property<int>("Id")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
|
||||||
|
|
||||||
b.Property<int>("Count")
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
b.Property<DateTime>("DateCreate")
|
|
||||||
.HasColumnType("timestamp with time zone");
|
|
||||||
|
|
||||||
b.Property<DateTime?>("DateImplement")
|
|
||||||
.HasColumnType("timestamp with time zone");
|
|
||||||
|
|
||||||
b.Property<int>("PizzaId")
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
b.Property<int>("Status")
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
b.Property<double>("Sum")
|
|
||||||
.HasColumnType("double precision");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.HasIndex("PizzaId");
|
|
||||||
|
|
||||||
b.ToTable("Orders");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("PizzeriaDatabaseImplement.models.Pizza", b =>
|
|
||||||
{
|
|
||||||
b.Property<int>("Id")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
|
||||||
|
|
||||||
b.Property<string>("PizzaName")
|
|
||||||
.IsRequired()
|
|
||||||
.HasColumnType("text");
|
|
||||||
|
|
||||||
b.Property<double>("Price")
|
|
||||||
.HasColumnType("double precision");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.ToTable("Pizzas");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("PizzeriaDatabaseImplement.models.PizzaComponent", b =>
|
|
||||||
{
|
|
||||||
b.Property<int>("Id")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
|
||||||
|
|
||||||
b.Property<int>("ComponentId")
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
b.Property<int>("Count")
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
b.Property<int>("PizzaId")
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.HasIndex("ComponentId");
|
|
||||||
|
|
||||||
b.HasIndex("PizzaId");
|
|
||||||
|
|
||||||
b.ToTable("PizzaComponents");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("PizzeriaDatabaseImplement.models.Order", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("PizzeriaDatabaseImplement.models.Pizza", "Pizza")
|
|
||||||
.WithMany("Orders")
|
|
||||||
.HasForeignKey("PizzaId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.Navigation("Pizza");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("PizzeriaDatabaseImplement.models.PizzaComponent", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("PizzeriaDatabaseImplement.models.Component", "Component")
|
|
||||||
.WithMany("PizzaComponents")
|
|
||||||
.HasForeignKey("ComponentId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.HasOne("PizzeriaDatabaseImplement.models.Pizza", "Pizza")
|
|
||||||
.WithMany("Components")
|
|
||||||
.HasForeignKey("PizzaId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.Navigation("Component");
|
|
||||||
|
|
||||||
b.Navigation("Pizza");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("PizzeriaDatabaseImplement.models.Component", b =>
|
|
||||||
{
|
|
||||||
b.Navigation("PizzaComponents");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("PizzeriaDatabaseImplement.models.Pizza", b =>
|
|
||||||
{
|
|
||||||
b.Navigation("Components");
|
|
||||||
|
|
||||||
b.Navigation("Orders");
|
|
||||||
});
|
|
||||||
#pragma warning restore 612, 618
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,37 +0,0 @@
|
|||||||
using System;
|
|
||||||
using Microsoft.EntityFrameworkCore.Migrations;
|
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
namespace PizzeriaDatabaseImplement.Migrations
|
|
||||||
{
|
|
||||||
/// <inheritdoc />
|
|
||||||
public partial class Changeconstraint : Migration
|
|
||||||
{
|
|
||||||
/// <inheritdoc />
|
|
||||||
protected override void Up(MigrationBuilder migrationBuilder)
|
|
||||||
{
|
|
||||||
migrationBuilder.AlterColumn<DateTime>(
|
|
||||||
name: "DateImplement",
|
|
||||||
table: "Orders",
|
|
||||||
type: "timestamp with time zone",
|
|
||||||
nullable: true,
|
|
||||||
oldClrType: typeof(DateTime),
|
|
||||||
oldType: "timestamp with time zone");
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
protected override void Down(MigrationBuilder migrationBuilder)
|
|
||||||
{
|
|
||||||
migrationBuilder.AlterColumn<DateTime>(
|
|
||||||
name: "DateImplement",
|
|
||||||
table: "Orders",
|
|
||||||
type: "timestamp with time zone",
|
|
||||||
nullable: false,
|
|
||||||
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified),
|
|
||||||
oldClrType: typeof(DateTime),
|
|
||||||
oldType: "timestamp with time zone",
|
|
||||||
oldNullable: true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,168 +0,0 @@
|
|||||||
// <auto-generated />
|
|
||||||
using System;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
|
||||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
|
||||||
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
|
||||||
using PizzeriaDatabaseImplement;
|
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
namespace PizzeriaDatabaseImplement.Migrations
|
|
||||||
{
|
|
||||||
[DbContext(typeof(PizzeriaDatabase))]
|
|
||||||
partial class PizzeriaDatabaseModelSnapshot : ModelSnapshot
|
|
||||||
{
|
|
||||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
|
||||||
{
|
|
||||||
#pragma warning disable 612, 618
|
|
||||||
modelBuilder
|
|
||||||
.HasAnnotation("ProductVersion", "7.0.3")
|
|
||||||
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
|
||||||
|
|
||||||
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
|
||||||
|
|
||||||
modelBuilder.Entity("PizzeriaDatabaseImplement.models.Component", b =>
|
|
||||||
{
|
|
||||||
b.Property<int>("Id")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
|
||||||
|
|
||||||
b.Property<string>("ComponentName")
|
|
||||||
.IsRequired()
|
|
||||||
.HasColumnType("text");
|
|
||||||
|
|
||||||
b.Property<double>("Cost")
|
|
||||||
.HasColumnType("double precision");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.ToTable("Components");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("PizzeriaDatabaseImplement.models.Order", b =>
|
|
||||||
{
|
|
||||||
b.Property<int>("Id")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
|
||||||
|
|
||||||
b.Property<int>("Count")
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
b.Property<DateTime>("DateCreate")
|
|
||||||
.HasColumnType("timestamp with time zone");
|
|
||||||
|
|
||||||
b.Property<DateTime?>("DateImplement")
|
|
||||||
.HasColumnType("timestamp with time zone");
|
|
||||||
|
|
||||||
b.Property<int>("PizzaId")
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
b.Property<int>("Status")
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
b.Property<double>("Sum")
|
|
||||||
.HasColumnType("double precision");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.HasIndex("PizzaId");
|
|
||||||
|
|
||||||
b.ToTable("Orders");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("PizzeriaDatabaseImplement.models.Pizza", b =>
|
|
||||||
{
|
|
||||||
b.Property<int>("Id")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
|
||||||
|
|
||||||
b.Property<string>("PizzaName")
|
|
||||||
.IsRequired()
|
|
||||||
.HasColumnType("text");
|
|
||||||
|
|
||||||
b.Property<double>("Price")
|
|
||||||
.HasColumnType("double precision");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.ToTable("Pizzas");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("PizzeriaDatabaseImplement.models.PizzaComponent", b =>
|
|
||||||
{
|
|
||||||
b.Property<int>("Id")
|
|
||||||
.ValueGeneratedOnAdd()
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
|
||||||
|
|
||||||
b.Property<int>("ComponentId")
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
b.Property<int>("Count")
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
b.Property<int>("PizzaId")
|
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
b.HasKey("Id");
|
|
||||||
|
|
||||||
b.HasIndex("ComponentId");
|
|
||||||
|
|
||||||
b.HasIndex("PizzaId");
|
|
||||||
|
|
||||||
b.ToTable("PizzaComponents");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("PizzeriaDatabaseImplement.models.Order", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("PizzeriaDatabaseImplement.models.Pizza", "Pizza")
|
|
||||||
.WithMany("Orders")
|
|
||||||
.HasForeignKey("PizzaId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.Navigation("Pizza");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("PizzeriaDatabaseImplement.models.PizzaComponent", b =>
|
|
||||||
{
|
|
||||||
b.HasOne("PizzeriaDatabaseImplement.models.Component", "Component")
|
|
||||||
.WithMany("PizzaComponents")
|
|
||||||
.HasForeignKey("ComponentId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.HasOne("PizzeriaDatabaseImplement.models.Pizza", "Pizza")
|
|
||||||
.WithMany("Components")
|
|
||||||
.HasForeignKey("PizzaId")
|
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
|
||||||
.IsRequired();
|
|
||||||
|
|
||||||
b.Navigation("Component");
|
|
||||||
|
|
||||||
b.Navigation("Pizza");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("PizzeriaDatabaseImplement.models.Component", b =>
|
|
||||||
{
|
|
||||||
b.Navigation("PizzaComponents");
|
|
||||||
});
|
|
||||||
|
|
||||||
modelBuilder.Entity("PizzeriaDatabaseImplement.models.Pizza", b =>
|
|
||||||
{
|
|
||||||
b.Navigation("Components");
|
|
||||||
|
|
||||||
b.Navigation("Orders");
|
|
||||||
});
|
|
||||||
#pragma warning restore 612, 618
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,23 +0,0 @@
|
|||||||
using PizzeriaDatabaseImplement.models;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
|
|
||||||
namespace PizzeriaDatabaseImplement
|
|
||||||
{
|
|
||||||
public class PizzeriaDatabase : DbContext
|
|
||||||
{
|
|
||||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
|
||||||
{
|
|
||||||
if (optionsBuilder.IsConfigured == false)
|
|
||||||
{
|
|
||||||
optionsBuilder.UseNpgsql(@"Host=localhost;Port=5432;Database=PizzeriaDatabase;Username=postgres;Password=postgres");
|
|
||||||
}
|
|
||||||
base.OnConfiguring(optionsBuilder);
|
|
||||||
}
|
|
||||||
public virtual DbSet<Component> Components { set; get; }
|
|
||||||
public virtual DbSet<Pizza> Pizzas { set; get; }
|
|
||||||
public virtual DbSet<Shop> Shops { set; get; }
|
|
||||||
public virtual DbSet<PizzaComponent> PizzaComponents { set; get; }
|
|
||||||
public virtual DbSet<ShopPizza> ShopPizzas { set; get; }
|
|
||||||
public virtual DbSet<Order> Orders { set; get; }
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,24 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.3" />
|
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.3" />
|
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.3">
|
|
||||||
<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="..\PizzeriaContracts\PizzeriaContracts.csproj" />
|
|
||||||
<ProjectReference Include="..\PizzeriaDataModels\PizzeriaDataModels.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
@ -1,57 +0,0 @@
|
|||||||
using PizzeriaContracts.BindingModels;
|
|
||||||
using PizzeriaContracts.ViewModels;
|
|
||||||
using PizzeriaDataModels;
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
|
||||||
|
|
||||||
namespace PizzeriaDatabaseImplement.models
|
|
||||||
{
|
|
||||||
public class Component : IComponentModel
|
|
||||||
{
|
|
||||||
public int Id { get; private set; }
|
|
||||||
[Required]
|
|
||||||
public string ComponentName { get; private set; } = string.Empty;
|
|
||||||
[Required]
|
|
||||||
public double Cost { get; set; }
|
|
||||||
[ForeignKey("ComponentId")]
|
|
||||||
public virtual List<PizzaComponent> PizzaComponents { get; set; } =
|
|
||||||
new();
|
|
||||||
public static Component? Create(ComponentBindingModel model)
|
|
||||||
{
|
|
||||||
if (model == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return new Component()
|
|
||||||
{
|
|
||||||
Id = model.Id,
|
|
||||||
ComponentName = model.ComponentName,
|
|
||||||
Cost = model.Cost
|
|
||||||
};
|
|
||||||
}
|
|
||||||
public static Component Create(ComponentViewModel model)
|
|
||||||
{
|
|
||||||
return new Component
|
|
||||||
{
|
|
||||||
Id = model.Id,
|
|
||||||
ComponentName = model.ComponentName,
|
|
||||||
Cost = model.Cost
|
|
||||||
};
|
|
||||||
}
|
|
||||||
public void Update(ComponentBindingModel model)
|
|
||||||
{
|
|
||||||
if (model == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ComponentName = model.ComponentName;
|
|
||||||
Cost = model.Cost;
|
|
||||||
}
|
|
||||||
public ComponentViewModel GetViewModel => new()
|
|
||||||
{
|
|
||||||
Id = Id,
|
|
||||||
ComponentName = ComponentName,
|
|
||||||
Cost = Cost
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,72 +0,0 @@
|
|||||||
using PizzeriaContracts.BindingModels;
|
|
||||||
using PizzeriaContracts.ViewModels;
|
|
||||||
using PizzeriaDataModels;
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
|
|
||||||
namespace PizzeriaDatabaseImplement.models
|
|
||||||
{
|
|
||||||
public class Order : IOrderModel
|
|
||||||
{
|
|
||||||
[Required]
|
|
||||||
public int PizzaId { get; private set; }
|
|
||||||
|
|
||||||
[Required]
|
|
||||||
public int Count { get; private set; }
|
|
||||||
|
|
||||||
[Required]
|
|
||||||
public double Sum { get; private set; }
|
|
||||||
|
|
||||||
[Required]
|
|
||||||
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
|
|
||||||
|
|
||||||
[Required]
|
|
||||||
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
|
||||||
|
|
||||||
public DateTime? DateImplement { get; private set; }
|
|
||||||
|
|
||||||
public virtual Pizza Pizza { get; set; } = new();
|
|
||||||
|
|
||||||
public int Id { get; private set; }
|
|
||||||
|
|
||||||
public static Order? Create(PizzeriaDatabase context, OrderBindingModel? model)
|
|
||||||
{
|
|
||||||
if (model == null)
|
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return new Order()
|
|
||||||
{
|
|
||||||
Id = model.Id,
|
|
||||||
PizzaId = model.PizzaId,
|
|
||||||
Pizza = context.Pizzas.FirstOrDefault(x => x.Id == model.PizzaId),
|
|
||||||
Count = model.Count,
|
|
||||||
Sum = model.Sum,
|
|
||||||
Status = model.Status,
|
|
||||||
DateCreate = model.DateCreate,
|
|
||||||
DateImplement = model.DateImplement
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Update(OrderBindingModel? model)
|
|
||||||
{
|
|
||||||
if (model == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Status = model.Status;
|
|
||||||
DateImplement = model.DateImplement;
|
|
||||||
}
|
|
||||||
|
|
||||||
public OrderViewModel GetViewModel => new()
|
|
||||||
{
|
|
||||||
Id = Id,
|
|
||||||
PizzaId = PizzaId,
|
|
||||||
PizzaName = Pizza.PizzaName,
|
|
||||||
Count = Count,
|
|
||||||
Sum = Sum,
|
|
||||||
Status = Status,
|
|
||||||
DateCreate = DateCreate,
|
|
||||||
DateImplement = DateImplement
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,97 +0,0 @@
|
|||||||
using PizzeriaContracts.BindingModels;
|
|
||||||
using PizzeriaContracts.ViewModels;
|
|
||||||
using PizzeriaDataModels;
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
|
||||||
|
|
||||||
|
|
||||||
namespace PizzeriaDatabaseImplement.models
|
|
||||||
{
|
|
||||||
public class Pizza : IPizzaModel
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
[Required]
|
|
||||||
public string PizzaName { get; set; } = string.Empty;
|
|
||||||
[Required]
|
|
||||||
public double Price { get; set; }
|
|
||||||
private Dictionary<int, (IComponentModel, int)>? _pizzaComponents =
|
|
||||||
null;
|
|
||||||
[NotMapped]
|
|
||||||
public Dictionary<int, (IComponentModel, int)> PizzaComponents
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (_pizzaComponents == null)
|
|
||||||
{
|
|
||||||
_pizzaComponents = Components
|
|
||||||
.ToDictionary(recPC => recPC.ComponentId, recPC =>
|
|
||||||
(recPC.Component as IComponentModel, recPC.Count));
|
|
||||||
}
|
|
||||||
return _pizzaComponents;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
[ForeignKey("PizzaId")]
|
|
||||||
public virtual List<PizzaComponent> Components { get; set; } = new();
|
|
||||||
[ForeignKey("PizzaId")]
|
|
||||||
public virtual List<Order> Orders { get; set; } = new();
|
|
||||||
public static Pizza Create(PizzeriaDatabase context, PizzaBindingModel model)
|
|
||||||
{
|
|
||||||
return new Pizza()
|
|
||||||
{
|
|
||||||
Id = model.Id,
|
|
||||||
PizzaName = model.PizzaName,
|
|
||||||
Price = model.Price,
|
|
||||||
Components = model.PizzaComponents.Select(x => new
|
|
||||||
PizzaComponent
|
|
||||||
{
|
|
||||||
Component = context.Components.First(y => y.Id == x.Key),
|
|
||||||
Count = x.Value.Item2
|
|
||||||
}).ToList()
|
|
||||||
};
|
|
||||||
}
|
|
||||||
public void Update(PizzaBindingModel model)
|
|
||||||
{
|
|
||||||
PizzaName = model.PizzaName;
|
|
||||||
Price = model.Price;
|
|
||||||
}
|
|
||||||
public PizzaViewModel GetViewModel => new()
|
|
||||||
{
|
|
||||||
Id = Id,
|
|
||||||
PizzaName = PizzaName,
|
|
||||||
Price = Price,
|
|
||||||
PizzaComponents = PizzaComponents
|
|
||||||
};
|
|
||||||
public void UpdateComponents(PizzeriaDatabase context,
|
|
||||||
PizzaBindingModel model)
|
|
||||||
{
|
|
||||||
var pizzaComponents = context.PizzaComponents.Where(rec =>
|
|
||||||
rec.PizzaId == model.Id).ToList();
|
|
||||||
if (pizzaComponents != null && pizzaComponents.Count > 0)
|
|
||||||
{ // удалили те, которых нет в модели
|
|
||||||
context.PizzaComponents.RemoveRange(pizzaComponents.Where(rec
|
|
||||||
=> !model.PizzaComponents.ContainsKey(rec.ComponentId)));
|
|
||||||
context.SaveChanges();
|
|
||||||
// обновили количество у существующих записей
|
|
||||||
foreach (var updateComponent in pizzaComponents)
|
|
||||||
{
|
|
||||||
updateComponent.Count =
|
|
||||||
model.PizzaComponents[updateComponent.ComponentId].Item2;
|
|
||||||
model.PizzaComponents.Remove(updateComponent.ComponentId);
|
|
||||||
}
|
|
||||||
context.SaveChanges();
|
|
||||||
}
|
|
||||||
var pizza = context.Pizzas.First(x => x.Id == Id);
|
|
||||||
foreach (var pc in model.PizzaComponents)
|
|
||||||
{
|
|
||||||
context.PizzaComponents.Add(new PizzaComponent
|
|
||||||
{
|
|
||||||
Pizza = pizza,
|
|
||||||
Component = context.Components.First(x => x.Id == pc.Key),
|
|
||||||
Count = pc.Value.Item2
|
|
||||||
});
|
|
||||||
context.SaveChanges();
|
|
||||||
}
|
|
||||||
_pizzaComponents = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
|
|
||||||
namespace PizzeriaDatabaseImplement.models
|
|
||||||
{
|
|
||||||
public class PizzaComponent
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
[Required]
|
|
||||||
public int PizzaId { get; set; }
|
|
||||||
[Required]
|
|
||||||
public int ComponentId { get; set; }
|
|
||||||
[Required]
|
|
||||||
public int Count { get; set; }
|
|
||||||
public virtual Component Component { get; set; } = new();
|
|
||||||
public virtual Pizza Pizza { get; set; } = new();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,105 +0,0 @@
|
|||||||
using PizzeriaContracts.BindingModels;
|
|
||||||
using PizzeriaContracts.ViewModels;
|
|
||||||
using PizzeriaDataModels;
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using System.ComponentModel.DataAnnotations.Schema;
|
|
||||||
using System.Diagnostics;
|
|
||||||
|
|
||||||
namespace PizzeriaDatabaseImplement.models
|
|
||||||
{
|
|
||||||
public class Shop : IShopModel
|
|
||||||
{
|
|
||||||
[Required]
|
|
||||||
public int Id { get; set; }
|
|
||||||
[Required]
|
|
||||||
public string ShopName { get; set; } = string.Empty;
|
|
||||||
[Required]
|
|
||||||
public string Addres { get; set; } = string.Empty;
|
|
||||||
[Required]
|
|
||||||
public DateTime OpenTime { get; set; }
|
|
||||||
[Required]
|
|
||||||
public int Capacity { get; set; }
|
|
||||||
private Dictionary<int, (IPizzaModel, int)>? _shopPizzas = null;
|
|
||||||
[NotMapped]
|
|
||||||
public Dictionary<int, (IPizzaModel, int)> ShopPizzas
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (_shopPizzas == null)
|
|
||||||
{
|
|
||||||
_shopPizzas = Pizzas.ToDictionary(x => x.PizzaId, x => (x.Pizza as IPizzaModel, x.Count));
|
|
||||||
}
|
|
||||||
return _shopPizzas;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
[ForeignKey("ShopId")]
|
|
||||||
public virtual List<ShopPizza> Pizzas { get; set; } = new();
|
|
||||||
public static Shop Create(PizzeriaDatabase context, ShopBindingModel model)
|
|
||||||
{
|
|
||||||
return new Shop()
|
|
||||||
{
|
|
||||||
Id = model.Id,
|
|
||||||
ShopName = model.ShopName,
|
|
||||||
Addres = model.Addres,
|
|
||||||
OpenTime = model.OpenTime,
|
|
||||||
Capacity = model.Capacity,
|
|
||||||
Pizzas = model.ShopPizzas.Select(x => new
|
|
||||||
ShopPizza
|
|
||||||
{
|
|
||||||
Pizza = context.Pizzas.First(y => y.Id == x.Key),
|
|
||||||
Count = x.Value.Item2
|
|
||||||
}).ToList()
|
|
||||||
};
|
|
||||||
}
|
|
||||||
public void Update(ShopBindingModel model)
|
|
||||||
{
|
|
||||||
if (model == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ShopName = model.ShopName;
|
|
||||||
Addres = model.Addres;
|
|
||||||
OpenTime = model.OpenTime;
|
|
||||||
Capacity = model.Capacity;
|
|
||||||
}
|
|
||||||
public ShopViewModel GetViewModel => new()
|
|
||||||
{
|
|
||||||
Id = Id,
|
|
||||||
ShopName = ShopName,
|
|
||||||
Addres = Addres,
|
|
||||||
OpenTime = OpenTime,
|
|
||||||
Capacity = Capacity,
|
|
||||||
ShopPizzas = ShopPizzas
|
|
||||||
};
|
|
||||||
public void UpdatePizzas(PizzeriaDatabase context, ShopBindingModel model)
|
|
||||||
{
|
|
||||||
var shopPizzas = context.ShopPizzas.Where(rec => rec.ShopId == model.Id).ToList();
|
|
||||||
if (shopPizzas != null && shopPizzas.Count > 0)
|
|
||||||
{ // удалили те, которых нет в модели
|
|
||||||
context.ShopPizzas.RemoveRange(shopPizzas.Where(rec
|
|
||||||
=> !model.ShopPizzas.ContainsKey(rec.PizzaId)));
|
|
||||||
context.SaveChanges();
|
|
||||||
// обновили количество у существующих записей
|
|
||||||
foreach (var updatePizza in shopPizzas)
|
|
||||||
{
|
|
||||||
updatePizza.Count =
|
|
||||||
model.ShopPizzas[updatePizza.PizzaId].Item2;
|
|
||||||
model.ShopPizzas.Remove(updatePizza.PizzaId);
|
|
||||||
}
|
|
||||||
context.SaveChanges();
|
|
||||||
}
|
|
||||||
var shop = context.Shops.First(x => x.Id == Id);
|
|
||||||
foreach (var pc in model.ShopPizzas)
|
|
||||||
{
|
|
||||||
context.ShopPizzas.Add(new ShopPizza
|
|
||||||
{
|
|
||||||
Shop = shop,
|
|
||||||
Pizza = context.Pizzas.First(x => x.Id == pc.Key),
|
|
||||||
Count = pc.Value.Item2
|
|
||||||
});
|
|
||||||
context.SaveChanges();
|
|
||||||
}
|
|
||||||
_shopPizzas = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,17 +0,0 @@
|
|||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
|
|
||||||
namespace PizzeriaDatabaseImplement.models
|
|
||||||
{
|
|
||||||
public class ShopPizza
|
|
||||||
{
|
|
||||||
public int Id { get; set; }
|
|
||||||
[Required]
|
|
||||||
public int PizzaId { get; set; }
|
|
||||||
[Required]
|
|
||||||
public int ShopId { get; set; }
|
|
||||||
[Required]
|
|
||||||
public int Count { get; set; }
|
|
||||||
public virtual Shop Shop { get; set; } = new();
|
|
||||||
public virtual Pizza Pizza { get; set; } = new();
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user