diff --git a/Pizzeria/Pizzeria/FormComponent.Designer.cs b/Pizzeria/Pizzeria/FormComponent.Designer.cs index 4d1d77a..1c685f0 100644 --- a/Pizzeria/Pizzeria/FormComponent.Designer.cs +++ b/Pizzeria/Pizzeria/FormComponent.Designer.cs @@ -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(); diff --git a/Pizzeria/Pizzeria/FormComponent.cs b/Pizzeria/Pizzeria/FormComponent.cs index 1f694de..e5ebb06 100644 --- a/Pizzeria/Pizzeria/FormComponent.cs +++ b/Pizzeria/Pizzeria/FormComponent.cs @@ -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); } } diff --git a/Pizzeria/Pizzeria/FormComponents.Designer.cs b/Pizzeria/Pizzeria/FormComponents.Designer.cs index dcc698e..73f5145 100644 --- a/Pizzeria/Pizzeria/FormComponents.Designer.cs +++ b/Pizzeria/Pizzeria/FormComponents.Designer.cs @@ -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; } } \ No newline at end of file diff --git a/Pizzeria/Pizzeria/FormComponents.cs b/Pizzeria/Pizzeria/FormComponents.cs index 6684db0..42ecb4b 100644 --- a/Pizzeria/Pizzeria/FormComponents.cs +++ b/Pizzeria/Pizzeria/FormComponents.cs @@ -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(); diff --git a/Pizzeria/Pizzeria/Program.cs b/Pizzeria/Pizzeria/Program.cs index 7ca1d01..32150d8 100644 --- a/Pizzeria/Pizzeria/Program.cs +++ b/Pizzeria/Pizzeria/Program.cs @@ -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()); - */ } private static void ConfigureServices(ServiceCollection services) { @@ -39,17 +36,17 @@ namespace Pizzeria }); services.AddTransient(); services.AddTransient(); - services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); + services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); services.AddTransient(); - services.AddTransient(); - services.AddTransient(); - services.AddTransient(); + services.AddTransient(); + services.AddTransient(); + services.AddTransient(); } } } \ No newline at end of file diff --git a/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/ComponentLogic.cs b/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/ComponentLogic.cs index c00ad57..5f95a30 100644 --- a/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/ComponentLogic.cs +++ b/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/ComponentLogic.cs @@ -13,9 +13,10 @@ namespace PizzeriaBusinessLogic.BusinessLogic private readonly IComponentStorage _componentStorage; public ComponentLogic(ILogger logger, IComponentStorage componentStorage) { - //_logger = logger; + _logger = logger; _componentStorage = componentStorage; } + public List? 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("ингредиент с таким названием уже есть"); } } } diff --git a/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/OrderLogic.cs b/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/OrderLogic.cs index 87dd32e..6465b13 100644 --- a/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/OrderLogic.cs @@ -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? 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); } - - + + } } diff --git a/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/ProductLogic.cs b/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/ProductLogic.cs deleted file mode 100644 index 2873f11..0000000 --- a/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/ProductLogic.cs +++ /dev/null @@ -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 logger, IProductStorage ProductStorage) - { - //_logger = logger; - _productStorage = ProductStorage; - } - public List? 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("Продукт с таким названием уже есть"); - } - } - } -} diff --git a/Pizzeria/PizzeriaContracts/BindingModels/OrderBindingModel.cs b/Pizzeria/PizzeriaContracts/BindingModels/OrderBindingModel.cs index 755f4bb..575d717 100644 --- a/Pizzeria/PizzeriaContracts/BindingModels/OrderBindingModel.cs +++ b/Pizzeria/PizzeriaContracts/BindingModels/OrderBindingModel.cs @@ -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.Неизвестен; diff --git a/Pizzeria/PizzeriaContracts/BindingModels/ProductBindingModel.cs b/Pizzeria/PizzeriaContracts/BindingModels/ProductBindingModel.cs deleted file mode 100644 index 9ff2ff5..0000000 --- a/Pizzeria/PizzeriaContracts/BindingModels/ProductBindingModel.cs +++ /dev/null @@ -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 ProductComponents {get;set;} = new(); - - } -} diff --git a/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IProductLogic.cs b/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IProductLogic.cs deleted file mode 100644 index a21bcfd..0000000 --- a/Pizzeria/PizzeriaContracts/BusinessLogicsContracts/IProductLogic.cs +++ /dev/null @@ -1,15 +0,0 @@ -using PizzeriaContracts.BindingModels; -using PizzeriaContracts.SearchModels; -using PizzeriaContracts.ViewModels; - -namespace PizzeriaContracts.BusinessLogicsContracts -{ - public interface IProductLogic - { - List? ReadList(ProductSearchModel? model); - ProductViewModel? ReadElement(ProductSearchModel model); - bool Create(ProductBindingModel model); - bool Update(ProductBindingModel model); - bool Delete(ProductBindingModel model); - } -} diff --git a/Pizzeria/PizzeriaContracts/SearchModels/ProductSearchModel.cs b/Pizzeria/PizzeriaContracts/SearchModels/ProductSearchModel.cs deleted file mode 100644 index 7c2d61a..0000000 --- a/Pizzeria/PizzeriaContracts/SearchModels/ProductSearchModel.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace PizzeriaContracts.SearchModels -{ - public class ProductSearchModel - { - public int? Id { get; set; } - public string? ProductName { get; set; } - } -} diff --git a/Pizzeria/PizzeriaContracts/StorageContracts/IProductStorage.cs b/Pizzeria/PizzeriaContracts/StorageContracts/IProductStorage.cs deleted file mode 100644 index 9b0bfb1..0000000 --- a/Pizzeria/PizzeriaContracts/StorageContracts/IProductStorage.cs +++ /dev/null @@ -1,17 +0,0 @@ -using PizzeriaContracts.BindingModels; -using PizzeriaContracts.SearchModels; -using PizzeriaContracts.ViewModels; - -namespace PizzeriaContracts.StorageContracts -{ - public interface IProductStorage - { - List GetFullList(); - List GetFilteredList(ProductSearchModel model); - ProductViewModel? GetElement(ProductSearchModel model); - ProductViewModel? Insert(ProductBindingModel model); - ProductViewModel? Update(ProductBindingModel model); - ProductViewModel? Delete(ProductBindingModel model); - - } -} diff --git a/Pizzeria/PizzeriaContracts/ViewModels/ComponentViewModel.cs b/Pizzeria/PizzeriaContracts/ViewModels/ComponentViewModel.cs index 614f252..1844231 100644 --- a/Pizzeria/PizzeriaContracts/ViewModels/ComponentViewModel.cs +++ b/Pizzeria/PizzeriaContracts/ViewModels/ComponentViewModel.cs @@ -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; } diff --git a/Pizzeria/PizzeriaContracts/ViewModels/OrderViewModel.cs b/Pizzeria/PizzeriaContracts/ViewModels/OrderViewModel.cs index f5042cf..1d71477 100644 --- a/Pizzeria/PizzeriaContracts/ViewModels/OrderViewModel.cs +++ b/Pizzeria/PizzeriaContracts/ViewModels/OrderViewModel.cs @@ -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; } diff --git a/Pizzeria/PizzeriaContracts/ViewModels/ProductViewModel.cs b/Pizzeria/PizzeriaContracts/ViewModels/ProductViewModel.cs deleted file mode 100644 index c15904f..0000000 --- a/Pizzeria/PizzeriaContracts/ViewModels/ProductViewModel.cs +++ /dev/null @@ -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 ProductComponents {get;set;} = new(); - } -} diff --git a/Pizzeria/PizzeriaDataModels/Models/IOrderModel.cs b/Pizzeria/PizzeriaDataModels/Models/IOrderModel.cs index 11c9662..ed9a65e 100644 --- a/Pizzeria/PizzeriaDataModels/Models/IOrderModel.cs +++ b/Pizzeria/PizzeriaDataModels/Models/IOrderModel.cs @@ -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; } diff --git a/Pizzeria/PizzeriaDataModels/Models/IProductModel.cs b/Pizzeria/PizzeriaDataModels/Models/IProductModel.cs deleted file mode 100644 index 54548eb..0000000 --- a/Pizzeria/PizzeriaDataModels/Models/IProductModel.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace PizzeriaDataModels.Models -{ - public interface IProductModel : IId - { - string ProductName { get; } - double Price { get; } - Dictionary ProductComponents { get; } - } -} diff --git a/Pizzeria/PizzeriaListImplement/DataListSingleton.cs b/Pizzeria/PizzeriaListImplement/DataListSingleton.cs index c8ac9b2..f5047b2 100644 --- a/Pizzeria/PizzeriaListImplement/DataListSingleton.cs +++ b/Pizzeria/PizzeriaListImplement/DataListSingleton.cs @@ -7,12 +7,12 @@ namespace PizzeriaListImplement private static DataListSingleton? _instance; public List Components { get; set; } public List Orders { get; set; } - public List Products { get; set; } + public List Pizzas { get; set; } private DataListSingleton() { Components = new List(); Orders = new List(); - Products = new List(); + Pizzas = new List(); } public static DataListSingleton GetInstance() { diff --git a/Pizzeria/PizzeriaListImplement/Implements/OrderStorage.cs b/Pizzeria/PizzeriaListImplement/Implements/OrderStorage.cs index 0eff7eb..24b9031 100644 --- a/Pizzeria/PizzeriaListImplement/Implements/OrderStorage.cs +++ b/Pizzeria/PizzeriaListImplement/Implements/OrderStorage.cs @@ -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(); 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; + } + } } diff --git a/Pizzeria/PizzeriaListImplement/Implements/ProductStorage.cs b/Pizzeria/PizzeriaListImplement/Implements/ProductStorage.cs deleted file mode 100644 index 56441b9..0000000 --- a/Pizzeria/PizzeriaListImplement/Implements/ProductStorage.cs +++ /dev/null @@ -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 GetFullList() - { - var result = new List(); - foreach (var product in _source.Products) - { - result.Add(product.GetViewModel); - } - return result; - } - public List GetFilteredList(ProductSearchModel model) - { - var result = new List(); - 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; - } - } -} diff --git a/Pizzeria/PizzeriaListImplement/Models/Order.cs b/Pizzeria/PizzeriaListImplement/Models/Order.cs index 93de7f0..e0eb9c1 100644 --- a/Pizzeria/PizzeriaListImplement/Models/Order.cs +++ b/Pizzeria/PizzeriaListImplement/Models/Order.cs @@ -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, diff --git a/Pizzeria/PizzeriaListImplement/Models/Product.cs b/Pizzeria/PizzeriaListImplement/Models/Product.cs deleted file mode 100644 index b17aeb7..0000000 --- a/Pizzeria/PizzeriaListImplement/Models/Product.cs +++ /dev/null @@ -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 ProductComponents - { - get; - private set; - } = new Dictionary(); - 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 - }; - } -}