Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
388154766a | ||
|
|
32bb2102ab | ||
|
|
50d6fb49de | ||
|
|
7c5c501159 | ||
|
|
827b463ef6 | ||
|
|
ffd4068d80 | ||
|
|
c9a37b6da2 | ||
|
|
2d616bea4a |
@@ -11,7 +11,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PizzeriaDataModels", "Pizze
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PizzeriaListImplement", "PizzeriaListImplement\PizzeriaListImplement.csproj", "{E219B355-7A12-4E5C-A09A-035A60B11A9D}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PizzeriaListImplement", "PizzeriaListImplement\PizzeriaListImplement.csproj", "{E219B355-7A12-4E5C-A09A-035A60B11A9D}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PizzeriaView", "PizzeriaView\PizzeriaView.csproj", "{BE1F3CE5-00CC-4816-BB43-8F9BC6FA7DC1}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PizzeriaView", "PizzeriaView\PizzeriaView.csproj", "{BE1F3CE5-00CC-4816-BB43-8F9BC6FA7DC1}"
|
||||||
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PizzeriaFileImplement", "PizzeriaFileImplement\PizzeriaFileImplement.csproj", "{5DCE4FAE-CF2A-48A2-863A-EDED5B420203}"
|
||||||
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PizzeriaDatabaseImplement", "PizzeriaDatabaseImplement\PizzeriaDatabaseImplement.csproj", "{AA78A273-0E83-4B45-A155-F9CAFD64E895}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
@@ -39,6 +43,14 @@ Global
|
|||||||
{BE1F3CE5-00CC-4816-BB43-8F9BC6FA7DC1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{BE1F3CE5-00CC-4816-BB43-8F9BC6FA7DC1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{BE1F3CE5-00CC-4816-BB43-8F9BC6FA7DC1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{BE1F3CE5-00CC-4816-BB43-8F9BC6FA7DC1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{BE1F3CE5-00CC-4816-BB43-8F9BC6FA7DC1}.Release|Any CPU.Build.0 = Release|Any CPU
|
{BE1F3CE5-00CC-4816-BB43-8F9BC6FA7DC1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{5DCE4FAE-CF2A-48A2-863A-EDED5B420203}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{5DCE4FAE-CF2A-48A2-863A-EDED5B420203}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{5DCE4FAE-CF2A-48A2-863A-EDED5B420203}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{5DCE4FAE-CF2A-48A2-863A-EDED5B420203}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{AA78A273-0E83-4B45-A155-F9CAFD64E895}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{AA78A273-0E83-4B45-A155-F9CAFD64E895}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{AA78A273-0E83-4B45-A155-F9CAFD64E895}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{AA78A273-0E83-4B45-A155-F9CAFD64E895}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using PizzeriaContracts.SearchModels;
|
|||||||
using PizzeriaContracts.StoragesContracts;
|
using PizzeriaContracts.StoragesContracts;
|
||||||
using PizzeriaContracts.ViewModels;
|
using PizzeriaContracts.ViewModels;
|
||||||
using PizzeriaDataModels.Enums;
|
using PizzeriaDataModels.Enums;
|
||||||
|
using PizzeriaDataModels.Models;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -17,15 +18,25 @@ namespace PizzeriaBusinessLogic.BusinessLogics
|
|||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IOrderStorage _orderStorage;
|
private readonly IOrderStorage _orderStorage;
|
||||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
|
private readonly IShopStorage _shopStorage;
|
||||||
|
private readonly IShopLogic _shopLogic;
|
||||||
|
private readonly IPizzaStorage _pizzaStorage;
|
||||||
|
|
||||||
|
public OrderLogic(IOrderStorage orderStorage, IShopStorage shopStorage, IShopLogic shopLogic, IPizzaStorage pizzaStorage, ILogger<OrderLogic> logger)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_orderStorage = orderStorage;
|
_orderStorage = orderStorage;
|
||||||
|
_shopStorage = shopStorage;
|
||||||
|
_logger = logger;
|
||||||
|
_shopLogic = shopLogic;
|
||||||
|
_pizzaStorage = pizzaStorage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("ReadList. OrderId:{Id}", model?.Id);
|
_logger.LogInformation("ReadList. Id:{ Id}", model?.Id);
|
||||||
var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
|
var list = model == null ? _orderStorage.GetFullList() :
|
||||||
|
_orderStorage.GetFilteredList(model);
|
||||||
if (list == null)
|
if (list == null)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("ReadList return null list");
|
_logger.LogWarning("ReadList return null list");
|
||||||
@@ -34,11 +45,11 @@ namespace PizzeriaBusinessLogic.BusinessLogics
|
|||||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool CreateOrder(OrderBindingModel model)
|
public bool CreateOrder(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
CheckModel(model);
|
CheckModel(model);
|
||||||
if (model.Status != OrderStatus.Неизвестен)
|
if (model.Status != OrderStatus.Неизвестен) return false;
|
||||||
return false;
|
|
||||||
model.Status = OrderStatus.Принят;
|
model.Status = OrderStatus.Принят;
|
||||||
if (_orderStorage.Insert(model) == null)
|
if (_orderStorage.Insert(model) == null)
|
||||||
{
|
{
|
||||||
@@ -47,6 +58,98 @@ namespace PizzeriaBusinessLogic.BusinessLogics
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
private bool CheckSupply(IPizzaModel Pizza, int count)
|
||||||
|
{
|
||||||
|
if (count <= 0)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Check then supply operation error. Pizza count < 0.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int sumCapacity = 0;
|
||||||
|
int sumCount = 0;
|
||||||
|
sumCapacity = _shopStorage.GetFullList().Select(x => x.PizzaMaxCount).Sum();
|
||||||
|
sumCount = _shopStorage.GetFullList().Select(x => x.ShopPizzas.Select(y => y.Value.Item2).Sum()).Sum();
|
||||||
|
int freeSpace = sumCapacity - sumCount;
|
||||||
|
|
||||||
|
if (freeSpace - count < 0)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Check then supply operation error. There's no place for new Pizza in shops.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var shop in _shopStorage.GetFullList())
|
||||||
|
{
|
||||||
|
freeSpace = shop.PizzaMaxCount;
|
||||||
|
foreach (var doc in shop.ShopPizzas)
|
||||||
|
{
|
||||||
|
freeSpace -= doc.Value.Item2;
|
||||||
|
}
|
||||||
|
if (freeSpace == 0)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (freeSpace - count >= 0)
|
||||||
|
{
|
||||||
|
if (_shopLogic.MakeSupply(new() { Id = shop.Id }, Pizza, count))
|
||||||
|
count = 0;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Supply error");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (freeSpace - count < 0)
|
||||||
|
{
|
||||||
|
if (_shopLogic.MakeSupply(new() { Id = shop.Id }, Pizza, freeSpace))
|
||||||
|
count -= freeSpace;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Supply error");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (count <= 0)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool ChangeStatus(OrderBindingModel model, OrderStatus status)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
var element = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id });
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Read operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (element.Status != status - 1)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Status change operation failed");
|
||||||
|
throw new InvalidOperationException("Текущий статус заказа не может быть переведен в выбранный");
|
||||||
|
}
|
||||||
|
if (element.Status == OrderStatus.Готов)
|
||||||
|
{
|
||||||
|
var computer = _pizzaStorage.GetElement(new PizzaSearchModel() { Id = model.PizzaId });
|
||||||
|
if (computer == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Status update to " + status.ToString() + " operation failed. Document not found.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (CheckSupply(computer, model.Count) == false)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Status update to " + status.ToString() + " operation failed. Shop supply error.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
model.Status = status;
|
||||||
|
if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now;
|
||||||
|
_orderStorage.Update(model);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public bool TakeOrderInWork(OrderBindingModel model)
|
public bool TakeOrderInWork(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
@@ -73,53 +176,15 @@ namespace PizzeriaBusinessLogic.BusinessLogics
|
|||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (model.Count <= 0)
|
|
||||||
{
|
|
||||||
throw new ArgumentException("Колличество пиццы в заказе не может быть меньше 1", nameof(model.Count));
|
|
||||||
}
|
|
||||||
if (model.Sum <= 0)
|
if (model.Sum <= 0)
|
||||||
{
|
{
|
||||||
throw new ArgumentException("Стоимость заказа на может быть меньше 1", nameof(model.Sum));
|
throw new ArgumentNullException("Цена заказа должна быть больше 0", nameof(model.Sum));
|
||||||
}
|
}
|
||||||
if (model.DateImplement.HasValue && model.DateImplement < model.DateCreate)
|
if (model.Count <= 0)
|
||||||
{
|
{
|
||||||
throw new ArithmeticException($"Дата выдачи заказа {model.DateImplement} не может быть раньше даты его создания {model.DateCreate}");
|
throw new ArgumentNullException("Количество элементов в заказе должно быть больше 0", nameof(model.Count));
|
||||||
}
|
}
|
||||||
_logger.LogInformation("Pizza. PizzaId:{PizzaId}.Count:{Count}.Sum:{Sum}Id:{Id}",
|
_logger.LogInformation("Order. Sum:{ Cost}. Id: { Id}", model.Sum, model.Id);
|
||||||
model.PizzaId, model.Count, model.Sum, model.Id);
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool ChangeStatus(OrderBindingModel model, OrderStatus requiredStatus)
|
|
||||||
{
|
|
||||||
CheckModel(model, false);
|
|
||||||
var element = _orderStorage.GetElement(new OrderSearchModel()
|
|
||||||
{
|
|
||||||
Id = model.Id
|
|
||||||
});
|
|
||||||
if (element == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(element));
|
|
||||||
}
|
|
||||||
model.DateCreate = element.DateCreate;
|
|
||||||
model.PizzaId = element.PizzaId;
|
|
||||||
model.DateImplement = element.DateImplement;
|
|
||||||
model.Status = element.Status;
|
|
||||||
model.Count = element.Count;
|
|
||||||
model.Sum = element.Sum;
|
|
||||||
if (requiredStatus - model.Status == 1)
|
|
||||||
{
|
|
||||||
model.Status = requiredStatus;
|
|
||||||
if (model.Status == OrderStatus.Готов)
|
|
||||||
model.DateImplement = DateTime.Now;
|
|
||||||
if (_orderStorage.Update(model) == null)
|
|
||||||
{
|
|
||||||
_logger.LogWarning("Update operation failed");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
_logger.LogWarning("Changing status operation faled: Current-{Status}:required-{requiredStatus}.", model.Status, requiredStatus);
|
|
||||||
throw new ArgumentException($"Невозможно присвоить статус {requiredStatus} заказу с текущим статусом {model.Status}");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using PizzeriaContracts.BusinessLogicsContracts;
|
|||||||
using PizzeriaContracts.SearchModels;
|
using PizzeriaContracts.SearchModels;
|
||||||
using PizzeriaContracts.StoragesContracts;
|
using PizzeriaContracts.StoragesContracts;
|
||||||
using PizzeriaContracts.ViewModels;
|
using PizzeriaContracts.ViewModels;
|
||||||
|
using PizzeriaDataModels.Models;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -89,41 +90,47 @@ namespace PizzeriaBusinessLogic.BusinessLogics
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool MakeSupply(SupplyBindingModel model)
|
|
||||||
|
public bool MakeSupply(ShopSearchModel model, IPizzaModel pizza, int count)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (model == null)
|
if (model == null)
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(model));
|
throw new ArgumentNullException(nameof(model));
|
||||||
}
|
if (pizza == null)
|
||||||
if (model.Count <= 0)
|
throw new ArgumentNullException(nameof(pizza));
|
||||||
|
if (count <= 0)
|
||||||
|
throw new ArgumentNullException("Количество должно быть положительным числом");
|
||||||
|
|
||||||
|
ShopViewModel curModel = _shopStorage.GetElement(model);
|
||||||
|
if (curModel == null)
|
||||||
|
throw new ArgumentNullException(nameof(curModel));
|
||||||
|
var countItems = curModel.ShopPizzas.Select(x => x.Value.Item2).Sum();
|
||||||
|
if (curModel.PizzaMaxCount - countItems >= count)
|
||||||
{
|
{
|
||||||
throw new ArgumentException("Количество изделий должно быть больше 0");
|
if (curModel.ShopPizzas.TryGetValue(pizza.Id, out var sameDocument))
|
||||||
}
|
|
||||||
var shop = _shopStorage.GetElement(new ShopSearchModel
|
|
||||||
{
|
{
|
||||||
Id = model.ShopId
|
curModel.ShopPizzas[pizza.Id] = (pizza, sameDocument.Item2 + count);
|
||||||
});
|
_logger.LogInformation("Same pizza found by supply. Added {0} of {1} in {2} shop", count, pizza.PizzaName, curModel.ShopName);
|
||||||
if (shop == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentException("Магазина не существует");
|
|
||||||
}
|
|
||||||
if (shop.ShopPizzas.ContainsKey(model.PizzaId))
|
|
||||||
{
|
|
||||||
var oldValue = shop.ShopPizzas[model.PizzaId];
|
|
||||||
oldValue.Item2 += model.Count;
|
|
||||||
shop.ShopPizzas[model.PizzaId] = oldValue;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var pizza = _pizzaStorage.GetElement(new PizzaSearchModel
|
curModel.ShopPizzas[pizza.Id] = (pizza, count);
|
||||||
{
|
_logger.LogInformation("New pizza added by supply. Added {0} of {1} in {2} shop", count, pizza.PizzaName, curModel.ShopName);
|
||||||
Id = model.PizzaId
|
|
||||||
});
|
|
||||||
if (pizza == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentException($"Поставка: Товар с id:{model.PizzaId} не найден");
|
|
||||||
}
|
}
|
||||||
shop.ShopPizzas.Add(model.PizzaId, (pizza, model.Count));
|
_shopStorage.Update(new()
|
||||||
|
{
|
||||||
|
Id = curModel.Id,
|
||||||
|
ShopName = curModel.ShopName,
|
||||||
|
Adress = curModel.Adress,
|
||||||
|
OpeningDate = curModel.OpeningDate,
|
||||||
|
ShopPizzas = curModel.ShopPizzas,
|
||||||
|
PizzaMaxCount = curModel.PizzaMaxCount
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Required shop is overflowed");
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -140,7 +147,7 @@ namespace PizzeriaBusinessLogic.BusinessLogics
|
|||||||
}
|
}
|
||||||
if (string.IsNullOrEmpty(model.Adress))
|
if (string.IsNullOrEmpty(model.Adress))
|
||||||
{
|
{
|
||||||
throw new ArgumentException("Адрес магазина длжен быть заполнен", nameof(model.Adress));
|
throw new ArgumentException("Адрес магазина должен быть заполнен", nameof(model.Adress));
|
||||||
}
|
}
|
||||||
if (string.IsNullOrEmpty(model.ShopName))
|
if (string.IsNullOrEmpty(model.ShopName))
|
||||||
{
|
{
|
||||||
@@ -156,5 +163,10 @@ namespace PizzeriaBusinessLogic.BusinessLogics
|
|||||||
throw new InvalidOperationException("Магазин с таким названием уже есть");
|
throw new InvalidOperationException("Магазин с таким названием уже есть");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool MakeSell(IPizzaModel pizza, int count)
|
||||||
|
{
|
||||||
|
return _shopStorage.SellPizzas(pizza, count);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,19 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.27" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.27">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.27" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.27">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\PizzeriaContracts\PizzeriaContracts.csproj" />
|
<ProjectReference Include="..\PizzeriaContracts\PizzeriaContracts.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -14,5 +14,6 @@ namespace PizzeriaContracts.BindingModels
|
|||||||
public string Adress { get; set; } = string.Empty;
|
public string Adress { get; set; } = string.Empty;
|
||||||
public DateTime OpeningDate { get; set; } = DateTime.Now;
|
public DateTime OpeningDate { get; set; } = DateTime.Now;
|
||||||
public Dictionary<int, (IPizzaModel, int)> ShopPizzas { get; set; } = new();
|
public Dictionary<int, (IPizzaModel, int)> ShopPizzas { get; set; } = new();
|
||||||
|
public int PizzaMaxCount { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
using PizzeriaContracts.BindingModels;
|
using PizzeriaContracts.BindingModels;
|
||||||
using PizzeriaContracts.SearchModels;
|
using PizzeriaContracts.SearchModels;
|
||||||
using PizzeriaContracts.ViewModels;
|
using PizzeriaContracts.ViewModels;
|
||||||
|
using PizzeriaDataModels.Models;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -16,6 +17,7 @@ namespace PizzeriaContracts.BusinessLogicsContracts
|
|||||||
bool Create(ShopBindingModel model);
|
bool Create(ShopBindingModel model);
|
||||||
bool Update(ShopBindingModel model);
|
bool Update(ShopBindingModel model);
|
||||||
bool Delete(ShopBindingModel model);
|
bool Delete(ShopBindingModel model);
|
||||||
bool MakeSupply(SupplyBindingModel model);
|
bool MakeSupply(ShopSearchModel model, IPizzaModel pizza, int count);
|
||||||
|
bool MakeSell(IPizzaModel pizza, int count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
14
Pizzeria/PizzeriaContracts/SearchModels/SupplySearchModel.cs
Normal file
14
Pizzeria/PizzeriaContracts/SearchModels/SupplySearchModel.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace PizzeriaContracts.SearchModels
|
||||||
|
{
|
||||||
|
public class SupplySearchModel
|
||||||
|
{
|
||||||
|
public int? PizzaId { get; set; }
|
||||||
|
public int? Count { get; set; }
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
using PizzeriaContracts.BindingModels;
|
using PizzeriaContracts.BindingModels;
|
||||||
using PizzeriaContracts.SearchModels;
|
using PizzeriaContracts.SearchModels;
|
||||||
using PizzeriaContracts.ViewModels;
|
using PizzeriaContracts.ViewModels;
|
||||||
|
using PizzeriaDataModels.Models;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -17,5 +18,6 @@ namespace PizzeriaContracts.StoragesContracts
|
|||||||
ShopViewModel? Insert(ShopBindingModel model);
|
ShopViewModel? Insert(ShopBindingModel model);
|
||||||
ShopViewModel? Update(ShopBindingModel model);
|
ShopViewModel? Update(ShopBindingModel model);
|
||||||
ShopViewModel? Delete(ShopBindingModel model);
|
ShopViewModel? Delete(ShopBindingModel model);
|
||||||
|
public bool SellPizzas(IPizzaModel model, int count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -18,5 +18,7 @@ namespace PizzeriaContracts.ViewModels
|
|||||||
[DisplayName("Дата открытия")]
|
[DisplayName("Дата открытия")]
|
||||||
public DateTime OpeningDate { get; set; }
|
public DateTime OpeningDate { get; set; }
|
||||||
public Dictionary<int, (IPizzaModel, int)> ShopPizzas { get; set; } = new();
|
public Dictionary<int, (IPizzaModel, int)> ShopPizzas { get; set; } = new();
|
||||||
|
[DisplayName("Вместимость")]
|
||||||
|
public int PizzaMaxCount { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -14,5 +14,6 @@ namespace PizzeriaDataModels.Models
|
|||||||
string Adress { get; }
|
string Adress { get; }
|
||||||
DateTime OpeningDate { get; }
|
DateTime OpeningDate { get; }
|
||||||
Dictionary<int, (IPizzaModel, int)> ShopPizzas { get; }
|
Dictionary<int, (IPizzaModel, int)> ShopPizzas { get; }
|
||||||
|
public int PizzaMaxCount { get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,79 @@
|
|||||||
|
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)
|
||||||
|
{
|
||||||
|
if (!model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
using var context = new PizzeriaDatabase();
|
||||||
|
return context.Orders.Include(x => x.Pizza).Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||||
|
{
|
||||||
|
if (!model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
using var context = new PizzeriaDatabase();
|
||||||
|
return context.Orders.Include(x => x.Pizza).FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel? Insert(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new PizzeriaDatabase();
|
||||||
|
if (model == null)
|
||||||
|
return null;
|
||||||
|
var newOrder = Order.Create(context, model);
|
||||||
|
if (newOrder == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
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 order = context.Orders.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
|
if (order != null)
|
||||||
|
{
|
||||||
|
context.Orders.Remove(order);
|
||||||
|
context.SaveChanges();
|
||||||
|
return order.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
131
Pizzeria/PizzeriaDatabaseImplement/Implements/ShopStorage.cs
Normal file
131
Pizzeria/PizzeriaDatabaseImplement/Implements/ShopStorage.cs
Normal file
@@ -0,0 +1,131 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using PizzeriaContracts.BindingModels;
|
||||||
|
using PizzeriaContracts.SearchModels;
|
||||||
|
using PizzeriaContracts.StoragesContracts;
|
||||||
|
using PizzeriaContracts.ViewModels;
|
||||||
|
using PizzeriaDatabaseImplement.Models;
|
||||||
|
using PizzeriaDataModels.Models;
|
||||||
|
|
||||||
|
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 new();
|
||||||
|
}
|
||||||
|
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 (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(x => x.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 shop = context.Shops.Include(x => x.Pizzas).FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (shop != null)
|
||||||
|
{
|
||||||
|
context.Shops.Remove(shop);
|
||||||
|
context.SaveChanges();
|
||||||
|
return shop.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool SellPizzas(IPizzaModel model, int count)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
return false;
|
||||||
|
using var context = new PizzeriaDatabase();
|
||||||
|
using var transaction = context.Database.BeginTransaction();
|
||||||
|
List<ShopPizzas> lst = new List<ShopPizzas>();
|
||||||
|
foreach (var el in context.ShopPizzas.Where(x => x.PizzaId == model.Id))
|
||||||
|
{
|
||||||
|
int dif = count;
|
||||||
|
if (el.Count < dif)
|
||||||
|
dif = el.Count;
|
||||||
|
el.Count -= dif;
|
||||||
|
count -= dif;
|
||||||
|
if (el.Count == 0)
|
||||||
|
{
|
||||||
|
lst.Add(el);
|
||||||
|
}
|
||||||
|
if (count == 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (count > 0)
|
||||||
|
{
|
||||||
|
transaction.Rollback();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
foreach (var el in lst)
|
||||||
|
{
|
||||||
|
context.ShopPizzas.Remove(el);
|
||||||
|
}
|
||||||
|
context.SaveChanges();
|
||||||
|
transaction.Commit();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
170
Pizzeria/PizzeriaDatabaseImplement/Migrations/20240309113549_InitMigration.Designer.cs
generated
Normal file
170
Pizzeria/PizzeriaDatabaseImplement/Migrations/20240309113549_InitMigration.Designer.cs
generated
Normal file
@@ -0,0 +1,170 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using PizzeriaDatabaseImplement;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace PizzeriaDatabaseImplement.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(PizzeriaDatabase))]
|
||||||
|
[Migration("20240309113549_InitMigration")]
|
||||||
|
partial class InitMigration
|
||||||
|
{
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "6.0.27")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||||
|
|
||||||
|
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1);
|
||||||
|
|
||||||
|
modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Component", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);
|
||||||
|
|
||||||
|
b.Property<string>("ComponentName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<double>("Cost")
|
||||||
|
.HasColumnType("float");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Components");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Order", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);
|
||||||
|
|
||||||
|
b.Property<int>("Count")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateCreate")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<DateTime?>("DateImplement")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<int>("PizzaId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("Status")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<double>("Sum")
|
||||||
|
.HasColumnType("float");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("PizzaId");
|
||||||
|
|
||||||
|
b.ToTable("Orders");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Pizza", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);
|
||||||
|
|
||||||
|
b.Property<string>("PizzaName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<double>("Price")
|
||||||
|
.HasColumnType("float");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Pizzas");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("PizzeriaDatabaseImplement.Models.PizzaComponent", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);
|
||||||
|
|
||||||
|
b.Property<int>("ComponentId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("Count")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("PizzaId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,122 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace PizzeriaDatabaseImplement.Migrations
|
||||||
|
{
|
||||||
|
public partial class InitMigration : Migration
|
||||||
|
{
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Components",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
|
ComponentName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||||
|
Cost = table.Column<double>(type: "float", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Components", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Pizzas",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
|
PizzaName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||||
|
Price = table.Column<double>(type: "float", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Pizzas", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Orders",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
|
PizzaId = table.Column<int>(type: "int", nullable: false),
|
||||||
|
Count = table.Column<int>(type: "int", nullable: false),
|
||||||
|
Sum = table.Column<double>(type: "float", nullable: false),
|
||||||
|
Status = table.Column<int>(type: "int", nullable: false),
|
||||||
|
DateCreate = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||||
|
DateImplement = table.Column<DateTime>(type: "datetime2", nullable: true)
|
||||||
|
},
|
||||||
|
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: "int", nullable: false)
|
||||||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
|
PizzaId = table.Column<int>(type: "int", nullable: false),
|
||||||
|
ComponentId = table.Column<int>(type: "int", nullable: false),
|
||||||
|
Count = table.Column<int>(type: "int", 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");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Orders");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "PizzaComponents");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Components");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Pizzas");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
249
Pizzeria/PizzeriaDatabaseImplement/Migrations/20240504122039_ShopMigration.Designer.cs
generated
Normal file
249
Pizzeria/PizzeriaDatabaseImplement/Migrations/20240504122039_ShopMigration.Designer.cs
generated
Normal file
@@ -0,0 +1,249 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using PizzeriaDatabaseImplement;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace PizzeriaDatabaseImplement.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(PizzeriaDatabase))]
|
||||||
|
[Migration("20240504122039_ShopMigration")]
|
||||||
|
partial class ShopMigration
|
||||||
|
{
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "6.0.0")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||||
|
|
||||||
|
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1);
|
||||||
|
|
||||||
|
modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Component", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);
|
||||||
|
|
||||||
|
b.Property<string>("ComponentName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<double>("Cost")
|
||||||
|
.HasColumnType("float");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Components");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Order", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);
|
||||||
|
|
||||||
|
b.Property<int>("Count")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateCreate")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<DateTime?>("DateImplement")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<int>("PizzaId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("Status")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<double>("Sum")
|
||||||
|
.HasColumnType("float");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("PizzaId");
|
||||||
|
|
||||||
|
b.ToTable("Orders");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Pizza", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);
|
||||||
|
|
||||||
|
b.Property<string>("PizzaName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<double>("Price")
|
||||||
|
.HasColumnType("float");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Pizzas");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("PizzeriaDatabaseImplement.Models.PizzaComponent", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);
|
||||||
|
|
||||||
|
b.Property<int>("ComponentId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("Count")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("PizzaId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("ComponentId");
|
||||||
|
|
||||||
|
b.HasIndex("PizzaId");
|
||||||
|
|
||||||
|
b.ToTable("PizzaComponents");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Shop", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);
|
||||||
|
|
||||||
|
b.Property<string>("Adress")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<DateTime>("OpeningDate")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<int>("PizzaMaxCount")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<string>("ShopName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Shops");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("PizzeriaDatabaseImplement.Models.ShopPizzas", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);
|
||||||
|
|
||||||
|
b.Property<int>("Count")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("PizzaId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("ShopId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("PizzaId");
|
||||||
|
|
||||||
|
b.HasIndex("ShopId");
|
||||||
|
|
||||||
|
b.ToTable("ShopPizzas");
|
||||||
|
});
|
||||||
|
|
||||||
|
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.ShopPizzas", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("PizzeriaDatabaseImplement.Models.Pizza", "Pizza")
|
||||||
|
.WithMany("ShopPizzas")
|
||||||
|
.HasForeignKey("PizzaId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("PizzeriaDatabaseImplement.Models.Shop", "Shop")
|
||||||
|
.WithMany("Pizzas")
|
||||||
|
.HasForeignKey("ShopId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Pizza");
|
||||||
|
|
||||||
|
b.Navigation("Shop");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Component", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("PizzaComponents");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Pizza", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Components");
|
||||||
|
|
||||||
|
b.Navigation("Orders");
|
||||||
|
|
||||||
|
b.Navigation("ShopPizzas");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Shop", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Pizzas");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace PizzeriaDatabaseImplement.Migrations
|
||||||
|
{
|
||||||
|
public partial class ShopMigration : Migration
|
||||||
|
{
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Shops",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
|
ShopName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||||
|
Adress = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||||
|
OpeningDate = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||||
|
PizzaMaxCount = table.Column<int>(type: "int", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Shops", x => x.Id);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "ShopPizzas",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
Id = table.Column<int>(type: "int", nullable: false)
|
||||||
|
.Annotation("SqlServer:Identity", "1, 1"),
|
||||||
|
PizzaId = table.Column<int>(type: "int", nullable: false),
|
||||||
|
ShopId = table.Column<int>(type: "int", nullable: false),
|
||||||
|
Count = table.Column<int>(type: "int", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_ShopPizzas", x => x.Id);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_ShopPizzas_Pizzas_PizzaId",
|
||||||
|
column: x => x.PizzaId,
|
||||||
|
principalTable: "Pizzas",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_ShopPizzas_Shops_ShopId",
|
||||||
|
column: x => x.ShopId,
|
||||||
|
principalTable: "Shops",
|
||||||
|
principalColumn: "Id",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_ShopPizzas_PizzaId",
|
||||||
|
table: "ShopPizzas",
|
||||||
|
column: "PizzaId");
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_ShopPizzas_ShopId",
|
||||||
|
table: "ShopPizzas",
|
||||||
|
column: "ShopId");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "ShopPizzas");
|
||||||
|
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Shops");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,247 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
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", "6.0.0")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||||
|
|
||||||
|
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1);
|
||||||
|
|
||||||
|
modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Component", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);
|
||||||
|
|
||||||
|
b.Property<string>("ComponentName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<double>("Cost")
|
||||||
|
.HasColumnType("float");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Components");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Order", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);
|
||||||
|
|
||||||
|
b.Property<int>("Count")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateCreate")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<DateTime?>("DateImplement")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<int>("PizzaId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("Status")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<double>("Sum")
|
||||||
|
.HasColumnType("float");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("PizzaId");
|
||||||
|
|
||||||
|
b.ToTable("Orders");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Pizza", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);
|
||||||
|
|
||||||
|
b.Property<string>("PizzaName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<double>("Price")
|
||||||
|
.HasColumnType("float");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Pizzas");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("PizzeriaDatabaseImplement.Models.PizzaComponent", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);
|
||||||
|
|
||||||
|
b.Property<int>("ComponentId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("Count")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("PizzaId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("ComponentId");
|
||||||
|
|
||||||
|
b.HasIndex("PizzaId");
|
||||||
|
|
||||||
|
b.ToTable("PizzaComponents");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Shop", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);
|
||||||
|
|
||||||
|
b.Property<string>("Adress")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<DateTime>("OpeningDate")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<int>("PizzaMaxCount")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<string>("ShopName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Shops");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("PizzeriaDatabaseImplement.Models.ShopPizzas", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);
|
||||||
|
|
||||||
|
b.Property<int>("Count")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("PizzaId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("ShopId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("PizzaId");
|
||||||
|
|
||||||
|
b.HasIndex("ShopId");
|
||||||
|
|
||||||
|
b.ToTable("ShopPizzas");
|
||||||
|
});
|
||||||
|
|
||||||
|
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.ShopPizzas", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("PizzeriaDatabaseImplement.Models.Pizza", "Pizza")
|
||||||
|
.WithMany("ShopPizzas")
|
||||||
|
.HasForeignKey("PizzaId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("PizzeriaDatabaseImplement.Models.Shop", "Shop")
|
||||||
|
.WithMany("Pizzas")
|
||||||
|
.HasForeignKey("ShopId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Pizza");
|
||||||
|
|
||||||
|
b.Navigation("Shop");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Component", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("PizzaComponents");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Pizza", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Components");
|
||||||
|
|
||||||
|
b.Navigation("Orders");
|
||||||
|
|
||||||
|
b.Navigation("ShopPizzas");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("PizzeriaDatabaseImplement.Models.Shop", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Pizzas");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
60
Pizzeria/PizzeriaDatabaseImplement/Models/Component.cs
Normal file
60
Pizzeria/PizzeriaDatabaseImplement/Models/Component.cs
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
using PizzeriaContracts.BindingModels;
|
||||||
|
using PizzeriaContracts.ViewModels;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using PizzeriaDataModels.Models;
|
||||||
|
|
||||||
|
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
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
69
Pizzeria/PizzeriaDatabaseImplement/Models/Order.cs
Normal file
69
Pizzeria/PizzeriaDatabaseImplement/Models/Order.cs
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
using PizzeriaContracts.BindingModels;
|
||||||
|
using PizzeriaContracts.ViewModels;
|
||||||
|
using PizzeriaDataModels.Enums;
|
||||||
|
using PizzeriaDataModels.Models;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace PizzeriaDatabaseImplement.Models
|
||||||
|
{
|
||||||
|
public class Order : IOrderModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
|
||||||
|
[Required]
|
||||||
|
public int PizzaId { get; private set; }
|
||||||
|
|
||||||
|
public virtual Pizza Pizza { get; set; } = new();
|
||||||
|
|
||||||
|
[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 static Order Create(PizzeriaDatabase context, OrderBindingModel model)
|
||||||
|
{
|
||||||
|
return new Order()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
PizzaId = model.PizzaId,
|
||||||
|
Pizza = context.Pizzas.First(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,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
99
Pizzeria/PizzeriaDatabaseImplement/Models/Pizza.cs
Normal file
99
Pizzeria/PizzeriaDatabaseImplement/Models/Pizza.cs
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
using PizzeriaContracts.BindingModels;
|
||||||
|
using PizzeriaContracts.ViewModels;
|
||||||
|
using PizzeriaDataModels.Models;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
[ForeignKey("PizzaId")]
|
||||||
|
public virtual List<ShopPizzas> ShopPizzas { 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
17
Pizzeria/PizzeriaDatabaseImplement/Models/PizzaComponent.cs
Normal file
17
Pizzeria/PizzeriaDatabaseImplement/Models/PizzaComponent.cs
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
114
Pizzeria/PizzeriaDatabaseImplement/Models/Shop.cs
Normal file
114
Pizzeria/PizzeriaDatabaseImplement/Models/Shop.cs
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
using PizzeriaContracts.BindingModels;
|
||||||
|
using PizzeriaContracts.ViewModels;
|
||||||
|
using PizzeriaDataModels.Models;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
|
namespace PizzeriaDatabaseImplement.Models
|
||||||
|
{
|
||||||
|
public class Shop : IShopModel
|
||||||
|
{
|
||||||
|
public int Id { get; set; }
|
||||||
|
public string ShopName { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public string Adress { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public DateTime OpeningDate { get; set; }
|
||||||
|
|
||||||
|
public int PizzaMaxCount { get; set; }
|
||||||
|
|
||||||
|
private Dictionary<int, (IPizzaModel, int)>? _shopPizzas = null;
|
||||||
|
|
||||||
|
public Dictionary<int, (IPizzaModel, int)> ShopPizzas
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_shopPizzas == null)
|
||||||
|
{
|
||||||
|
if (_shopPizzas == null)
|
||||||
|
{
|
||||||
|
_shopPizzas = Pizzas
|
||||||
|
.ToDictionary(recSP => recSP.PizzaId, recSP => (recSP.Pizza as IPizzaModel, recSP.Count));
|
||||||
|
}
|
||||||
|
return _shopPizzas;
|
||||||
|
}
|
||||||
|
return _shopPizzas;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[ForeignKey("ShopId")]
|
||||||
|
public List<ShopPizzas> Pizzas { get; set; } = new();
|
||||||
|
|
||||||
|
public static Shop Create(PizzeriaDatabase context, ShopBindingModel model)
|
||||||
|
{
|
||||||
|
return new Shop()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
ShopName = model.ShopName,
|
||||||
|
Adress = model.Adress,
|
||||||
|
OpeningDate = model.OpeningDate,
|
||||||
|
Pizzas = model.ShopPizzas.Select(x => new ShopPizzas
|
||||||
|
{
|
||||||
|
Pizza = context.Pizzas.First(y => y.Id == x.Key),
|
||||||
|
Count = x.Value.Item2
|
||||||
|
}).ToList(),
|
||||||
|
PizzaMaxCount = model.PizzaMaxCount
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(ShopBindingModel model)
|
||||||
|
{
|
||||||
|
ShopName = model.ShopName;
|
||||||
|
Adress = model.Adress;
|
||||||
|
OpeningDate = model.OpeningDate;
|
||||||
|
PizzaMaxCount = model.PizzaMaxCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
ShopName = ShopName,
|
||||||
|
Adress = Adress,
|
||||||
|
OpeningDate = OpeningDate,
|
||||||
|
ShopPizzas = ShopPizzas,
|
||||||
|
PizzaMaxCount = PizzaMaxCount
|
||||||
|
};
|
||||||
|
|
||||||
|
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();
|
||||||
|
ShopPizzas = context.ShopPizzas.Where(rec => rec.ShopId == model.Id).ToList();
|
||||||
|
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 ar in model.ShopPizzas)
|
||||||
|
{
|
||||||
|
context.ShopPizzas.Add(new ShopPizzas
|
||||||
|
{
|
||||||
|
Shop = shop,
|
||||||
|
Pizza = context.Pizzas.First(x => x.Id == ar.Key),
|
||||||
|
Count = ar.Value.Item2
|
||||||
|
});
|
||||||
|
context.SaveChanges();
|
||||||
|
}
|
||||||
|
_shopPizzas = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void PizzasDictionatyUpdate(PizzeriaDatabase context)
|
||||||
|
{
|
||||||
|
UpdatePizzas(context, new ShopBindingModel
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
ShopPizzas = ShopPizzas,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
22
Pizzeria/PizzeriaDatabaseImplement/Models/ShopPizzas.cs
Normal file
22
Pizzeria/PizzeriaDatabaseImplement/Models/ShopPizzas.cs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace PizzeriaDatabaseImplement.Models
|
||||||
|
{
|
||||||
|
public class ShopPizzas
|
||||||
|
{
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
25
Pizzeria/PizzeriaDatabaseImplement/PizzeriaDatabase.cs
Normal file
25
Pizzeria/PizzeriaDatabaseImplement/PizzeriaDatabase.cs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
using PizzeriaDatabaseImplement.Models;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace PizzeriaDatabaseImplement
|
||||||
|
{
|
||||||
|
public class PizzeriaDatabase : DbContext
|
||||||
|
{
|
||||||
|
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||||
|
{
|
||||||
|
if (!optionsBuilder.IsConfigured)
|
||||||
|
{
|
||||||
|
optionsBuilder.UseSqlServer(@"Data Source=ALYONA\;Initial Catalog=PizzeriaDatabase;Integrated Security=True;MultipleActiveResultSets=True;;TrustServerCertificate=True");
|
||||||
|
}
|
||||||
|
base.OnConfiguring(optionsBuilder);
|
||||||
|
}
|
||||||
|
public virtual DbSet<Component> Components { set; get; }
|
||||||
|
public virtual DbSet<Pizza> Pizzas { set; get; }
|
||||||
|
public virtual DbSet<PizzaComponent> PizzaComponents { set; get; }
|
||||||
|
public virtual DbSet<Order> Orders { set; get; }
|
||||||
|
|
||||||
|
public virtual DbSet<Shop> Shops { get; set; }
|
||||||
|
public virtual DbSet<ShopPizzas> ShopPizzas { get; set; }
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\PizzeriaContracts\PizzeriaContracts.csproj" />
|
||||||
|
<ProjectReference Include="..\PizzeriaDataModels\PizzeriaDataModels.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.0" />
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.0">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
57
Pizzeria/PizzeriaFileImplement/DataFileSingleton.cs
Normal file
57
Pizzeria/PizzeriaFileImplement/DataFileSingleton.cs
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
using PizzeriaFileImplement.Models;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
|
namespace PizzeriaFileImplement
|
||||||
|
{
|
||||||
|
public class DataFileSingleton
|
||||||
|
{
|
||||||
|
private static DataFileSingleton? instance;
|
||||||
|
private readonly string ComponentFileName = "Component.xml";
|
||||||
|
private readonly string OrderFileName = "Order.xml";
|
||||||
|
private readonly string PizzaFileName = "Pizza.xml";
|
||||||
|
private readonly string ShopFileName = "Shop.xml";
|
||||||
|
public List<Component> Components { get; private set; }
|
||||||
|
public List<Order> Orders { get; private set; }
|
||||||
|
public List<Pizza> Pizzas { get; private set; }
|
||||||
|
public List<Shop> Shops { get; private set; }
|
||||||
|
|
||||||
|
public static DataFileSingleton GetInstance()
|
||||||
|
{
|
||||||
|
if (instance == null)
|
||||||
|
{
|
||||||
|
instance = new DataFileSingleton();
|
||||||
|
}
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SaveComponents() => SaveData(Components, ComponentFileName, "Components", x => x.GetXElement);
|
||||||
|
public void SavePizzas() => SaveData(Pizzas, PizzaFileName, "Pizzas", x => x.GetXElement);
|
||||||
|
public void SaveOrders() => SaveData(Orders, OrderFileName, "Orders", x => x.GetXElement);
|
||||||
|
public void SaveShops() => SaveData(Shops, ShopFileName, "Shops", x => x.GetXElement);
|
||||||
|
|
||||||
|
private DataFileSingleton()
|
||||||
|
{
|
||||||
|
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
|
||||||
|
Pizzas = LoadData(PizzaFileName, "Pizza", x => Pizza.Create(x)!)!;
|
||||||
|
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
|
||||||
|
Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
|
||||||
|
{
|
||||||
|
if (File.Exists(filename))
|
||||||
|
{
|
||||||
|
return XDocument.Load(filename)?.Root?.Elements(xmlNodeName)?.Select(selectFunction)?.ToList();
|
||||||
|
}
|
||||||
|
return new List<T>();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void SaveData<T>(List<T> data, string filename, string xmlNodeName, Func<T, XElement> selectFunction)
|
||||||
|
{
|
||||||
|
if (data != null)
|
||||||
|
{
|
||||||
|
new XDocument(new XElement(xmlNodeName, data.Select(selectFunction).ToArray())).Save(filename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using PizzeriaContracts.BindingModels;
|
||||||
|
using PizzeriaContracts.SearchModels;
|
||||||
|
using PizzeriaContracts.StoragesContracts;
|
||||||
|
using PizzeriaContracts.ViewModels;
|
||||||
|
using PizzeriaFileImplement.Models;
|
||||||
|
|
||||||
|
namespace PizzeriaFileImplement.Implements
|
||||||
|
{
|
||||||
|
public class ComponentStorage : IComponentStorage
|
||||||
|
{
|
||||||
|
private readonly DataFileSingleton source;
|
||||||
|
|
||||||
|
public ComponentStorage()
|
||||||
|
{
|
||||||
|
source = DataFileSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ComponentViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
return source.Components.Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ComponentViewModel> GetFilteredList(ComponentSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.ComponentName))
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
return source.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;
|
||||||
|
}
|
||||||
|
return source.Components.FirstOrDefault(x =>
|
||||||
|
(!string.IsNullOrEmpty(model.ComponentName) && x.ComponentName == model.ComponentName) ||
|
||||||
|
(model.Id.HasValue && x.Id == model.Id))
|
||||||
|
?.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ComponentViewModel? Insert(ComponentBindingModel model)
|
||||||
|
{
|
||||||
|
model.Id = source.Components.Count > 0 ? source.Components.Max(x => x.Id) + 1 : 1;
|
||||||
|
var newComponent = Component.Create(model);
|
||||||
|
if (newComponent == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
source.Components.Add(newComponent);
|
||||||
|
source.SaveComponents();
|
||||||
|
return newComponent.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ComponentViewModel? Update(ComponentBindingModel model)
|
||||||
|
{
|
||||||
|
var component = source.Components.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (component == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
component.Update(model);
|
||||||
|
source.SaveComponents();
|
||||||
|
return component.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ComponentViewModel? Delete(ComponentBindingModel model)
|
||||||
|
{
|
||||||
|
var element = source.Components.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (element != null)
|
||||||
|
{
|
||||||
|
source.Components.Remove(element);
|
||||||
|
source.SaveComponents();
|
||||||
|
return element.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
90
Pizzeria/PizzeriaFileImplement/Implements/OrderStorage.cs
Normal file
90
Pizzeria/PizzeriaFileImplement/Implements/OrderStorage.cs
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
using PizzeriaContracts.BindingModels;
|
||||||
|
using PizzeriaContracts.SearchModels;
|
||||||
|
using PizzeriaContracts.StoragesContracts;
|
||||||
|
using PizzeriaContracts.ViewModels;
|
||||||
|
using PizzeriaFileImplement.Models;
|
||||||
|
|
||||||
|
namespace PizzeriaFileImplement.Implements
|
||||||
|
{
|
||||||
|
public class OrderStorage : IOrderStorage
|
||||||
|
{
|
||||||
|
private readonly DataFileSingleton source;
|
||||||
|
|
||||||
|
public OrderStorage()
|
||||||
|
{
|
||||||
|
source = DataFileSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<OrderViewModel> GetFullList() => source.Orders.Select(x => AttachPizzaName(x.GetViewModel)).ToList();
|
||||||
|
|
||||||
|
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||||
|
{
|
||||||
|
if (!model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
return source.Orders.Where(x => x.Id == model.Id).Select(x => AttachPizzaName(x.GetViewModel)).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||||
|
{
|
||||||
|
if (!model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
return AttachPizzaName(source.Orders.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel? Insert(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1;
|
||||||
|
var newOrder = Order.Create(model);
|
||||||
|
if (newOrder == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
source.Orders.Add(newOrder);
|
||||||
|
source.SaveOrders();
|
||||||
|
return AttachPizzaName(newOrder.GetViewModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel? Update(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
var order = source.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (order == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
order.Update(model);
|
||||||
|
source.SaveOrders();
|
||||||
|
return AttachPizzaName(order.GetViewModel);
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel? Delete(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
var order = source.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (order != null)
|
||||||
|
{
|
||||||
|
source.Orders.Remove(order);
|
||||||
|
source.SaveOrders();
|
||||||
|
return AttachPizzaName(order.GetViewModel);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private OrderViewModel? AttachPizzaName(OrderViewModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
var pizza = source.Pizzas.FirstOrDefault(x => x.Id == model.PizzaId);
|
||||||
|
if (pizza != null)
|
||||||
|
{
|
||||||
|
model.PizzaName = pizza.PizzaName;
|
||||||
|
}
|
||||||
|
return model;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
81
Pizzeria/PizzeriaFileImplement/Implements/PizzaStorage.cs
Normal file
81
Pizzeria/PizzeriaFileImplement/Implements/PizzaStorage.cs
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
using PizzeriaContracts.BindingModels;
|
||||||
|
using PizzeriaContracts.SearchModels;
|
||||||
|
using PizzeriaContracts.StoragesContracts;
|
||||||
|
using PizzeriaContracts.ViewModels;
|
||||||
|
using PizzeriaFileImplement.Models;
|
||||||
|
|
||||||
|
namespace PizzeriaFileImplement.Implements
|
||||||
|
{
|
||||||
|
public class PizzaStorage : IPizzaStorage
|
||||||
|
{
|
||||||
|
private readonly DataFileSingleton source;
|
||||||
|
|
||||||
|
public PizzaStorage()
|
||||||
|
{
|
||||||
|
source = DataFileSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<PizzaViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
return source.Pizzas.Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<PizzaViewModel> GetFilteredList(PizzaSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.PizzaName))
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
return source.Pizzas.Where(x => x.PizzaName.Contains(model.PizzaName)).Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public PizzaViewModel? GetElement(PizzaSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.PizzaName) && !model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return source.Pizzas.FirstOrDefault(x =>
|
||||||
|
(!string.IsNullOrEmpty(model.PizzaName) && x.PizzaName == model.PizzaName) ||
|
||||||
|
(model.Id.HasValue && x.Id == model.Id))
|
||||||
|
?.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PizzaViewModel? Insert(PizzaBindingModel model)
|
||||||
|
{
|
||||||
|
model.Id = source.Pizzas.Count > 0 ? source.Pizzas.Max(x => x.Id) + 1 : 1;
|
||||||
|
var newPizza = Pizza.Create(model);
|
||||||
|
if (newPizza == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
source.Pizzas.Add(newPizza);
|
||||||
|
source.SavePizzas();
|
||||||
|
return newPizza.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PizzaViewModel? Update(PizzaBindingModel model)
|
||||||
|
{
|
||||||
|
var Pizza = source.Pizzas.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (Pizza == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
Pizza.Update(model);
|
||||||
|
source.SavePizzas();
|
||||||
|
return Pizza.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PizzaViewModel? Delete(PizzaBindingModel model)
|
||||||
|
{
|
||||||
|
var Pizza = source.Pizzas.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (Pizza != null)
|
||||||
|
{
|
||||||
|
source.Pizzas.Remove(Pizza);
|
||||||
|
source.SavePizzas();
|
||||||
|
return Pizza.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
131
Pizzeria/PizzeriaFileImplement/Implements/ShopStorage.cs
Normal file
131
Pizzeria/PizzeriaFileImplement/Implements/ShopStorage.cs
Normal file
@@ -0,0 +1,131 @@
|
|||||||
|
using PizzeriaContracts.BindingModels;
|
||||||
|
using PizzeriaContracts.SearchModels;
|
||||||
|
using PizzeriaContracts.StoragesContracts;
|
||||||
|
using PizzeriaContracts.ViewModels;
|
||||||
|
using PizzeriaDataModels.Models;
|
||||||
|
using PizzeriaFileImplement.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace PizzeriaFileImplement.Implements
|
||||||
|
{
|
||||||
|
public class ShopStorage : IShopStorage
|
||||||
|
{
|
||||||
|
private readonly DataFileSingleton source;
|
||||||
|
|
||||||
|
public ShopStorage()
|
||||||
|
{
|
||||||
|
source = DataFileSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ShopViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
return source.Shops.Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ShopViewModel> GetFilteredList(ShopSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.ShopName))
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
return source.Shops.Where(x => x.ShopName.Contains(model.ShopName)).Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopViewModel? GetElement(ShopSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.ShopName) && !model.Id.HasValue)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return source.Shops.FirstOrDefault(x =>
|
||||||
|
(!string.IsNullOrEmpty(model.ShopName) && x.ShopName == model.ShopName) ||
|
||||||
|
(model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopViewModel? Insert(ShopBindingModel model)
|
||||||
|
{
|
||||||
|
model.Id = source.Shops.Count > 0 ? source.Shops.Max(x => x.Id) + 1 : 1;
|
||||||
|
var newShop = Shop.Create(model);
|
||||||
|
if (newShop == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
source.Shops.Add(newShop);
|
||||||
|
source.SaveShops();
|
||||||
|
return newShop.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopViewModel? Update(ShopBindingModel model)
|
||||||
|
{
|
||||||
|
var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (shop == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
shop.Update(model);
|
||||||
|
source.SaveShops();
|
||||||
|
return shop.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopViewModel? Delete(ShopBindingModel model)
|
||||||
|
{
|
||||||
|
var shop = source.Shops.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
if (shop != null)
|
||||||
|
{
|
||||||
|
source.Shops.Remove(shop);
|
||||||
|
source.SaveShops();
|
||||||
|
return shop.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool SellPizzas(IPizzaModel model, int count)
|
||||||
|
{
|
||||||
|
var pizza = source.Pizzas.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
|
||||||
|
int countStore = source.Shops
|
||||||
|
.SelectMany(x => x.ShopPizzas)
|
||||||
|
.Where(y => y.Key == model.Id)
|
||||||
|
.Sum(y => y.Value.Item2);
|
||||||
|
|
||||||
|
if (pizza == null || count > countStore)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
foreach (var shop in source.Shops)
|
||||||
|
{
|
||||||
|
var pizzas = shop.ShopPizzas;
|
||||||
|
|
||||||
|
foreach (var c in pizzas.Where(x => x.Value.Item1.Id == pizza.Id))
|
||||||
|
{
|
||||||
|
int min = Math.Min(c.Value.Item2, count);
|
||||||
|
pizzas[c.Value.Item1.Id] = (c.Value.Item1, c.Value.Item2 - min);
|
||||||
|
count -= min;
|
||||||
|
|
||||||
|
if (count <= 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
shop.Update(new ShopBindingModel
|
||||||
|
{
|
||||||
|
Id = shop.Id,
|
||||||
|
ShopName = shop.ShopName,
|
||||||
|
Adress = shop.Adress,
|
||||||
|
PizzaMaxCount = shop.PizzaMaxCount,
|
||||||
|
OpeningDate = shop.OpeningDate,
|
||||||
|
ShopPizzas = pizzas
|
||||||
|
});
|
||||||
|
|
||||||
|
source.SaveShops();
|
||||||
|
|
||||||
|
if (count <= 0)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
64
Pizzeria/PizzeriaFileImplement/Models/Component.cs
Normal file
64
Pizzeria/PizzeriaFileImplement/Models/Component.cs
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
using PizzeriaContracts.BindingModels;
|
||||||
|
using PizzeriaContracts.ViewModels;
|
||||||
|
using PizzeriaDataModels.Models;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
|
namespace PizzeriaFileImplement.Models
|
||||||
|
{
|
||||||
|
public class Component : IComponentModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
public string ComponentName { get; private set; } = string.Empty;
|
||||||
|
public double Cost { get; set; }
|
||||||
|
|
||||||
|
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(XElement element)
|
||||||
|
{
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Component()
|
||||||
|
{
|
||||||
|
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||||
|
ComponentName = element.Element("ComponentName")!.Value,
|
||||||
|
Cost = Convert.ToDouble(element.Element("Cost")!.Value)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
};
|
||||||
|
|
||||||
|
public XElement GetXElement => new("Component",
|
||||||
|
new XAttribute("Id", Id),
|
||||||
|
new XElement("ComponentName", ComponentName),
|
||||||
|
new XElement("Cost", Cost.ToString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
87
Pizzeria/PizzeriaFileImplement/Models/Order.cs
Normal file
87
Pizzeria/PizzeriaFileImplement/Models/Order.cs
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
using PizzeriaDataModels.Enums;
|
||||||
|
using PizzeriaDataModels.Models;
|
||||||
|
using PizzeriaContracts.BindingModels;
|
||||||
|
using PizzeriaContracts.ViewModels;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
|
namespace PizzeriaFileImplement.Models
|
||||||
|
{
|
||||||
|
public class Order : IOrderModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
public int PizzaId { get; private set; }
|
||||||
|
public int Count { get; private set; }
|
||||||
|
public double Sum { get; private set; }
|
||||||
|
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
|
||||||
|
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
||||||
|
public DateTime? DateImplement { get; private set; }
|
||||||
|
|
||||||
|
public static Order? Create(OrderBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Order()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
PizzaId = model.PizzaId,
|
||||||
|
Count = model.Count,
|
||||||
|
Sum = model.Sum,
|
||||||
|
Status = model.Status,
|
||||||
|
DateCreate = model.DateCreate,
|
||||||
|
DateImplement = model.DateImplement,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Order? Create(XElement element)
|
||||||
|
{
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
string dateImplement = element.Element("DateImplement")!.Value;
|
||||||
|
return new Order()
|
||||||
|
{
|
||||||
|
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||||
|
PizzaId = Convert.ToInt32(element.Element("PizzaId")!.Value),
|
||||||
|
Count = Convert.ToInt32(element.Element("Count")!.Value),
|
||||||
|
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
|
||||||
|
Status = (OrderStatus)(Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value)),
|
||||||
|
DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value),
|
||||||
|
DateImplement = (dateImplement == "" || dateImplement is null) ? Convert.ToDateTime(null) : Convert.ToDateTime(dateImplement)
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(OrderBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Status = model.Status;
|
||||||
|
if (model.Status == OrderStatus.Готов) DateImplement = model.DateImplement;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
PizzaId = PizzaId,
|
||||||
|
Count = Count,
|
||||||
|
Sum = Sum,
|
||||||
|
Status = Status,
|
||||||
|
DateCreate = DateCreate,
|
||||||
|
DateImplement = DateImplement,
|
||||||
|
};
|
||||||
|
|
||||||
|
public XElement GetXElement => new("Order",
|
||||||
|
new XAttribute("Id", Id),
|
||||||
|
new XElement("PizzaId", PizzaId.ToString()),
|
||||||
|
new XElement("Count", Count.ToString()),
|
||||||
|
new XElement("Sum", Sum.ToString()),
|
||||||
|
new XElement("Status", Status.ToString()),
|
||||||
|
new XElement("DateCreate", DateCreate.ToString()),
|
||||||
|
new XElement("DateImplement", DateImplement.ToString()));
|
||||||
|
}
|
||||||
|
}
|
||||||
81
Pizzeria/PizzeriaFileImplement/Models/Pizza.cs
Normal file
81
Pizzeria/PizzeriaFileImplement/Models/Pizza.cs
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
using PizzeriaContracts.BindingModels;
|
||||||
|
using PizzeriaContracts.ViewModels;
|
||||||
|
using PizzeriaDataModels.Models;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
|
namespace PizzeriaFileImplement.Models
|
||||||
|
{
|
||||||
|
public class Pizza : IPizzaModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
public string PizzaName { get; private set; } = string.Empty;
|
||||||
|
public double Price { get; private set; }
|
||||||
|
public Dictionary<int, int> Components { get; private set; } = new();
|
||||||
|
private Dictionary<int, (IComponentModel, int)>? _pizzaComponents = null;
|
||||||
|
public Dictionary<int, (IComponentModel, int)> PizzaComponents
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_pizzaComponents == null)
|
||||||
|
{
|
||||||
|
var source = DataFileSingleton.GetInstance();
|
||||||
|
_pizzaComponents = Components.ToDictionary(x => x.Key, y => ((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!, y.Value));
|
||||||
|
}
|
||||||
|
return _pizzaComponents;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public static Pizza? Create(PizzaBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Pizza()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
PizzaName = model.PizzaName,
|
||||||
|
Price = model.Price,
|
||||||
|
Components = model.PizzaComponents.ToDictionary(x => x.Key, x => x.Value.Item2)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public static Pizza? Create(XElement element)
|
||||||
|
{
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Pizza()
|
||||||
|
{
|
||||||
|
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||||
|
PizzaName = element.Element("PizzaName")!.Value,
|
||||||
|
Price = Convert.ToDouble(element.Element("Price")!.Value),
|
||||||
|
Components = element.Element("PizzaComponents")!.Elements("PizzaComponent").ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value),
|
||||||
|
x => Convert.ToInt32(x.Element("Value")?.Value))
|
||||||
|
};
|
||||||
|
}
|
||||||
|
public void Update(PizzaBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
PizzaName = model.PizzaName;
|
||||||
|
Price = model.Price;
|
||||||
|
Components = model.PizzaComponents.ToDictionary(x => x.Key, x => x.Value.Item2);
|
||||||
|
_pizzaComponents = null;
|
||||||
|
}
|
||||||
|
public PizzaViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
PizzaName = PizzaName,
|
||||||
|
Price = Price,
|
||||||
|
PizzaComponents = PizzaComponents
|
||||||
|
};
|
||||||
|
public XElement GetXElement => new("Pizza",
|
||||||
|
new XAttribute("Id", Id),
|
||||||
|
new XElement("PizzaName", PizzaName),
|
||||||
|
new XElement("Price", Price.ToString()),
|
||||||
|
new XElement("PizzaComponents", Components.Select(
|
||||||
|
x => new XElement("PizzaComponent", new XElement("Key", x.Key), new XElement("Value", x.Value))).ToArray()));
|
||||||
|
}
|
||||||
|
}
|
||||||
111
Pizzeria/PizzeriaFileImplement/Models/Shop.cs
Normal file
111
Pizzeria/PizzeriaFileImplement/Models/Shop.cs
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
using PizzeriaDataModels.Models;
|
||||||
|
using PizzeriaContracts.BindingModels;
|
||||||
|
using PizzeriaContracts.ViewModels;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
|
namespace PizzeriaFileImplement.Models
|
||||||
|
{
|
||||||
|
public class Shop : IShopModel
|
||||||
|
{
|
||||||
|
public int Id { get; private set; }
|
||||||
|
public string ShopName { get; private set; } = string.Empty;
|
||||||
|
public string Adress { get; private set; } = string.Empty;
|
||||||
|
public DateTime OpeningDate { get; private set; }
|
||||||
|
public Dictionary<int, int> Pizzas { get; private set; } = new();
|
||||||
|
private Dictionary<int, (IPizzaModel, int)>? _shopPizzas = null;
|
||||||
|
|
||||||
|
public Dictionary<int, (IPizzaModel, int)> ShopPizzas
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (_shopPizzas == null)
|
||||||
|
{
|
||||||
|
var source = DataFileSingleton.GetInstance();
|
||||||
|
_shopPizzas = Pizzas.ToDictionary(x => x.Key, y => ((source.Pizzas.FirstOrDefault(z => z.Id == y.Key) as IPizzaModel)!, y.Value));
|
||||||
|
}
|
||||||
|
return _shopPizzas;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int PizzaMaxCount { get; private set; }
|
||||||
|
|
||||||
|
public static Shop? Create(ShopBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new Shop()
|
||||||
|
{
|
||||||
|
Id = model.Id,
|
||||||
|
ShopName = model.ShopName,
|
||||||
|
Adress = model.Adress,
|
||||||
|
OpeningDate = model.OpeningDate,
|
||||||
|
Pizzas = model.ShopPizzas.ToDictionary(x => x.Key, x => x.Value.Item2),
|
||||||
|
PizzaMaxCount = model.PizzaMaxCount
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Shop? Create(XElement element)
|
||||||
|
{
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new()
|
||||||
|
{
|
||||||
|
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
|
||||||
|
ShopName = element.Element("ShopName")!.Value,
|
||||||
|
Adress = element.Element("Adress")!.Value,
|
||||||
|
OpeningDate = Convert.ToDateTime(element.Element("OpeningDate")!.Value),
|
||||||
|
Pizzas = element.Element("ShopPizzas")!.Elements("ShopPizza")!.ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value),
|
||||||
|
x => Convert.ToInt32(x.Element("Value")?.Value)),
|
||||||
|
PizzaMaxCount = Convert.ToInt32(element.Element("PizzaMaxCount")!.Value)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Update(ShopBindingModel? model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ShopName = model.ShopName;
|
||||||
|
Adress = model.Adress;
|
||||||
|
OpeningDate = model.OpeningDate;
|
||||||
|
PizzaMaxCount = model.PizzaMaxCount;
|
||||||
|
Pizzas = model.ShopPizzas.ToDictionary(x => x.Key, x => x.Value.Item2);
|
||||||
|
_shopPizzas = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ShopViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Id = Id,
|
||||||
|
ShopName = ShopName,
|
||||||
|
Adress = Adress,
|
||||||
|
OpeningDate = OpeningDate,
|
||||||
|
ShopPizzas = ShopPizzas,
|
||||||
|
PizzaMaxCount = PizzaMaxCount
|
||||||
|
};
|
||||||
|
|
||||||
|
public XElement GetXElement => new("Shop",
|
||||||
|
new XAttribute("Id", Id),
|
||||||
|
new XElement("ShopName", ShopName),
|
||||||
|
new XElement("Adress", Adress),
|
||||||
|
new XElement("OpeningDate", OpeningDate.ToString()),
|
||||||
|
new XElement("ShopPizzas", Pizzas.Select(
|
||||||
|
x => new XElement("ShopPizza", new XElement("Key", x.Key), new XElement("Value", x.Value))).ToArray()),
|
||||||
|
new XElement("PizzaMaxCount", PizzaMaxCount.ToString())
|
||||||
|
);
|
||||||
|
|
||||||
|
public void PizzasUpdate()
|
||||||
|
{
|
||||||
|
_shopPizzas = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
14
Pizzeria/PizzeriaFileImplement/PizzeriaFileImplement.csproj
Normal file
14
Pizzeria/PizzeriaFileImplement/PizzeriaFileImplement.csproj
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\PizzeriaContracts\PizzeriaContracts.csproj" />
|
||||||
|
<ProjectReference Include="..\PizzeriaDataModels\PizzeriaDataModels.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
using PizzeriaContracts.SearchModels;
|
using PizzeriaContracts.SearchModels;
|
||||||
using PizzeriaContracts.StoragesContracts;
|
using PizzeriaContracts.StoragesContracts;
|
||||||
using PizzeriaContracts.ViewModels;
|
using PizzeriaContracts.ViewModels;
|
||||||
|
using PizzeriaDataModels.Models;
|
||||||
using PizzeriaListImplement.Models;
|
using PizzeriaListImplement.Models;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@@ -109,5 +110,14 @@ namespace PizzeriaListImplement.Implements
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public bool SellPizzas(IPizzaModel model, int count)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ namespace PizzeriaListImplement.Models
|
|||||||
public string Adress { get; private set; } = string.Empty;
|
public string Adress { get; private set; } = string.Empty;
|
||||||
public DateTime OpeningDate { get; private set; }
|
public DateTime OpeningDate { get; private set; }
|
||||||
public Dictionary<int, (IPizzaModel, int)> ShopPizzas { get; private set; } = new();
|
public Dictionary<int, (IPizzaModel, int)> ShopPizzas { get; private set; } = new();
|
||||||
|
public int PizzaMaxCount { get; private set; }
|
||||||
|
|
||||||
public static Shop? Create(ShopBindingModel? model)
|
public static Shop? Create(ShopBindingModel? model)
|
||||||
{
|
{
|
||||||
@@ -28,7 +29,8 @@ namespace PizzeriaListImplement.Models
|
|||||||
Id = model.Id,
|
Id = model.Id,
|
||||||
ShopName = model.ShopName,
|
ShopName = model.ShopName,
|
||||||
Adress = model.Adress,
|
Adress = model.Adress,
|
||||||
OpeningDate = model.OpeningDate
|
OpeningDate = model.OpeningDate,
|
||||||
|
PizzaMaxCount = model.PizzaMaxCount,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,6 +43,7 @@ namespace PizzeriaListImplement.Models
|
|||||||
ShopName = model.ShopName;
|
ShopName = model.ShopName;
|
||||||
Adress = model.Adress;
|
Adress = model.Adress;
|
||||||
OpeningDate = model.OpeningDate;
|
OpeningDate = model.OpeningDate;
|
||||||
|
PizzaMaxCount = model.PizzaMaxCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ShopViewModel GetViewModel => new()
|
public ShopViewModel GetViewModel => new()
|
||||||
@@ -49,7 +52,8 @@ namespace PizzeriaListImplement.Models
|
|||||||
ShopName = ShopName,
|
ShopName = ShopName,
|
||||||
Adress = Adress,
|
Adress = Adress,
|
||||||
OpeningDate = OpeningDate,
|
OpeningDate = OpeningDate,
|
||||||
ShopPizzas = ShopPizzas
|
ShopPizzas = ShopPizzas,
|
||||||
|
PizzaMaxCount = PizzaMaxCount,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using PizzeriaBusinessLogic.BusinessLogics;
|
||||||
using PizzeriaContracts.BindingModels;
|
using PizzeriaContracts.BindingModels;
|
||||||
using PizzeriaContracts.BusinessLogicsContracts;
|
using PizzeriaContracts.BusinessLogicsContracts;
|
||||||
|
using PizzeriaContracts.SearchModels;
|
||||||
using PizzeriaContracts.ViewModels;
|
using PizzeriaContracts.ViewModels;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
@@ -56,40 +58,54 @@ namespace PizzeriaView
|
|||||||
|
|
||||||
private void ButtonSave_Click(object sender, EventArgs e)
|
private void ButtonSave_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (comboBoxShop.SelectedValue == null)
|
if (string.IsNullOrEmpty(textBoxCount.Text))
|
||||||
{
|
{
|
||||||
MessageBox.Show("Выберите магазин", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show("Заполните поле Количество", "Ошибка",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (comboBoxPizza.SelectedValue == null)
|
if (comboBoxPizza.SelectedValue == null)
|
||||||
{
|
{
|
||||||
MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show("Выберите пиццу", "Ошибка",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_logger.LogInformation("Создание поставки");
|
if (comboBoxPizza.SelectedValue == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Выберите магазин", "Ошибка",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var operationResult = _logicS.MakeSupply(new SupplyBindingModel
|
int count = Convert.ToInt32(textBoxCount.Text);
|
||||||
|
|
||||||
|
bool res = _logicS.MakeSupply(
|
||||||
|
new ShopSearchModel() { Id = Convert.ToInt32(comboBoxShop.SelectedValue) },
|
||||||
|
_logicP.ReadElement(new() { Id = Convert.ToInt32(comboBoxPizza.SelectedValue) }),
|
||||||
|
count
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!res)
|
||||||
{
|
{
|
||||||
ShopId = Convert.ToInt32(comboBoxShop.SelectedValue),
|
throw new Exception("Ошибка при пополнении. Дополнительная информация в логах");
|
||||||
PizzaId = Convert.ToInt32(comboBoxPizza.SelectedValue),
|
|
||||||
Count = Convert.ToInt32(textBoxCount.Text)
|
|
||||||
});
|
|
||||||
if (!operationResult)
|
|
||||||
{
|
|
||||||
throw new Exception("Ошибка при создании поставки. Дополнительная информация в логах.");
|
|
||||||
}
|
}
|
||||||
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
||||||
|
MessageBox.Show("Пополнение прошло успешно");
|
||||||
DialogResult = DialogResult.OK;
|
DialogResult = DialogResult.OK;
|
||||||
Close();
|
Close();
|
||||||
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception err)
|
||||||
{
|
{
|
||||||
_logger.LogError(ex, "Ошибка создания поставки");
|
MessageBox.Show("Ошибка пополнения");
|
||||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void ButtonCancel_Click(object sender, EventArgs e)
|
private void ButtonCancel_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
DialogResult = DialogResult.Cancel;
|
DialogResult = DialogResult.Cancel;
|
||||||
|
|||||||
18
Pizzeria/PizzeriaView/FormMain.Designer.cs
generated
18
Pizzeria/PizzeriaView/FormMain.Designer.cs
generated
@@ -41,6 +41,7 @@
|
|||||||
this.buttonOrderReady = new System.Windows.Forms.Button();
|
this.buttonOrderReady = new System.Windows.Forms.Button();
|
||||||
this.buttonIssuedOrder = new System.Windows.Forms.Button();
|
this.buttonIssuedOrder = new System.Windows.Forms.Button();
|
||||||
this.buttonRef = new System.Windows.Forms.Button();
|
this.buttonRef = new System.Windows.Forms.Button();
|
||||||
|
this.продажаToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||||
this.menuStrip1.SuspendLayout();
|
this.menuStrip1.SuspendLayout();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
@@ -71,28 +72,29 @@
|
|||||||
// ingridientsToolStripMenuItem
|
// ingridientsToolStripMenuItem
|
||||||
//
|
//
|
||||||
this.ingridientsToolStripMenuItem.Name = "ingridientsToolStripMenuItem";
|
this.ingridientsToolStripMenuItem.Name = "ingridientsToolStripMenuItem";
|
||||||
this.ingridientsToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
this.ingridientsToolStripMenuItem.Size = new System.Drawing.Size(148, 22);
|
||||||
this.ingridientsToolStripMenuItem.Text = "Ингредиенты";
|
this.ingridientsToolStripMenuItem.Text = "Ингредиенты";
|
||||||
this.ingridientsToolStripMenuItem.Click += new System.EventHandler(this.IngridentsToolStripMenuItem_Click);
|
this.ingridientsToolStripMenuItem.Click += new System.EventHandler(this.IngridentsToolStripMenuItem_Click);
|
||||||
//
|
//
|
||||||
// pizzasToolStripMenuItem
|
// pizzasToolStripMenuItem
|
||||||
//
|
//
|
||||||
this.pizzasToolStripMenuItem.Name = "pizzasToolStripMenuItem";
|
this.pizzasToolStripMenuItem.Name = "pizzasToolStripMenuItem";
|
||||||
this.pizzasToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
this.pizzasToolStripMenuItem.Size = new System.Drawing.Size(148, 22);
|
||||||
this.pizzasToolStripMenuItem.Text = "Пиццы";
|
this.pizzasToolStripMenuItem.Text = "Пиццы";
|
||||||
this.pizzasToolStripMenuItem.Click += new System.EventHandler(this.PizzasToolStripMenuItem_Click);
|
this.pizzasToolStripMenuItem.Click += new System.EventHandler(this.PizzasToolStripMenuItem_Click);
|
||||||
//
|
//
|
||||||
// shopsToolStripMenuItem
|
// shopsToolStripMenuItem
|
||||||
//
|
//
|
||||||
this.shopsToolStripMenuItem.Name = "shopsToolStripMenuItem";
|
this.shopsToolStripMenuItem.Name = "shopsToolStripMenuItem";
|
||||||
this.shopsToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
this.shopsToolStripMenuItem.Size = new System.Drawing.Size(148, 22);
|
||||||
this.shopsToolStripMenuItem.Text = "Магазины";
|
this.shopsToolStripMenuItem.Text = "Магазины";
|
||||||
this.shopsToolStripMenuItem.Click += new System.EventHandler(this.shopsToolStripMenuItem_Click);
|
this.shopsToolStripMenuItem.Click += new System.EventHandler(this.shopsToolStripMenuItem_Click);
|
||||||
//
|
//
|
||||||
// operationToolStripMenuItem
|
// operationToolStripMenuItem
|
||||||
//
|
//
|
||||||
this.operationToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
this.operationToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
|
||||||
this.transactionToolStripMenuItem});
|
this.transactionToolStripMenuItem,
|
||||||
|
this.продажаToolStripMenuItem});
|
||||||
this.operationToolStripMenuItem.Name = "operationToolStripMenuItem";
|
this.operationToolStripMenuItem.Name = "operationToolStripMenuItem";
|
||||||
this.operationToolStripMenuItem.Size = new System.Drawing.Size(75, 20);
|
this.operationToolStripMenuItem.Size = new System.Drawing.Size(75, 20);
|
||||||
this.operationToolStripMenuItem.Text = "Операции";
|
this.operationToolStripMenuItem.Text = "Операции";
|
||||||
@@ -173,6 +175,13 @@
|
|||||||
this.buttonRef.UseVisualStyleBackColor = true;
|
this.buttonRef.UseVisualStyleBackColor = true;
|
||||||
this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
|
this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
|
||||||
//
|
//
|
||||||
|
// продажаToolStripMenuItem
|
||||||
|
//
|
||||||
|
this.продажаToolStripMenuItem.Name = "продажаToolStripMenuItem";
|
||||||
|
this.продажаToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
|
||||||
|
this.продажаToolStripMenuItem.Text = "Продажа";
|
||||||
|
this.продажаToolStripMenuItem.Click += new System.EventHandler(this.SellToolStripMenuItem_Click);
|
||||||
|
//
|
||||||
// FormMain
|
// FormMain
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
|
||||||
@@ -213,5 +222,6 @@
|
|||||||
private ToolStripMenuItem shopsToolStripMenuItem;
|
private ToolStripMenuItem shopsToolStripMenuItem;
|
||||||
private ToolStripMenuItem operationToolStripMenuItem;
|
private ToolStripMenuItem operationToolStripMenuItem;
|
||||||
private ToolStripMenuItem transactionToolStripMenuItem;
|
private ToolStripMenuItem transactionToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem продажаToolStripMenuItem;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using PizzeriaContracts.BindingModels;
|
using PizzeriaContracts.BindingModels;
|
||||||
using PizzeriaContracts.BusinessLogicsContracts;
|
using PizzeriaContracts.BusinessLogicsContracts;
|
||||||
|
using PizzeriaDataModels.Enums;
|
||||||
|
|
||||||
namespace PizzeriaView
|
namespace PizzeriaView
|
||||||
{
|
{
|
||||||
@@ -42,6 +43,19 @@ namespace PizzeriaView
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private OrderBindingModel CreateBindingModel(int id, bool isDone = false)
|
||||||
|
{
|
||||||
|
return new OrderBindingModel
|
||||||
|
{
|
||||||
|
Id = id,
|
||||||
|
PizzaId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["PizzaId"].Value),
|
||||||
|
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
|
||||||
|
Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
|
||||||
|
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
|
||||||
|
DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
private void IngridentsToolStripMenuItem_Click(object sender, EventArgs e)
|
private void IngridentsToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var service = Program.ServiceProvider?.GetService(typeof(FormComponents));
|
var service = Program.ServiceProvider?.GetService(typeof(FormComponents));
|
||||||
@@ -75,13 +89,10 @@ namespace PizzeriaView
|
|||||||
if (dataGridView.SelectedRows.Count == 1)
|
if (dataGridView.SelectedRows.Count == 1)
|
||||||
{
|
{
|
||||||
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||||
_logger.LogInformation("Заказ No{id}. Меняется статус на 'В работе'", id);
|
_logger.LogInformation("Заказ №{id}. Меняется статус на 'В работе'", id);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel
|
var operationResult = _orderLogic.TakeOrderInWork(CreateBindingModel(id));
|
||||||
{
|
|
||||||
Id = id
|
|
||||||
});
|
|
||||||
if (!operationResult)
|
if (!operationResult)
|
||||||
{
|
{
|
||||||
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||||
@@ -101,13 +112,10 @@ namespace PizzeriaView
|
|||||||
if (dataGridView.SelectedRows.Count == 1)
|
if (dataGridView.SelectedRows.Count == 1)
|
||||||
{
|
{
|
||||||
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||||
_logger.LogInformation("Заказ No{id}. Меняется статус на 'Готов'", id);
|
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Готов'", id);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var operationResult = _orderLogic.FinishOrder(new OrderBindingModel
|
var operationResult = _orderLogic.FinishOrder(CreateBindingModel(id));
|
||||||
{
|
|
||||||
Id = id
|
|
||||||
});
|
|
||||||
if (!operationResult)
|
if (!operationResult)
|
||||||
{
|
{
|
||||||
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||||
@@ -127,18 +135,15 @@ namespace PizzeriaView
|
|||||||
if (dataGridView.SelectedRows.Count == 1)
|
if (dataGridView.SelectedRows.Count == 1)
|
||||||
{
|
{
|
||||||
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||||
_logger.LogInformation("Заказ No{id}. Меняется статус на 'Выдан'", id);
|
_logger.LogInformation("Заказ №{id}. Меняется статус на 'Выдан'", id);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var operationResult = _orderLogic.DeliveryOrder(new OrderBindingModel
|
var operationResult = _orderLogic.DeliveryOrder(CreateBindingModel(id));
|
||||||
{
|
|
||||||
Id = id
|
|
||||||
});
|
|
||||||
if (!operationResult)
|
if (!operationResult)
|
||||||
{
|
{
|
||||||
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||||
}
|
}
|
||||||
_logger.LogInformation("Заказ No{id} выдан", id);
|
_logger.LogInformation("Заказ №{id} выдан", id);
|
||||||
LoadData();
|
LoadData();
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -171,5 +176,14 @@ namespace PizzeriaView
|
|||||||
form.ShowDialog();
|
form.ShowDialog();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void SellToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormSellPizza));
|
||||||
|
if (service is FormSellPizza form)
|
||||||
|
{
|
||||||
|
form.ShowDialog();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
149
Pizzeria/PizzeriaView/FormPizzas.Designer.cs
generated
149
Pizzeria/PizzeriaView/FormPizzas.Designer.cs
generated
@@ -28,86 +28,103 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
dataGridView = new DataGridView();
|
this.ToolsPanel = new System.Windows.Forms.Panel();
|
||||||
buttonAdd = new Button();
|
this.buttonRef = new System.Windows.Forms.Button();
|
||||||
buttonEdit = new Button();
|
this.buttonDel = new System.Windows.Forms.Button();
|
||||||
buttonDelete = new Button();
|
this.buttonUpd = new System.Windows.Forms.Button();
|
||||||
buttonUpdate = new Button();
|
this.buttonAdd = new System.Windows.Forms.Button();
|
||||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
this.dataGridView = new System.Windows.Forms.DataGridView();
|
||||||
SuspendLayout();
|
this.ToolsPanel.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||||
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
// dataGridView
|
// ToolsPanel
|
||||||
//
|
//
|
||||||
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
this.ToolsPanel.Controls.Add(this.buttonRef);
|
||||||
dataGridView.Location = new Point(29, 28);
|
this.ToolsPanel.Controls.Add(this.buttonDel);
|
||||||
dataGridView.Name = "dataGridView";
|
this.ToolsPanel.Controls.Add(this.buttonUpd);
|
||||||
dataGridView.RowHeadersWidth = 62;
|
this.ToolsPanel.Controls.Add(this.buttonAdd);
|
||||||
dataGridView.RowTemplate.Height = 33;
|
this.ToolsPanel.Location = new System.Drawing.Point(608, 12);
|
||||||
dataGridView.Size = new Size(471, 383);
|
this.ToolsPanel.Name = "ToolsPanel";
|
||||||
dataGridView.TabIndex = 0;
|
this.ToolsPanel.Size = new System.Drawing.Size(180, 426);
|
||||||
|
this.ToolsPanel.TabIndex = 3;
|
||||||
|
//
|
||||||
|
// buttonRef
|
||||||
|
//
|
||||||
|
this.buttonRef.Location = new System.Drawing.Point(31, 206);
|
||||||
|
this.buttonRef.Name = "buttonRef";
|
||||||
|
this.buttonRef.Size = new System.Drawing.Size(126, 36);
|
||||||
|
this.buttonRef.TabIndex = 3;
|
||||||
|
this.buttonRef.Text = "Обновить";
|
||||||
|
this.buttonRef.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonRef.Click += new System.EventHandler(this.ButtonRef_Click);
|
||||||
|
//
|
||||||
|
// buttonDel
|
||||||
|
//
|
||||||
|
this.buttonDel.Location = new System.Drawing.Point(31, 142);
|
||||||
|
this.buttonDel.Name = "buttonDel";
|
||||||
|
this.buttonDel.Size = new System.Drawing.Size(126, 36);
|
||||||
|
this.buttonDel.TabIndex = 2;
|
||||||
|
this.buttonDel.Text = "Удалить";
|
||||||
|
this.buttonDel.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonDel.Click += new System.EventHandler(this.ButtonDel_Click);
|
||||||
|
//
|
||||||
|
// buttonUpd
|
||||||
|
//
|
||||||
|
this.buttonUpd.Location = new System.Drawing.Point(31, 76);
|
||||||
|
this.buttonUpd.Name = "buttonUpd";
|
||||||
|
this.buttonUpd.Size = new System.Drawing.Size(126, 36);
|
||||||
|
this.buttonUpd.TabIndex = 1;
|
||||||
|
this.buttonUpd.Text = "Изменить";
|
||||||
|
this.buttonUpd.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonUpd.Click += new System.EventHandler(this.ButtonUpd_Click);
|
||||||
//
|
//
|
||||||
// buttonAdd
|
// buttonAdd
|
||||||
//
|
//
|
||||||
buttonAdd.Location = new Point(540, 58);
|
this.buttonAdd.Location = new System.Drawing.Point(31, 16);
|
||||||
buttonAdd.Name = "buttonAdd";
|
this.buttonAdd.Name = "buttonAdd";
|
||||||
buttonAdd.Size = new Size(202, 71);
|
this.buttonAdd.Size = new System.Drawing.Size(126, 36);
|
||||||
buttonAdd.TabIndex = 1;
|
this.buttonAdd.TabIndex = 0;
|
||||||
buttonAdd.Text = "Добавить";
|
this.buttonAdd.Text = "Добавить";
|
||||||
buttonAdd.UseVisualStyleBackColor = true;
|
this.buttonAdd.UseVisualStyleBackColor = true;
|
||||||
buttonAdd.Click += buttonAdd_Click;
|
this.buttonAdd.Click += new System.EventHandler(this.ButtonAdd_Click);
|
||||||
//
|
//
|
||||||
// buttonEdit
|
// dataGridView
|
||||||
//
|
//
|
||||||
buttonEdit.Location = new Point(540, 140);
|
this.dataGridView.AllowUserToAddRows = false;
|
||||||
buttonEdit.Name = "buttonEdit";
|
this.dataGridView.AllowUserToDeleteRows = false;
|
||||||
buttonEdit.Size = new Size(202, 71);
|
this.dataGridView.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
buttonEdit.TabIndex = 2;
|
this.dataGridView.Location = new System.Drawing.Point(12, 12);
|
||||||
buttonEdit.Text = "Изменить";
|
this.dataGridView.Name = "dataGridView";
|
||||||
buttonEdit.UseVisualStyleBackColor = true;
|
this.dataGridView.ReadOnly = true;
|
||||||
buttonEdit.Click += buttonEdit_Click;
|
this.dataGridView.RowHeadersWidth = 51;
|
||||||
//
|
this.dataGridView.RowTemplate.Height = 29;
|
||||||
// buttonDelete
|
this.dataGridView.Size = new System.Drawing.Size(590, 426);
|
||||||
//
|
this.dataGridView.TabIndex = 2;
|
||||||
buttonDelete.Location = new Point(540, 231);
|
|
||||||
buttonDelete.Name = "buttonDelete";
|
|
||||||
buttonDelete.Size = new Size(202, 71);
|
|
||||||
buttonDelete.TabIndex = 3;
|
|
||||||
buttonDelete.Text = "Удалить";
|
|
||||||
buttonDelete.UseVisualStyleBackColor = true;
|
|
||||||
buttonDelete.Click += buttonDelete_Click;
|
|
||||||
//
|
|
||||||
// buttonUpdate
|
|
||||||
//
|
|
||||||
buttonUpdate.Location = new Point(540, 328);
|
|
||||||
buttonUpdate.Name = "buttonUpdate";
|
|
||||||
buttonUpdate.Size = new Size(202, 71);
|
|
||||||
buttonUpdate.TabIndex = 4;
|
|
||||||
buttonUpdate.Text = "Обновить";
|
|
||||||
buttonUpdate.UseVisualStyleBackColor = true;
|
|
||||||
buttonUpdate.Click += buttonUpdate_Click;
|
|
||||||
//
|
//
|
||||||
// FormPizzas
|
// FormPizzas
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(10F, 25F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
ClientSize = new Size(800, 450);
|
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||||
Controls.Add(buttonUpdate);
|
this.Controls.Add(this.ToolsPanel);
|
||||||
Controls.Add(buttonDelete);
|
this.Controls.Add(this.dataGridView);
|
||||||
Controls.Add(buttonEdit);
|
this.Name = "FormPizzas";
|
||||||
Controls.Add(buttonAdd);
|
this.Text = "Пицца";
|
||||||
Controls.Add(dataGridView);
|
this.Load += new System.EventHandler(this.FormPizza_Load);
|
||||||
Name = "FormPizzas";
|
this.ToolsPanel.ResumeLayout(false);
|
||||||
Text = "Пицца";
|
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
||||||
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
this.ResumeLayout(false);
|
||||||
ResumeLayout(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private DataGridView dataGridView;
|
private Panel ToolsPanel;
|
||||||
|
private Button buttonRef;
|
||||||
|
private Button buttonDel;
|
||||||
|
private Button buttonUpd;
|
||||||
private Button buttonAdd;
|
private Button buttonAdd;
|
||||||
private Button buttonEdit;
|
private DataGridView dataGridView;
|
||||||
private Button buttonDelete;
|
|
||||||
private Button buttonUpdate;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,15 +1,7 @@
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using PizzeriaView;
|
||||||
using PizzeriaContracts.BindingModels;
|
using PizzeriaContracts.BindingModels;
|
||||||
using PizzeriaContracts.BusinessLogicsContracts;
|
using PizzeriaContracts.BusinessLogicsContracts;
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Data;
|
|
||||||
using System.Drawing;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using System.Windows.Forms;
|
|
||||||
|
|
||||||
namespace PizzeriaView
|
namespace PizzeriaView
|
||||||
{
|
{
|
||||||
@@ -25,6 +17,11 @@ namespace PizzeriaView
|
|||||||
_logic = logic;
|
_logic = logic;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void FormPizza_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
|
||||||
private void LoadData()
|
private void LoadData()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
@@ -46,7 +43,8 @@ namespace PizzeriaView
|
|||||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void buttonAdd_Click(object sender, EventArgs e)
|
|
||||||
|
private void ButtonAdd_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
var service = Program.ServiceProvider?.GetService(typeof(FormPizza));
|
var service = Program.ServiceProvider?.GetService(typeof(FormPizza));
|
||||||
if (service is FormPizza form)
|
if (service is FormPizza form)
|
||||||
@@ -57,9 +55,9 @@ namespace PizzeriaView
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void buttonEdit_Click(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
|
|
||||||
|
private void ButtonUpd_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
if (dataGridView.SelectedRows.Count == 1)
|
if (dataGridView.SelectedRows.Count == 1)
|
||||||
{
|
{
|
||||||
var service = Program.ServiceProvider?.GetService(typeof(FormPizza));
|
var service = Program.ServiceProvider?.GetService(typeof(FormPizza));
|
||||||
@@ -72,10 +70,9 @@ namespace PizzeriaView
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buttonDelete_Click(object sender, EventArgs e)
|
private void ButtonDel_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (dataGridView.SelectedRows.Count == 1)
|
if (dataGridView.SelectedRows.Count == 1)
|
||||||
{
|
{
|
||||||
@@ -103,7 +100,7 @@ namespace PizzeriaView
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buttonUpdate_Click(object sender, EventArgs e)
|
private void ButtonRef_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
LoadData();
|
LoadData();
|
||||||
}
|
}
|
||||||
|
|||||||
120
Pizzeria/PizzeriaView/FormSellPizza.Designer.cs
generated
Normal file
120
Pizzeria/PizzeriaView/FormSellPizza.Designer.cs
generated
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
namespace PizzeriaView
|
||||||
|
{
|
||||||
|
partial class FormSellPizza
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
this.labelPizza = new System.Windows.Forms.Label();
|
||||||
|
this.comboBoxPizza = new System.Windows.Forms.ComboBox();
|
||||||
|
this.labelCount = new System.Windows.Forms.Label();
|
||||||
|
this.textBoxCount = new System.Windows.Forms.TextBox();
|
||||||
|
this.buttonSell = new System.Windows.Forms.Button();
|
||||||
|
this.buttonCancel = new System.Windows.Forms.Button();
|
||||||
|
this.SuspendLayout();
|
||||||
|
//
|
||||||
|
// labelPizza
|
||||||
|
//
|
||||||
|
this.labelPizza.AutoSize = true;
|
||||||
|
this.labelPizza.Location = new System.Drawing.Point(12, 14);
|
||||||
|
this.labelPizza.Name = "labelPizza";
|
||||||
|
this.labelPizza.Size = new System.Drawing.Size(75, 20);
|
||||||
|
this.labelPizza.TabIndex = 0;
|
||||||
|
this.labelPizza.Text = "Пицца: ";
|
||||||
|
//
|
||||||
|
// comboBoxPizza
|
||||||
|
//
|
||||||
|
this.comboBoxPizza.FormattingEnabled = true;
|
||||||
|
this.comboBoxPizza.Location = new System.Drawing.Point(115, 11);
|
||||||
|
this.comboBoxPizza.Name = "comboBoxPizza";
|
||||||
|
this.comboBoxPizza.Size = new System.Drawing.Size(239, 28);
|
||||||
|
this.comboBoxPizza.TabIndex = 1;
|
||||||
|
//
|
||||||
|
// labelCount
|
||||||
|
//
|
||||||
|
this.labelCount.AutoSize = true;
|
||||||
|
this.labelCount.Location = new System.Drawing.Point(12, 55);
|
||||||
|
this.labelCount.Name = "labelCount";
|
||||||
|
this.labelCount.Size = new System.Drawing.Size(97, 20);
|
||||||
|
this.labelCount.TabIndex = 2;
|
||||||
|
this.labelCount.Text = "Количество: ";
|
||||||
|
//
|
||||||
|
// textBoxCount
|
||||||
|
//
|
||||||
|
this.textBoxCount.Location = new System.Drawing.Point(115, 52);
|
||||||
|
this.textBoxCount.Name = "textBoxCount";
|
||||||
|
this.textBoxCount.Size = new System.Drawing.Size(239, 27);
|
||||||
|
this.textBoxCount.TabIndex = 3;
|
||||||
|
//
|
||||||
|
// buttonSell
|
||||||
|
//
|
||||||
|
this.buttonSell.Location = new System.Drawing.Point(128, 99);
|
||||||
|
this.buttonSell.Name = "buttonSell";
|
||||||
|
this.buttonSell.Size = new System.Drawing.Size(94, 29);
|
||||||
|
this.buttonSell.TabIndex = 4;
|
||||||
|
this.buttonSell.Text = "Продать";
|
||||||
|
this.buttonSell.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonSell.Click += new System.EventHandler(this.ButtonSell_Click);
|
||||||
|
//
|
||||||
|
// buttonCancel
|
||||||
|
//
|
||||||
|
this.buttonCancel.Location = new System.Drawing.Point(242, 99);
|
||||||
|
this.buttonCancel.Name = "buttonCancel";
|
||||||
|
this.buttonCancel.Size = new System.Drawing.Size(94, 29);
|
||||||
|
this.buttonCancel.TabIndex = 5;
|
||||||
|
this.buttonCancel.Text = "Отмена";
|
||||||
|
this.buttonCancel.UseVisualStyleBackColor = true;
|
||||||
|
this.buttonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
|
||||||
|
//
|
||||||
|
// FormSellPizza
|
||||||
|
//
|
||||||
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||||
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
|
this.ClientSize = new System.Drawing.Size(366, 140);
|
||||||
|
this.Controls.Add(this.buttonCancel);
|
||||||
|
this.Controls.Add(this.buttonSell);
|
||||||
|
this.Controls.Add(this.textBoxCount);
|
||||||
|
this.Controls.Add(this.labelCount);
|
||||||
|
this.Controls.Add(this.comboBoxPizza);
|
||||||
|
this.Controls.Add(this.labelPizza);
|
||||||
|
this.Name = "FormSellPizza";
|
||||||
|
this.Text = "Продажа пиццы";
|
||||||
|
this.Load += new System.EventHandler(this.FormSellingPizza_Load);
|
||||||
|
this.ResumeLayout(false);
|
||||||
|
this.PerformLayout();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private Label labelPizza;
|
||||||
|
private ComboBox comboBoxPizza;
|
||||||
|
private Label labelCount;
|
||||||
|
private TextBox textBoxCount;
|
||||||
|
private Button buttonSell;
|
||||||
|
private Button buttonCancel;
|
||||||
|
}
|
||||||
|
}
|
||||||
94
Pizzeria/PizzeriaView/FormSellPizza.cs
Normal file
94
Pizzeria/PizzeriaView/FormSellPizza.cs
Normal file
@@ -0,0 +1,94 @@
|
|||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using PizzeriaBusinessLogic.BusinessLogics;
|
||||||
|
using PizzeriaContracts.BusinessLogicsContracts;
|
||||||
|
using PizzeriaContracts.SearchModels;
|
||||||
|
using PizzeriaContracts.StoragesContracts;
|
||||||
|
using PizzeriaContracts.ViewModels;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
|
using System.Data;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
|
||||||
|
namespace PizzeriaView
|
||||||
|
{
|
||||||
|
public partial class FormSellPizza : Form
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IPizzaLogic _logicP;
|
||||||
|
private readonly IShopLogic _logicS;
|
||||||
|
private List<PizzaViewModel> _pizzaList = new List<PizzaViewModel>();
|
||||||
|
|
||||||
|
public FormSellPizza(ILogger<FormSellPizza> logger, IPizzaLogic logicP, IShopLogic logicS)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
|
_logicP = logicP;
|
||||||
|
_logicS = logicS;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FormSellingPizza_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
_pizzaList = _logicP.ReadList(null);
|
||||||
|
if (_pizzaList != null)
|
||||||
|
{
|
||||||
|
comboBoxPizza.DisplayMember = "PizzaName";
|
||||||
|
comboBoxPizza.ValueMember = "Id";
|
||||||
|
comboBoxPizza.DataSource = _pizzaList;
|
||||||
|
comboBoxPizza.SelectedItem = null;
|
||||||
|
_logger.LogInformation("Загрузка пиццы для продажи");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonSell_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(textBoxCount.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Заполните поле Количество", "Ошибка",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (comboBoxPizza.SelectedValue == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Выберите пиццу", "Ошибка",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int count = Convert.ToInt32(textBoxCount.Text);
|
||||||
|
var computer = _logicP.ReadElement(new() { Id = Convert.ToInt32(comboBoxPizza.SelectedValue) });
|
||||||
|
if (computer == null)
|
||||||
|
return;
|
||||||
|
bool res = _logicS.MakeSell(computer, count);
|
||||||
|
|
||||||
|
if (!res)
|
||||||
|
{
|
||||||
|
throw new Exception("Ошибка при продаже.");
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageBox.Show("Продажа прошла успешно");
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
Close();
|
||||||
|
|
||||||
|
}
|
||||||
|
catch (Exception err)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Ошибка продажи");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonCancel_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
DialogResult = DialogResult.Cancel;
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
33
Pizzeria/PizzeriaView/FormShop.Designer.cs
generated
33
Pizzeria/PizzeriaView/FormShop.Designer.cs
generated
@@ -40,7 +40,10 @@
|
|||||||
this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn();
|
||||||
this.label1 = new System.Windows.Forms.Label();
|
this.label1 = new System.Windows.Forms.Label();
|
||||||
this.dateTimeOpen = new System.Windows.Forms.DateTimePicker();
|
this.dateTimeOpen = new System.Windows.Forms.DateTimePicker();
|
||||||
|
this.label2 = new System.Windows.Forms.Label();
|
||||||
|
this.numericUpPizzaMaxCount = new System.Windows.Forms.NumericUpDown();
|
||||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.numericUpPizzaMaxCount)).BeginInit();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
// labelName
|
// labelName
|
||||||
@@ -105,13 +108,13 @@
|
|||||||
this.id,
|
this.id,
|
||||||
this.PizzaName,
|
this.PizzaName,
|
||||||
this.Count});
|
this.Count});
|
||||||
this.dataGridView.Location = new System.Drawing.Point(12, 144);
|
this.dataGridView.Location = new System.Drawing.Point(12, 185);
|
||||||
this.dataGridView.Name = "dataGridView";
|
this.dataGridView.Name = "dataGridView";
|
||||||
this.dataGridView.ReadOnly = true;
|
this.dataGridView.ReadOnly = true;
|
||||||
this.dataGridView.RowHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.None;
|
this.dataGridView.RowHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.None;
|
||||||
this.dataGridView.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.AutoSizeToDisplayedHeaders;
|
this.dataGridView.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.AutoSizeToDisplayedHeaders;
|
||||||
this.dataGridView.RowTemplate.Height = 29;
|
this.dataGridView.RowTemplate.Height = 29;
|
||||||
this.dataGridView.Size = new System.Drawing.Size(569, 307);
|
this.dataGridView.Size = new System.Drawing.Size(569, 266);
|
||||||
this.dataGridView.TabIndex = 7;
|
this.dataGridView.TabIndex = 7;
|
||||||
//
|
//
|
||||||
// id
|
// id
|
||||||
@@ -152,11 +155,34 @@
|
|||||||
this.dateTimeOpen.Size = new System.Drawing.Size(401, 27);
|
this.dateTimeOpen.Size = new System.Drawing.Size(401, 27);
|
||||||
this.dateTimeOpen.TabIndex = 9;
|
this.dateTimeOpen.TabIndex = 9;
|
||||||
//
|
//
|
||||||
|
// label2
|
||||||
|
//
|
||||||
|
this.label2.AutoSize = true;
|
||||||
|
this.label2.Location = new System.Drawing.Point(12, 148);
|
||||||
|
this.label2.Name = "label2";
|
||||||
|
this.label2.Size = new System.Drawing.Size(100, 20);
|
||||||
|
this.label2.TabIndex = 10;
|
||||||
|
this.label2.Text = "Вместимость";
|
||||||
|
//
|
||||||
|
// numericUpPizzaMaxCount
|
||||||
|
//
|
||||||
|
this.numericUpPizzaMaxCount.Location = new System.Drawing.Point(128, 146);
|
||||||
|
this.numericUpPizzaMaxCount.Maximum = new decimal(new int[] {
|
||||||
|
10000,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0});
|
||||||
|
this.numericUpPizzaMaxCount.Name = "numericUpPizzaMaxCount";
|
||||||
|
this.numericUpPizzaMaxCount.Size = new System.Drawing.Size(401, 27);
|
||||||
|
this.numericUpPizzaMaxCount.TabIndex = 11;
|
||||||
|
//
|
||||||
// FormShop
|
// FormShop
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
|
||||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||||
this.ClientSize = new System.Drawing.Size(593, 513);
|
this.ClientSize = new System.Drawing.Size(593, 513);
|
||||||
|
this.Controls.Add(this.numericUpPizzaMaxCount);
|
||||||
|
this.Controls.Add(this.label2);
|
||||||
this.Controls.Add(this.dateTimeOpen);
|
this.Controls.Add(this.dateTimeOpen);
|
||||||
this.Controls.Add(this.label1);
|
this.Controls.Add(this.label1);
|
||||||
this.Controls.Add(this.dataGridView);
|
this.Controls.Add(this.dataGridView);
|
||||||
@@ -170,6 +196,7 @@
|
|||||||
this.Text = "Магазин";
|
this.Text = "Магазин";
|
||||||
this.Load += new System.EventHandler(this.FormShop_Load);
|
this.Load += new System.EventHandler(this.FormShop_Load);
|
||||||
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.numericUpPizzaMaxCount)).EndInit();
|
||||||
this.ResumeLayout(false);
|
this.ResumeLayout(false);
|
||||||
this.PerformLayout();
|
this.PerformLayout();
|
||||||
|
|
||||||
@@ -189,5 +216,7 @@
|
|||||||
private DataGridViewTextBoxColumn Count;
|
private DataGridViewTextBoxColumn Count;
|
||||||
private Label label1;
|
private Label label1;
|
||||||
private DateTimePicker dateTimeOpen;
|
private DateTimePicker dateTimeOpen;
|
||||||
|
private Label label2;
|
||||||
|
private NumericUpDown numericUpPizzaMaxCount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -23,7 +23,6 @@ namespace PizzeriaView
|
|||||||
public int Id { set { _id = value; } }
|
public int Id { set { _id = value; } }
|
||||||
private Dictionary<int, (IPizzaModel, int)> _ShopPizzas;
|
private Dictionary<int, (IPizzaModel, int)> _ShopPizzas;
|
||||||
private DateTime? _openingDate = null;
|
private DateTime? _openingDate = null;
|
||||||
|
|
||||||
public FormShop(ILogger<FormShop> logger, IShopLogic logic)
|
public FormShop(ILogger<FormShop> logger, IShopLogic logic)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@@ -31,7 +30,6 @@ namespace PizzeriaView
|
|||||||
_logic = logic;
|
_logic = logic;
|
||||||
_ShopPizzas = new Dictionary<int, (IPizzaModel, int)>();
|
_ShopPizzas = new Dictionary<int, (IPizzaModel, int)>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FormShop_Load(object sender, EventArgs e)
|
private void FormShop_Load(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (_id.HasValue)
|
if (_id.HasValue)
|
||||||
@@ -48,6 +46,7 @@ namespace PizzeriaView
|
|||||||
textBoxName.Text = view.ShopName;
|
textBoxName.Text = view.ShopName;
|
||||||
textBoxAdress.Text = view.Adress;
|
textBoxAdress.Text = view.Adress;
|
||||||
dateTimeOpen.Value = view.OpeningDate;
|
dateTimeOpen.Value = view.OpeningDate;
|
||||||
|
numericUpPizzaMaxCount.Value = view.PizzaMaxCount;
|
||||||
_ShopPizzas = view.ShopPizzas ?? new Dictionary<int, (IPizzaModel, int)>();
|
_ShopPizzas = view.ShopPizzas ?? new Dictionary<int, (IPizzaModel, int)>();
|
||||||
LoadData();
|
LoadData();
|
||||||
}
|
}
|
||||||
@@ -101,7 +100,8 @@ namespace PizzeriaView
|
|||||||
Id = _id ?? 0,
|
Id = _id ?? 0,
|
||||||
ShopName = textBoxName.Text,
|
ShopName = textBoxName.Text,
|
||||||
Adress = textBoxAdress.Text,
|
Adress = textBoxAdress.Text,
|
||||||
OpeningDate = dateTimeOpen.Value
|
OpeningDate = dateTimeOpen.Value,
|
||||||
|
PizzaMaxCount = (int)numericUpPizzaMaxCount.Value
|
||||||
};
|
};
|
||||||
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
|
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
|
||||||
if (!operationResult)
|
if (!operationResult)
|
||||||
@@ -118,7 +118,6 @@ namespace PizzeriaView
|
|||||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buttonCancel_Click(object sender, EventArgs e)
|
private void buttonCancel_Click(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
DialogResult = DialogResult.Cancel;
|
DialogResult = DialogResult.Cancel;
|
||||||
|
|||||||
@@ -19,6 +19,10 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.0">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
|
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="8.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
|
||||||
<PackageReference Include="NLog" Version="5.2.8" />
|
<PackageReference Include="NLog" Version="5.2.8" />
|
||||||
@@ -28,7 +32,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\PizzeriaBusinessLogic\PizzeriaBusinessLogic.csproj" />
|
<ProjectReference Include="..\PizzeriaBusinessLogic\PizzeriaBusinessLogic.csproj" />
|
||||||
<ProjectReference Include="..\PizzeriaContracts\PizzeriaContracts.csproj" />
|
<ProjectReference Include="..\PizzeriaContracts\PizzeriaContracts.csproj" />
|
||||||
<ProjectReference Include="..\PizzeriaDataModels\PizzeriaDataModels.csproj" />
|
<ProjectReference Include="..\PizzeriaDatabaseImplement\PizzeriaDatabaseImplement.csproj" />
|
||||||
<ProjectReference Include="..\PizzeriaListImplement\PizzeriaListImplement.csproj" />
|
<ProjectReference Include="..\PizzeriaListImplement\PizzeriaListImplement.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ using NLog.Extensions.Logging;
|
|||||||
using PizzeriaBusinessLogic.BusinessLogics;
|
using PizzeriaBusinessLogic.BusinessLogics;
|
||||||
using PizzeriaContracts.BusinessLogicsContracts;
|
using PizzeriaContracts.BusinessLogicsContracts;
|
||||||
using PizzeriaContracts.StoragesContracts;
|
using PizzeriaContracts.StoragesContracts;
|
||||||
using PizzeriaListImplement.Implements;
|
using PizzeriaDatabaseImplement.Implements;
|
||||||
using System;
|
|
||||||
|
|
||||||
namespace PizzeriaView
|
namespace PizzeriaView
|
||||||
{
|
{
|
||||||
@@ -49,11 +49,6 @@ namespace PizzeriaView
|
|||||||
services.AddTransient<FormPizza>();
|
services.AddTransient<FormPizza>();
|
||||||
services.AddTransient<FormPizzaComponent>();
|
services.AddTransient<FormPizzaComponent>();
|
||||||
services.AddTransient<FormPizzas>();
|
services.AddTransient<FormPizzas>();
|
||||||
services.AddTransient<IShopStorage, ShopStorage>();
|
|
||||||
services.AddTransient<IShopLogic, ShopLogic>();
|
|
||||||
services.AddTransient<FormShop>();
|
|
||||||
services.AddTransient<FormShops>();
|
|
||||||
services.AddTransient<FormCreateSupply>();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user