Zacharchenko Lab work 2 Hard #7

Closed
shadowik wants to merge 6 commits from Lab2_Hard into Lab1_Hard
34 changed files with 1328 additions and 11 deletions

View File

@ -13,6 +13,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PizzeriaBusinessLogic", "Pi
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PizzeriaListImplement", "PizzeriaListImplement\PizzeriaListImplement.csproj", "{17269B24-6A77-4C45-B3DD-AA444F22D9B8}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PizzeriaFileImplement", "PizzeriaFileImplement\PizzeriaFileImplement.csproj", "{B3A0C7DA-97ED-428C-9E2E-6FF6569F81A9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -39,6 +41,10 @@ Global
{17269B24-6A77-4C45-B3DD-AA444F22D9B8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{17269B24-6A77-4C45-B3DD-AA444F22D9B8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{17269B24-6A77-4C45-B3DD-AA444F22D9B8}.Release|Any CPU.Build.0 = Release|Any CPU
{B3A0C7DA-97ED-428C-9E2E-6FF6569F81A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B3A0C7DA-97ED-428C-9E2E-6FF6569F81A9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B3A0C7DA-97ED-428C-9E2E-6FF6569F81A9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B3A0C7DA-97ED-428C-9E2E-6FF6569F81A9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -41,6 +41,7 @@
this.buttonOrderReady = new System.Windows.Forms.Button();
this.buttonIssuedOrder = new System.Windows.Forms.Button();
this.buttonRef = new System.Windows.Forms.Button();
this.продажаToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.menuStrip1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.SuspendLayout();
@ -71,28 +72,29 @@
// 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.Click += new System.EventHandler(this.IngridentsToolStripMenuItem_Click);
//
// 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.Click += new System.EventHandler(this.PizzasToolStripMenuItem_Click);
//
// 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.Click += new System.EventHandler(this.shopsToolStripMenuItem_Click);
//
// operationToolStripMenuItem
//
this.operationToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.transactionToolStripMenuItem});
this.transactionToolStripMenuItem,
this.продажаToolStripMenuItem});
this.operationToolStripMenuItem.Name = "operationToolStripMenuItem";
this.operationToolStripMenuItem.Size = new System.Drawing.Size(75, 20);
this.operationToolStripMenuItem.Text = "Операции";
@ -173,6 +175,13 @@
this.buttonRef.UseVisualStyleBackColor = true;
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
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
@ -213,5 +222,6 @@
private ToolStripMenuItem shopsToolStripMenuItem;
private ToolStripMenuItem operationToolStripMenuItem;
private ToolStripMenuItem transactionToolStripMenuItem;
private ToolStripMenuItem продажаToolStripMenuItem;
}
}

View File

@ -162,5 +162,14 @@ namespace PizzeriaView
form.ShowDialog();
}
}
private void SellToolStripMenuItem_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormSellPizza));
if (service is FormSellPizza form)
{
form.ShowDialog();
}
}
}
}

View 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;
}
}

View File

@ -0,0 +1,83 @@
using Microsoft.Extensions.Logging;
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 (comboBoxPizza.SelectedValue == null)
{
MessageBox.Show("Выберите пиццу", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Создание покупки");
try
{
bool resout = _logicS.Sale(new SupplySearchModel
{
PizzaId = Convert.ToInt32(comboBoxPizza.SelectedValue),
Count = Convert.ToInt32(textBoxCount.Text)
});
if (resout)
{
_logger.LogInformation("Проверка пройдена, продажа проведена");
MessageBox.Show("Продажа проведена", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
else {
_logger.LogInformation("Проверка не пройдена");
MessageBox.Show("Продажа не может быть создана.", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
catch(Exception ex)
{
_logger.LogError(ex, "Ошибка создания покупки");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
}
}

View File

@ -0,0 +1,60 @@
<root>
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -40,7 +40,10 @@
this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.label1 = new System.Windows.Forms.Label();
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.numericUpPizzaMaxCount)).BeginInit();
this.SuspendLayout();
//
// labelName
@ -105,13 +108,13 @@
this.id,
this.PizzaName,
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.ReadOnly = true;
this.dataGridView.RowHeadersBorderStyle = System.Windows.Forms.DataGridViewHeaderBorderStyle.None;
this.dataGridView.RowHeadersWidthSizeMode = System.Windows.Forms.DataGridViewRowHeadersWidthSizeMode.AutoSizeToDisplayedHeaders;
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;
//
// id
@ -152,11 +155,34 @@
this.dateTimeOpen.Size = new System.Drawing.Size(401, 27);
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
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
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.label1);
this.Controls.Add(this.dataGridView);
@ -170,6 +196,7 @@
this.Text = "Магазин";
this.Load += new System.EventHandler(this.FormShop_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpPizzaMaxCount)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
@ -189,5 +216,7 @@
private DataGridViewTextBoxColumn Count;
private Label label1;
private DateTimePicker dateTimeOpen;
private Label label2;
private NumericUpDown numericUpPizzaMaxCount;
}
}

View File

@ -46,6 +46,7 @@ namespace PizzeriaView
textBoxName.Text = view.ShopName;
textBoxAdress.Text = view.Adress;
dateTimeOpen.Value = view.OpeningDate;
numericUpPizzaMaxCount.Value = view.PizzaMaxCount;
_ShopPizzas = view.ShopPizzas ?? new Dictionary<int, (IPizzaModel, int)>();
LoadData();
}
@ -99,7 +100,8 @@ namespace PizzeriaView
Id = _id ?? 0,
ShopName = textBoxName.Text,
Adress = textBoxAdress.Text,
OpeningDate = dateTimeOpen.Value
OpeningDate = dateTimeOpen.Value,
PizzaMaxCount = (int) numericUpPizzaMaxCount.Value
};
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
if (!operationResult)

