end lab1
This commit is contained in:
parent
10698313a9
commit
8eee668ae4
4
Pizzeria/Pizzeria/FormComponent.Designer.cs
generated
4
Pizzeria/Pizzeria/FormComponent.Designer.cs
generated
@ -70,6 +70,7 @@
|
||||
//
|
||||
// buttonSave
|
||||
//
|
||||
buttonSave.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonSave.Location = new Point(177, 93);
|
||||
buttonSave.Name = "buttonSave";
|
||||
buttonSave.Size = new Size(75, 23);
|
||||
@ -80,6 +81,7 @@
|
||||
//
|
||||
// buttonCancel
|
||||
//
|
||||
buttonCancel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonCancel.Location = new Point(258, 93);
|
||||
buttonCancel.Name = "buttonCancel";
|
||||
buttonCancel.Size = new Size(75, 23);
|
||||
@ -100,7 +102,7 @@
|
||||
Controls.Add(labelPrice);
|
||||
Controls.Add(labelName);
|
||||
Name = "FormComponent";
|
||||
Text = "Компонент";
|
||||
Text = "Ингредиент";
|
||||
Load += FormComponent_Load;
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
|
@ -27,11 +27,10 @@ namespace Pizzeria
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger.LogInformation("Получение компонента");
|
||||
_logger.LogInformation("Получение ингредиента");
|
||||
var view = _logic.ReadElement(new ComponentSearchModel
|
||||
{
|
||||
Id =
|
||||
_id.Value
|
||||
Id =_id.Value
|
||||
});
|
||||
if (view != null)
|
||||
{
|
||||
@ -41,9 +40,8 @@ namespace Pizzeria
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения компонента");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Error);
|
||||
_logger.LogError(ex, "Ошибка получения ингредиента");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
@ -53,11 +51,10 @@ namespace Pizzeria
|
||||
{
|
||||
if (string.IsNullOrEmpty(textBoxName.Text))
|
||||
{
|
||||
MessageBox.Show("Заполните название", "Ошибка",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
MessageBox.Show("Заполните название", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
return;
|
||||
}
|
||||
_logger.LogInformation("Сохранение компонента");
|
||||
_logger.LogInformation("Сохранение ингредиента");
|
||||
try
|
||||
{
|
||||
var model = new ComponentBindingModel
|
||||
@ -66,22 +63,19 @@ namespace Pizzeria
|
||||
ComponentName = textBoxName.Text,
|
||||
Cost = Convert.ToDouble(textBoxCost.Text)
|
||||
};
|
||||
var operationResult = _id.HasValue ? _logic.Update(model) :
|
||||
_logic.Create(model);
|
||||
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
|
||||
if (!operationResult)
|
||||
{
|
||||
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||
}
|
||||
MessageBox.Show("Сохранение прошло успешно", "Сообщение",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка сохранения компонента");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Error);
|
||||
_logger.LogError(ex, "Ошибка сохранения ингредиента");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
|
72
Pizzeria/Pizzeria/FormComponents.Designer.cs
generated
72
Pizzeria/Pizzeria/FormComponents.Designer.cs
generated
@ -30,9 +30,9 @@
|
||||
{
|
||||
dataGridView = new DataGridView();
|
||||
ButtonAdd = new Button();
|
||||
ButtonRef = new Button();
|
||||
ButtonDel = new Button();
|
||||
ButtonUpd = new Button();
|
||||
ButtonDel = new Button();
|
||||
ButtonRef = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
@ -41,6 +41,7 @@
|
||||
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||
dataGridView.Dock = DockStyle.Left;
|
||||
dataGridView.Location = new Point(0, 0);
|
||||
dataGridView.Margin = new Padding(3, 2, 3, 2);
|
||||
dataGridView.MultiSelect = false;
|
||||
dataGridView.Name = "dataGridView";
|
||||
dataGridView.ReadOnly = true;
|
||||
@ -48,62 +49,71 @@
|
||||
dataGridView.RowHeadersWidth = 51;
|
||||
dataGridView.RowTemplate.Height = 29;
|
||||
dataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
|
||||
dataGridView.Size = new Size(628, 450);
|
||||
dataGridView.Size = new Size(550, 338);
|
||||
dataGridView.TabIndex = 0;
|
||||
//
|
||||
// ButtonAdd
|
||||
//
|
||||
ButtonAdd.Location = new Point(671, 47);
|
||||
ButtonAdd.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
ButtonAdd.Location = new Point(587, 35);
|
||||
ButtonAdd.Margin = new Padding(3, 2, 3, 2);
|
||||
ButtonAdd.Name = "ButtonAdd";
|
||||
ButtonAdd.Size = new Size(94, 29);
|
||||
ButtonAdd.Size = new Size(82, 22);
|
||||
ButtonAdd.TabIndex = 1;
|
||||
ButtonAdd.Text = "Добавить";
|
||||
ButtonAdd.UseVisualStyleBackColor = true;
|
||||
ButtonAdd.Click += ButtonAdd_Click;
|
||||
//
|
||||
// ButtonRef
|
||||
// ButtonUpd
|
||||
//
|
||||
ButtonRef.Location = new Point(671, 94);
|
||||
ButtonRef.Name = "ButtonRef";
|
||||
ButtonRef.Size = new Size(94, 29);
|
||||
ButtonRef.TabIndex = 2;
|
||||
ButtonRef.Text = "Изменить";
|
||||
ButtonRef.UseVisualStyleBackColor = true;
|
||||
ButtonRef.Click += ButtonRef_Click;
|
||||
ButtonUpd.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
ButtonUpd.Location = new Point(587, 70);
|
||||
ButtonUpd.Margin = new Padding(3, 2, 3, 2);
|
||||
ButtonUpd.Name = "ButtonUpd";
|
||||
ButtonUpd.Size = new Size(82, 22);
|
||||
ButtonUpd.TabIndex = 2;
|
||||
ButtonUpd.Text = "Изменить";
|
||||
ButtonUpd.UseVisualStyleBackColor = true;
|
||||
ButtonUpd.Click += ButtonUpd_Click;
|
||||
//
|
||||
// ButtonDel
|
||||
//
|
||||
ButtonDel.Location = new Point(671, 144);
|
||||
ButtonDel.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
ButtonDel.Location = new Point(587, 108);
|
||||
ButtonDel.Margin = new Padding(3, 2, 3, 2);
|
||||
ButtonDel.Name = "ButtonDel";
|
||||
ButtonDel.Size = new Size(94, 29);
|
||||
ButtonDel.Size = new Size(82, 22);
|
||||
ButtonDel.TabIndex = 3;
|
||||
ButtonDel.Text = "Удалить";
|
||||
ButtonDel.UseVisualStyleBackColor = true;
|
||||
ButtonDel.Click += ButtonDel_Click;
|
||||
//
|
||||
// ButtonUpd
|
||||
// ButtonRef
|
||||
//
|
||||
ButtonUpd.Location = new Point(671, 191);
|
||||
ButtonUpd.Name = "ButtonUpd";
|
||||
ButtonUpd.Size = new Size(94, 29);
|
||||
ButtonUpd.TabIndex = 4;
|
||||
ButtonUpd.Text = "Обновить";
|
||||
ButtonUpd.UseVisualStyleBackColor = true;
|
||||
ButtonUpd.Click += ButtonUpd_Click;
|
||||
ButtonRef.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
ButtonRef.Location = new Point(587, 143);
|
||||
ButtonRef.Margin = new Padding(3, 2, 3, 2);
|
||||
ButtonRef.Name = "ButtonRef";
|
||||
ButtonRef.Size = new Size(82, 22);
|
||||
ButtonRef.TabIndex = 4;
|
||||
ButtonRef.Text = "Обновить";
|
||||
ButtonRef.UseVisualStyleBackColor = true;
|
||||
ButtonRef.Click += ButtonRef_Click;
|
||||
//
|
||||
// FormComponents
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 450);
|
||||
Controls.Add(ButtonUpd);
|
||||
Controls.Add(ButtonDel);
|
||||
ClientSize = new Size(700, 338);
|
||||
Controls.Add(ButtonRef);
|
||||
Controls.Add(ButtonDel);
|
||||
Controls.Add(ButtonUpd);
|
||||
Controls.Add(ButtonAdd);
|
||||
Controls.Add(dataGridView);
|
||||
Margin = new Padding(3, 2, 3, 2);
|
||||
Name = "FormComponents";
|
||||
Text = "Компоненты";
|
||||
Load += FormComponent_Load;
|
||||
Text = "Ингредиенты";
|
||||
Load += FormComponents_Load;
|
||||
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
@ -112,8 +122,8 @@
|
||||
|
||||
private DataGridView dataGridView;
|
||||
private Button ButtonAdd;
|
||||
private Button ButtonRef;
|
||||
private Button ButtonDel;
|
||||
private Button ButtonUpd;
|
||||
private Button ButtonDel;
|
||||
private Button ButtonRef;
|
||||
}
|
||||
}
|
@ -1,8 +1,6 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.VisualBasic.Logging;
|
||||
using PizzeriaContracts.BindingModels;
|
||||
using PizzeriaContracts.BusinessLogicsContracts;
|
||||
|
||||
namespace Pizzeria
|
||||
{
|
||||
public partial class FormComponents : Form
|
||||
@ -16,7 +14,7 @@ namespace Pizzeria
|
||||
_logic = logic;
|
||||
}
|
||||
|
||||
private void FormComponent_Load(object sender, EventArgs e)
|
||||
private void FormComponents_Load(object sender, EventArgs e)
|
||||
{
|
||||
LoadData();
|
||||
}
|
||||
@ -31,11 +29,11 @@ namespace Pizzeria
|
||||
dataGridView.Columns["Id"].Visible = false;
|
||||
dataGridView.Columns["ComponentName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||
}
|
||||
_logger.LogInformation("Загрузка компонентов");
|
||||
_logger.LogInformation("Загрузка ингредиентов");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка загрузки компонентов");
|
||||
_logger.LogError(ex, "Ошибка загрузки ингредиентов");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
@ -62,12 +60,10 @@ namespace Pizzeria
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
if (MessageBox.Show("Удалить запись?", "Вопрос",
|
||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
if (MessageBox.Show("Удалить запись?", "Вопрос", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||
{
|
||||
int id =
|
||||
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
_logger.LogInformation("Удаление компонента");
|
||||
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
_logger.LogInformation("Удаление ингредиента");
|
||||
try
|
||||
{
|
||||
if (!_logic.Delete(new ComponentBindingModel
|
||||
@ -81,9 +77,8 @@ namespace Pizzeria
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка удаления компонента");
|
||||
MessageBox.Show(ex.Message, "Ошибка",
|
||||
MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
_logger.LogError(ex, "Ошибка удаления ингредиента");
|
||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -94,12 +89,10 @@ namespace Pizzeria
|
||||
{
|
||||
if (dataGridView.SelectedRows.Count == 1)
|
||||
{
|
||||
var service =
|
||||
Program.ServiceProvider?.GetService(typeof(FormComponent));
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormComponent));
|
||||
if (service is FormComponent form)
|
||||
{
|
||||
form.Id =
|
||||
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
form.Id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
LoadData();
|
||||
|
@ -20,15 +20,12 @@ namespace Pizzeria
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
/*/ To customize application configuration such as set high DPI
|
||||
settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
|
||||
ApplicationConfiguration.Initialize();
|
||||
var services = new ServiceCollection();
|
||||
ConfigureServices(services);
|
||||
_serviceProvider = services.BuildServiceProvider();
|
||||
Application.Run(_serviceProvider.GetRequiredService<FormMain>());
|
||||
*/
|
||||
}
|
||||
private static void ConfigureServices(ServiceCollection services)
|
||||
{
|
||||
@ -39,17 +36,17 @@ namespace Pizzeria
|
||||
});
|
||||
services.AddTransient<IComponentStorage, ComponentStorage>();
|
||||
services.AddTransient<IOrderStorage, OrderStorage>();
|
||||
services.AddTransient<IProductStorage, ProductStorage>();
|
||||
services.AddTransient<IPizzaStorage, PizzaStorage>();
|
||||
services.AddTransient<IComponentLogic, ComponentLogic>();
|
||||
services.AddTransient<IOrderLogic, OrderLogic>();
|
||||
services.AddTransient<IProductLogic, ProductLogic>();
|
||||
services.AddTransient<IPizzaLogic, PizzaLogic>();
|
||||
services.AddTransient<FormMain>();
|
||||
services.AddTransient<FormComponent>();
|
||||
services.AddTransient<FormComponents>();
|
||||
services.AddTransient<FormCreateOrder>();
|
||||
services.AddTransient<FormProduct>();
|
||||
services.AddTransient<FormProductComponent>();
|
||||
services.AddTransient<FormProducts>();
|
||||
services.AddTransient<FormPizza>();
|
||||
services.AddTransient<FormPizzaComponent>();
|
||||
services.AddTransient<FormPizzas>();
|
||||
}
|
||||
}
|
||||
}
|
@ -13,9 +13,10 @@ namespace PizzeriaBusinessLogic.BusinessLogic
|
||||
private readonly IComponentStorage _componentStorage;
|
||||
public ComponentLogic(ILogger<ComponentLogic> logger, IComponentStorage componentStorage)
|
||||
{
|
||||
//_logger = logger;
|
||||
_logger = logger;
|
||||
_componentStorage = componentStorage;
|
||||
}
|
||||
|
||||
public List<ComponentViewModel>? ReadList(ComponentSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. ComponentName:{ComponentName}.Id:{ Id}", model?.ComponentName, model?.Id);
|
||||
@ -88,17 +89,17 @@ namespace PizzeriaBusinessLogic.BusinessLogic
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.ComponentName))
|
||||
{
|
||||
throw new ArgumentNullException("Нет названия компонента", nameof(model.ComponentName));
|
||||
throw new ArgumentNullException("Нет названия ингредиента", nameof(model.ComponentName));
|
||||
}
|
||||
if (model.Cost <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Цена компонента должна быть больше 0", nameof(model.Cost));
|
||||
throw new ArgumentNullException("Цена ингредиента должна быть больше 0", nameof(model.Cost));
|
||||
}
|
||||
_logger.LogInformation("Component. ComponentName:{ComponentName}.Cost:{ Cost}. Id: { Id}", model.ComponentName, model.Cost, model.Id);
|
||||
var element = _componentStorage.GetElement(new ComponentSearchModel{ ComponentName = model.ComponentName });
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Компонент с таким названием уже есть");
|
||||
throw new InvalidOperationException("ингредиент с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,8 +4,7 @@ using PizzeriaContracts.BusinessLogicsContracts;
|
||||
using PizzeriaContracts.SearchModels;
|
||||
using PizzeriaContracts.StorageContracts;
|
||||
using PizzeriaContracts.ViewModels;
|
||||
using PizzeriaDataModels.Enums;
|
||||
using System.Xml.Linq;
|
||||
using PizzeriaDataModels.Enums;
|
||||
|
||||
namespace PizzeriaBusinessLogic.BusinessLogic
|
||||
{
|
||||
@ -20,15 +19,15 @@ namespace PizzeriaBusinessLogic.BusinessLogic
|
||||
_logger = logger;
|
||||
_orderStorage = orderStorage;
|
||||
}
|
||||
|
||||
|
||||
public bool CreateOrder(OrderBindingModel model)
|
||||
{
|
||||
|
||||
CheckModel(model);
|
||||
|
||||
if (model.Status == OrderStatus.Неизвестен)
|
||||
if (model.Status != OrderStatus.Неизвестен)
|
||||
{
|
||||
_logger.LogWarning("Order status unknown");
|
||||
_logger.LogWarning("Invalid order status");
|
||||
return false;
|
||||
}
|
||||
model.Status = OrderStatus.Принят;
|
||||
@ -39,6 +38,8 @@ namespace PizzeriaBusinessLogic.BusinessLogic
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. OrderId: {Id}.", model?.Id);
|
||||
@ -68,73 +69,44 @@ namespace PizzeriaBusinessLogic.BusinessLogic
|
||||
}
|
||||
public bool ChangeStatus(OrderBindingModel model, OrderStatus status)
|
||||
{
|
||||
/*Неизвестен = -1,
|
||||
Принят = 0,
|
||||
Выполняется = 1,
|
||||
Готов = 2,
|
||||
Выдан = 3*/
|
||||
|
||||
CheckModel(model, false);
|
||||
|
||||
var order = _orderStorage.GetElement(new OrderSearchModel {
|
||||
Id = model.Id
|
||||
});
|
||||
|
||||
var order = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id });
|
||||
|
||||
if (order == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(order));
|
||||
}
|
||||
|
||||
model.ProductId = order.ProductId;
|
||||
model.PizzaId = order.PizzaId;
|
||||
model.Count = order.Count;
|
||||
model.Sum = order.Count;
|
||||
model.DateCreate = order.DateCreate;
|
||||
model.DateImplement = order.DateImplement;
|
||||
model.Status = order.Status;
|
||||
model.Count = order.Count;
|
||||
model.Sum = order.Sum;
|
||||
return true;
|
||||
/*
|
||||
|
||||
if (model.Status != status - 1)
|
||||
{
|
||||
_logger.LogWarning("Status update to " + status + " operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
model.Status = status;
|
||||
|
||||
if (model.Status == OrderStatus.Выдан)
|
||||
{
|
||||
model.DateImplement = DateTime.Now;
|
||||
}
|
||||
|
||||
if (_orderStorage.Update(model) == null)
|
||||
{
|
||||
model.Status--;
|
||||
_logger.LogWarning("Changing status operation faled");
|
||||
return false;
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
if (model.Status == OrderStatus.Готов)
|
||||
{
|
||||
model.DateImplement = DateTime.Now;
|
||||
}
|
||||
else
|
||||
{
|
||||
model.DateImplement = order.DateImplement;
|
||||
}
|
||||
if (_orderStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Change status operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
*/
|
||||
|
||||
}
|
||||
private void CheckModel(OrderBindingModel model, bool withParams = true)
|
||||
{
|
||||
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
@ -143,22 +115,22 @@ namespace PizzeriaBusinessLogic.BusinessLogic
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (model.ProductId <= 0)
|
||||
if (model.PizzaId <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Некорректный идентификатор изделия", nameof(model.ProductId));
|
||||
throw new ArgumentNullException("Некорректный идентификатор пиццы", nameof(model.PizzaId));
|
||||
}
|
||||
if (model.Count <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("В заказе должно быть хотя бы одно изделие", nameof(model.Count));
|
||||
throw new ArgumentNullException("В заказе должно быть хотя бы одно пицца", nameof(model.Count));
|
||||
}
|
||||
if (model.Sum <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Стоимость заказа должна быть больше 0", nameof(model.Sum));
|
||||
}
|
||||
_logger.LogInformation("Order. Id: {Id}. Sum: {Sum}. ProductId: {ProductId}. ReinforcedCount: {Count}", model.Id, model.Sum, model.ProductId, model.Count);
|
||||
_logger.LogInformation("Order. Id: {Id}. Sum: {Sum}. PizzaId: {PizzaId}. ReinforcedCount: {Count}", model.Id, model.Sum, model.PizzaId, model.Count);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,106 +0,0 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PizzeriaContracts.BindingModels;
|
||||
using PizzeriaContracts.BusinessLogicsContracts;
|
||||
using PizzeriaContracts.SearchModels;
|
||||
using PizzeriaContracts.StorageContracts;
|
||||
using PizzeriaContracts.ViewModels;
|
||||
|
||||
|
||||
namespace PizzeriaBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class ProductLogic : IProductLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IProductStorage _productStorage;
|
||||
public ProductLogic(ILogger<ProductLogic> logger, IProductStorage ProductStorage)
|
||||
{
|
||||
//_logger = logger;
|
||||
_productStorage = ProductStorage;
|
||||
}
|
||||
public List<ProductViewModel>? ReadList(ProductSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. ProductName:{ProductName}.Id:{ Id}", model?.ProductName, model?.Id);
|
||||
var list = model == null ? _productStorage.GetFullList() :
|
||||
_productStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
public ProductViewModel? ReadElement(ProductSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. ProductName:{ProductName}.Id:{ Id} ", model.ProductName, model.Id);
|
||||
var element = _productStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||
return element;
|
||||
}
|
||||
public bool Create(ProductBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_productStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Update(ProductBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_productStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool Delete(ProductBindingModel model)
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||
if (_productStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private void CheckModel(ProductBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.ProductName))
|
||||
{
|
||||
throw new ArgumentNullException("Нет названия продукта", nameof(model.ProductName));
|
||||
}
|
||||
if (model.Price <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Цена продукта должна быть больше 0", nameof(model.Price));
|
||||
}
|
||||
_logger.LogInformation("Product. ProductName:{ProductName}.Price:{ Price}. Id: { Id}", model.ProductName, model.Price, model.Id);
|
||||
var element = _productStorage.GetElement(new ProductSearchModel { ProductName = model.ProductName });
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Продукт с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -6,7 +6,7 @@ namespace PizzeriaContracts.BindingModels
|
||||
public class OrderBindingModel : IOrderModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public int ProductId { get; set; }
|
||||
public int PizzaId { get; set; }
|
||||
public int Count { get; set; }
|
||||
public double Sum { get; set; }
|
||||
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
|
||||
|
@ -1,12 +0,0 @@
|
||||
using PizzeriaDataModels.Models;
|
||||
namespace PizzeriaContracts.BindingModels
|
||||
{
|
||||
public class ProductBindingModel : IProductModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
public string ProductName { get; set; } = string.Empty;
|
||||
public double Price { get; set; }
|
||||
public Dictionary<int, (IComponentModel, int)> ProductComponents {get;set;} = new();
|
||||
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
using PizzeriaContracts.BindingModels;
|
||||
using PizzeriaContracts.SearchModels;
|
||||
using PizzeriaContracts.ViewModels;
|
||||
|
||||
namespace PizzeriaContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IProductLogic
|
||||
{
|
||||
List<ProductViewModel>? ReadList(ProductSearchModel? model);
|
||||
ProductViewModel? ReadElement(ProductSearchModel model);
|
||||
bool Create(ProductBindingModel model);
|
||||
bool Update(ProductBindingModel model);
|
||||
bool Delete(ProductBindingModel model);
|
||||
}
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
namespace PizzeriaContracts.SearchModels
|
||||
{
|
||||
public class ProductSearchModel
|
||||
{
|
||||
public int? Id { get; set; }
|
||||
public string? ProductName { get; set; }
|
||||
}
|
||||
}
|
@ -1,17 +0,0 @@
|
||||
using PizzeriaContracts.BindingModels;
|
||||
using PizzeriaContracts.SearchModels;
|
||||
using PizzeriaContracts.ViewModels;
|
||||
|
||||
namespace PizzeriaContracts.StorageContracts
|
||||
{
|
||||
public interface IProductStorage
|
||||
{
|
||||
List<ProductViewModel> GetFullList();
|
||||
List<ProductViewModel> GetFilteredList(ProductSearchModel model);
|
||||
ProductViewModel? GetElement(ProductSearchModel model);
|
||||
ProductViewModel? Insert(ProductBindingModel model);
|
||||
ProductViewModel? Update(ProductBindingModel model);
|
||||
ProductViewModel? Delete(ProductBindingModel model);
|
||||
|
||||
}
|
||||
}
|
@ -6,7 +6,7 @@ namespace PizzeriaContracts.ViewModels
|
||||
public class ComponentViewModel : IComponentModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[DisplayName("Название компонента")]
|
||||
[DisplayName("Название ингредиента")]
|
||||
public string ComponentName { get; set; } = string.Empty;
|
||||
[DisplayName("Цена")]
|
||||
public double Cost { get; set; }
|
||||
|
@ -8,10 +8,10 @@ namespace PizzeriaContracts.ViewModels
|
||||
{
|
||||
[DisplayName("Номер")]
|
||||
public int Id { get; set; }
|
||||
public int ProductId { get; set; }
|
||||
public int PizzaId { get; set; }
|
||||
|
||||
[DisplayName("Изделие")]
|
||||
public string ProductName { get; set; } = string.Empty;
|
||||
[DisplayName("Пицца")]
|
||||
public string PizzaName { get; set; } = string.Empty;
|
||||
|
||||
[DisplayName("Количество")]
|
||||
public int Count { get; set; }
|
||||
|
@ -1,15 +0,0 @@
|
||||
using PizzeriaDataModels.Models;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace PizzeriaContracts.ViewModels
|
||||
{
|
||||
public class ProductViewModel : IProductModel
|
||||
{
|
||||
public int Id { get; set; }
|
||||
[DisplayName("Название изделия")]
|
||||
public string ProductName { get; set; } = string.Empty;
|
||||
[DisplayName("Цена")]
|
||||
public double Price { get; set; }
|
||||
public Dictionary<int, (IComponentModel, int)> ProductComponents {get;set;} = new();
|
||||
}
|
||||
}
|
@ -4,7 +4,7 @@ namespace PizzeriaDataModels.Models
|
||||
{
|
||||
public interface IOrderModel : IId
|
||||
{
|
||||
int ProductId { get; }
|
||||
int PizzaId { get; }
|
||||
int Count { get; }
|
||||
double Sum { get; }
|
||||
OrderStatus Status { get; }
|
||||
|
@ -1,9 +0,0 @@
|
||||
namespace PizzeriaDataModels.Models
|
||||
{
|
||||
public interface IProductModel : IId
|
||||
{
|
||||
string ProductName { get; }
|
||||
double Price { get; }
|
||||
Dictionary<int, (IComponentModel, int)> ProductComponents { get; }
|
||||
}
|
||||
}
|
@ -7,12 +7,12 @@ namespace PizzeriaListImplement
|
||||
private static DataListSingleton? _instance;
|
||||
public List<Component> Components { get; set; }
|
||||
public List<Order> Orders { get; set; }
|
||||
public List<Product> Products { get; set; }
|
||||
public List<Pizza> Pizzas { get; set; }
|
||||
private DataListSingleton()
|
||||
{
|
||||
Components = new List<Component>();
|
||||
Orders = new List<Order>();
|
||||
Products = new List<Product>();
|
||||
Pizzas = new List<Pizza>();
|
||||
}
|
||||
public static DataListSingleton GetInstance()
|
||||
{
|
||||
|
@ -3,6 +3,7 @@ using PizzeriaContracts.SearchModels;
|
||||
using PizzeriaContracts.StorageContracts;
|
||||
using PizzeriaContracts.ViewModels;
|
||||
using PizzeriaListImplement.Models;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace PizzeriaListImplement.Implements
|
||||
{
|
||||
@ -22,7 +23,7 @@ namespace PizzeriaListImplement.Implements
|
||||
{
|
||||
var element = _source.Orders[i];
|
||||
_source.Orders.RemoveAt(i);
|
||||
return element.GetViewModel;
|
||||
return AddPizzaName(element.GetViewModel);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@ -37,7 +38,7 @@ namespace PizzeriaListImplement.Implements
|
||||
{
|
||||
if ((model.Id.HasValue && order.Id == model.Id))
|
||||
{
|
||||
return order.GetViewModel;
|
||||
return AddPizzaName(order.GetViewModel);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@ -54,7 +55,7 @@ namespace PizzeriaListImplement.Implements
|
||||
{
|
||||
if (order.Id == model.Id)
|
||||
{
|
||||
result.Add(order.GetViewModel);
|
||||
result.Add(AddPizzaName(order.GetViewModel));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@ -65,7 +66,7 @@ namespace PizzeriaListImplement.Implements
|
||||
var result = new List<OrderViewModel>();
|
||||
foreach (var order in _source.Orders)
|
||||
{
|
||||
result.Add(order.GetViewModel);
|
||||
result.Add(AddPizzaName(order.GetViewModel));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -85,7 +86,7 @@ namespace PizzeriaListImplement.Implements
|
||||
return null;
|
||||
}
|
||||
_source.Orders.Add(newOrder);
|
||||
return newOrder.GetViewModel;
|
||||
return AddPizzaName(newOrder.GetViewModel);
|
||||
}
|
||||
public OrderViewModel? Update(OrderBindingModel model)
|
||||
{
|
||||
@ -94,11 +95,21 @@ namespace PizzeriaListImplement.Implements
|
||||
if (order.Id == model.Id)
|
||||
{
|
||||
order.Update(model);
|
||||
return order.GetViewModel;
|
||||
return AddPizzaName(order.GetViewModel);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private OrderViewModel AddPizzaName(OrderViewModel model)
|
||||
{
|
||||
var selectedPizza = _source.Pizzas.Find(pizza => pizza.Id == model.PizzaId);
|
||||
if (selectedPizza != null)
|
||||
{
|
||||
model.PizzaName = selectedPizza.PizzaName;
|
||||
}
|
||||
return model;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,100 +0,0 @@
|
||||
using PizzeriaContracts.BindingModels;
|
||||
using PizzeriaContracts.SearchModels;
|
||||
using PizzeriaContracts.StorageContracts;
|
||||
using PizzeriaContracts.ViewModels;
|
||||
using PizzeriaListImplement.Models;
|
||||
|
||||
namespace PizzeriaListImplement.Implements
|
||||
{
|
||||
public class ProductStorage : IProductStorage
|
||||
{
|
||||
private readonly DataListSingleton _source;
|
||||
public ProductStorage()
|
||||
{
|
||||
_source = DataListSingleton.GetInstance();
|
||||
}
|
||||
public List<ProductViewModel> GetFullList()
|
||||
{
|
||||
var result = new List<ProductViewModel>();
|
||||
foreach (var product in _source.Products)
|
||||
{
|
||||
result.Add(product.GetViewModel);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public List<ProductViewModel> GetFilteredList(ProductSearchModel model)
|
||||
{
|
||||
var result = new List<ProductViewModel>();
|
||||
if (string.IsNullOrEmpty(model.ProductName))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
foreach (var product in _source.Products)
|
||||
{
|
||||
if (product.ProductName.Contains(model.ProductName))
|
||||
{
|
||||
result.Add(product.GetViewModel);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public ProductViewModel? GetElement(ProductSearchModel model)
|
||||
{
|
||||
if (string.IsNullOrEmpty(model.ProductName) && !model.Id.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
foreach (var product in _source.Products)
|
||||
{
|
||||
if ((!string.IsNullOrEmpty(model.ProductName) && product.ProductName == model.ProductName) || (model.Id.HasValue && product.Id == model.Id))
|
||||
{
|
||||
return product.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public ProductViewModel? Insert(ProductBindingModel model)
|
||||
{
|
||||
model.Id = 1;
|
||||
foreach (var product in _source.Products)
|
||||
{
|
||||
if (model.Id <= product.Id)
|
||||
{
|
||||
model.Id = product.Id + 1;
|
||||
}
|
||||
}
|
||||
var newProduct = Product.Create(model);
|
||||
if (newProduct == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
_source.Products.Add(newProduct);
|
||||
return newProduct.GetViewModel;
|
||||
}
|
||||
public ProductViewModel? Update(ProductBindingModel model)
|
||||
{
|
||||
foreach (var product in _source.Products)
|
||||
{
|
||||
if (product.Id == model.Id)
|
||||
{
|
||||
product.Update(model);
|
||||
return product.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public ProductViewModel? Delete(ProductBindingModel model)
|
||||
{
|
||||
for (int i = 0; i < _source.Products.Count; ++i)
|
||||
{
|
||||
if (_source.Products[i].Id == model.Id)
|
||||
{
|
||||
var element = _source.Products[i];
|
||||
_source.Products.RemoveAt(i);
|
||||
return element.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -16,7 +16,7 @@ namespace PizzeriaListImplement.Models
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
|
||||
public int ProductId { get; private set; }
|
||||
public int PizzaId { get; private set; }
|
||||
|
||||
public int Count { get; private set; }
|
||||
|
||||
@ -37,7 +37,7 @@ namespace PizzeriaListImplement.Models
|
||||
return new Order()
|
||||
{
|
||||
Id = model.Id,
|
||||
ProductId = model.ProductId,
|
||||
PizzaId = model.PizzaId,
|
||||
Count = model.Count,
|
||||
Sum = model.Sum,
|
||||
Status = model.Status,
|
||||
@ -58,7 +58,7 @@ namespace PizzeriaListImplement.Models
|
||||
public OrderViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ProductId = ProductId,
|
||||
PizzaId = PizzaId,
|
||||
Count = Count,
|
||||
Sum = Sum,
|
||||
Status = Status,
|
||||
|
@ -1,49 +0,0 @@
|
||||
using PizzeriaContracts.BindingModels;
|
||||
using PizzeriaContracts.ViewModels;
|
||||
using PizzeriaDataModels.Models;
|
||||
|
||||
namespace PizzeriaListImplement.Models
|
||||
{
|
||||
public class Product : IProductModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public string ProductName { get; private set; } = string.Empty;
|
||||
public double Price { get; private set; }
|
||||
public Dictionary<int, (IComponentModel, int)> ProductComponents
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
} = new Dictionary<int, (IComponentModel, int)>();
|
||||
public static Product? Create(ProductBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new Product()
|
||||
{
|
||||
Id = model.Id,
|
||||
ProductName = model.ProductName,
|
||||
Price = model.Price,
|
||||
ProductComponents = model.ProductComponents
|
||||
};
|
||||
}
|
||||
public void Update(ProductBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
ProductName = model.ProductName;
|
||||
Price = model.Price;
|
||||
ProductComponents = model.ProductComponents;
|
||||
}
|
||||
public ProductViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
ProductName = ProductName,
|
||||
Price = Price,
|
||||
ProductComponents = ProductComponents
|
||||
};
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user