View File

@ -66,4 +66,13 @@
<metadata name="Count.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="id.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="PizzaName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="Count.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
</root>

View File

@ -17,6 +17,7 @@
<ProjectReference Include="..\PizzeriaDataModels\PizzeriaDataModels.csproj" />
<ProjectReference Include="..\PizzeriaBusinessLogic\PizzeriaBusinessLogic.csproj" />
<ProjectReference Include="..\PizzeriaContracts\PizzeriaContracts.csproj" />
<ProjectReference Include="..\PizzeriaFileImplement\PizzeriaFileImplement.csproj" />
<ProjectReference Include="..\PizzeriaListImplement\PizzeriaListImplement.csproj" />
<ProjectReference Include="..\PizzeriaContracts\PizzeriaContracts.csproj" />
</ItemGroup>

View File

@ -4,7 +4,7 @@ using NLog.Extensions.Logging;
using PizzeriaBusinessLogic.BusinessLogics;
using PizzeriaContracts.BusinessLogicsContracts;
using PizzeriaContracts.StoragesContracts;
using PizzeriaListImplement.Implements;
using PizzeriaFileImplement.Implements;
using PizzeriaView;
using System;
using System.Drawing;
@ -56,6 +56,7 @@ namespace Pizzeria
services.AddTransient<FormShop>();
services.AddTransient<FormShops>();
services.AddTransient<FormCreateSupply>();
services.AddTransient<FormSellPizza>();
}
}
}

View File

@ -12,10 +12,12 @@ namespace PizzeriatBusinessLogic.BusinessLogics
{
private readonly ILogger _logger;
private readonly IOrderStorage _orderStorage;
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
private readonly IShopStorage _shopStorage;
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IShopStorage shopStorage)
{
_logger = logger;
_orderStorage = orderStorage;
_shopStorage = shopStorage;
}
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
{
@ -52,6 +54,23 @@ namespace PizzeriatBusinessLogic.BusinessLogics
}
public bool DeliveryOrder(OrderBindingModel model)
{
var order = _orderStorage.GetElement(new OrderSearchModel
{
Id = model.Id,
});
if (order == null)
{
throw new ArgumentNullException(nameof(order));
}
if (!_shopStorage.RestockingShops(new SupplyBindingModel
{
PizzaId = order.PizzaId,
Count = order.Count
}))
{
throw new ArgumentException("Недостаточно места");
}
return ChangeStatus(model, OrderStatus.Выдан);
}
private void CheckModel(OrderBindingModel model, bool withParams = true)

View File

@ -148,5 +148,21 @@ namespace PizzeriaBusinessLogic.BusinessLogics
throw new InvalidOperationException("Магазин с таким названием уже есть");
}
}
public bool Sale(SupplySearchModel model)
{
if (!model.PizzaId.HasValue || !model.Count.HasValue)
{
return false;
}
_logger.LogInformation("Check pizza count in all shops");
if (_shopStorage.Sale(model))
{
_logger.LogInformation("Selling sucsess");
return true;
}
_logger.LogInformation("Selling failed");
return false;
}
}
}

View File

@ -14,5 +14,6 @@ namespace PizzeriaContracts.BindingModels
public string Adress { get; set; } = string.Empty;
public DateTime OpeningDate { get; set; } = DateTime.Now;
public Dictionary<int, (IPizzaModel, int)> ShopPizzas { get; set; } = new();
public int PizzaMaxCount { get; set; }
}
}

View File

@ -17,5 +17,6 @@ namespace PizzeriaContracts.BusinessLogicsContracts
bool Update(ShopBindingModel model);
bool Delete(ShopBindingModel model);
bool MakeSupply(SupplyBindingModel model);
bool Sale(SupplySearchModel model);
}
}

View 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; }
}
}

View File

@ -17,5 +17,7 @@ namespace PizzeriaContracts.StoragesContracts
ShopViewModel? Insert(ShopBindingModel model);
ShopViewModel? Update(ShopBindingModel model);
ShopViewModel? Delete(ShopBindingModel model);
bool Sale(SupplySearchModel model);
bool RestockingShops(SupplyBindingModel model);
}
}

View File

@ -18,5 +18,7 @@ namespace PizzeriaContracts.ViewModels
[DisplayName("Дата открытия")]
public DateTime OpeningDate { get; set; }
public Dictionary<int, (IPizzaModel, int)> ShopPizzas { get; set; } = new();
[DisplayName("Вместимость")]
public int PizzaMaxCount { get; set; }
}
}

View File

@ -14,5 +14,6 @@ namespace PizzeriaDataModels.Models
string Adress { get; }
DateTime OpeningDate { get; }
Dictionary<int, (IPizzaModel, int)> ShopPizzas { get; }
public int PizzaMaxCount { get; }
}
}

View File

@ -0,0 +1,118 @@
using PizzeriaContracts.BindingModels;
using PizzeriaContracts.ViewModels;
using PizzeriaDataModels.Models;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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; }
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(),
Piz = model.ReinforcedMaxCount
};
}
public void Update(ShopBindingModel model)
{
ShopName = model.ShopName;
Adress = model.Adress;
OpeningDate = model.OpeningDate;
ReinforcedMaxCount = model.ReinforcedMaxCount;
}
public ShopViewModel GetViewModel => new()
{
Id = Id,
ShopName = ShopName,
Adress = Adress,
OpeningDate = OpeningDate,
ShopReinforcedes = ShopReinforcedes,
ReinforcedMaxCount = ReinforcedMaxCount
};
public void UpdateReinforcedes(PrecastConcretePlantDatabase context, ShopBindingModel model)
{
var ShopReinforcedes = context.ShopReinforcedes.Where(rec => rec.ShopId == model.Id).ToList();
if (ShopReinforcedes != null && ShopReinforcedes.Count > 0)
{
// удалили те, которых нет в модели
context.ShopReinforcedes.RemoveRange(ShopReinforcedes.Where(rec => !model.ShopReinforcedes.ContainsKey(rec.ReinforcedId)));
context.SaveChanges();
ShopReinforcedes = context.ShopReinforcedes.Where(rec => rec.ShopId == model.Id).ToList();
// обновили количество у существующих записей
foreach (var updateReinforced in ShopReinforcedes)
{
updateReinforced.Count = model.ShopReinforcedes[updateReinforced.ReinforcedId].Item2;
model.ShopReinforcedes.Remove(updateReinforced.ReinforcedId);
}
context.SaveChanges();
}
var shop = context.Shops.First(x => x.Id == Id);
foreach (var ar in model.ShopReinforcedes)
{
context.ShopReinforcedes.Add(new ShopReinforced
{
Shop = shop,
Reinforced = context.Reinforceds.First(x => x.Id == ar.Key),
Count = ar.Value.Item2
});
context.SaveChanges();
}
_shopReinforcedes = null;
}
public void ReinforcedDictionatyUpdate(PrecastConcretePlantDatabase context)
{
UpdateReinforcedes(context, new ShopBindingModel
{
Id = Id,
ShopReinforcedes = ShopReinforcedes,
});
}
}
}

View File

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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();
}
}

View File

@ -0,0 +1,55 @@
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);
}
}
}
}

View File

@ -0,0 +1,74 @@
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;
}
}
}

View File

@ -0,0 +1,84 @@
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;
}
}
}

View File

@ -0,0 +1,74 @@
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;
}
}
}

View File

@ -0,0 +1,144 @@
using PizzeriaContracts.BindingModels;
using PizzeriaContracts.SearchModels;
using PizzeriaContracts.StoragesContracts;
using PizzeriaContracts.ViewModels;
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 Sale(SupplySearchModel model) {
if (model == null || !model.PizzaId.HasValue || !model.Count.HasValue)
return false;
int remainingSpace = source.Shops.Select(x => x.Pizzas.ContainsKey(model.PizzaId.Value) ? x.Pizzas[model.PizzaId.Value] : 0).Sum();
if(remainingSpace < model.Count)
{
return false;
}
var shops = source.Shops.Where(x => x.Pizzas.ContainsKey(model.PizzaId.Value)).OrderByDescending(x => x.Pizzas[model.PizzaId.Value]).ToList();
foreach (var shop in shops)
{
int residue = model.Count.Value - shop.Pizzas[model.PizzaId.Value];
if (residue > 0)
{
shop.Pizzas.Remove(model.PizzaId.Value);
shop.PizzasUpdate();
model.Count = residue;
}
else
{
if (residue == 0)
{
shop.Pizzas.Remove(model.PizzaId.Value);
}
else
{
shop.Pizzas[model.PizzaId.Value] = -residue;
}
shop.PizzasUpdate();
source.SaveShops();
return true;
}
}
source.SaveShops();
return false;
}
public bool RestockingShops(SupplyBindingModel model)
{
if (model==null || source.Shops.Select(x => x.PizzaMaxCount - x.ShopPizzas.Select(y => y.Value.Item2).Sum()).Sum() < model.Count)
{
return false;
}
foreach (Shop shop in source.Shops)
{
int free_places = shop.PizzaMaxCount - shop.ShopPizzas.Select(x => x.Value.Item2).Sum();
if (free_places <= 0)
continue;
free_places = Math.Min(free_places, model.Count);
model.Count -= free_places;
if (shop.Pizzas.ContainsKey(model.PizzaId))
{
shop.Pizzas[model.PizzaId] += free_places;
}
else
{
shop.Pizzas.Add(model.PizzaId, free_places);
}
shop.PizzasUpdate();
if (model.Count == 0)
{
source.SaveShops();
return true;
}
}
return false;
}
}
}

View File

@ -0,0 +1,59 @@
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()));
}
}

View File

@ -0,0 +1,83 @@
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()));
}
}

View 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()));
}
}

View File

@ -0,0 +1,102 @@
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;
}
}
}

View 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>

View File

@ -102,5 +102,15 @@ namespace PizzeriaListImplement.Implements
}
return null;
}
public bool Sale(SupplySearchModel model)
{
throw new NotImplementedException();
}
public bool RestockingShops(SupplyBindingModel model)
{
throw new NotImplementedException();
}
}
}

View File

@ -39,6 +39,7 @@ namespace PizzeriaListImplement.Models
}
Status = model.Status;
if (model.Status == OrderStatus.Выдан) DateImplement = model.DateImplement;
if (model.Status == OrderStatus.Выдан) DateImplement = model.DateImplement;
}
public OrderViewModel GetViewModel => new()
{

View File

@ -16,6 +16,7 @@ namespace PizzeriaListImplement.Models
public string Adress { get; private set; } = string.Empty;
public DateTime OpeningDate { get; private set; }
public Dictionary<int, (IPizzaModel, int)> ShopPizzas { get; private set; } = new();
public int PizzaMaxCount { get; private set; }
public static Shop? Create(ShopBindingModel? model)
{
if (model == null)
@ -27,7 +28,8 @@ namespace PizzeriaListImplement.Models
Id = model.Id,
ShopName = model.ShopName,
Adress = model.Adress,
OpeningDate = model.OpeningDate
OpeningDate = model.OpeningDate,
PizzaMaxCount = model.PizzaMaxCount,
};
}
public void Update(ShopBindingModel? model)
@ -39,6 +41,7 @@ namespace PizzeriaListImplement.Models
ShopName = model.ShopName;
Adress = model.Adress;
OpeningDate = model.OpeningDate;
PizzaMaxCount = model.PizzaMaxCount;
}
public ShopViewModel GetViewModel => new()
{
@ -46,8 +49,10 @@ namespace PizzeriaListImplement.Models
ShopName = ShopName,
Adress = Adress,
OpeningDate = OpeningDate,
ShopPizzas = ShopPizzas
ShopPizzas = ShopPizzas,
PizzaMaxCount = PizzaMaxCount,
};
}
}