Tsukanova_I.V. LabWork02_hard #7

Closed
Inohara wants to merge 8 commits from LabWork02_hard into LabWork01_hard
42 changed files with 1400 additions and 327 deletions

View File

@ -1,25 +0,0 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.3.32922.545
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AbstractIceCreamShopDataModels", "AbstractIceCreamShopDataModels\AbstractIceCreamShopDataModels.csproj", "{28830087-9D9F-4E66-84CC-94C5CF376BF1}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{28830087-9D9F-4E66-84CC-94C5CF376BF1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{28830087-9D9F-4E66-84CC-94C5CF376BF1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{28830087-9D9F-4E66-84CC-94C5CF376BF1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{28830087-9D9F-4E66-84CC-94C5CF376BF1}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A7BDC253-D956-404D-9013-AD0FE1F32DD1}
EndGlobalSection
EndGlobal

View File

@ -1,9 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

View File

@ -1,14 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AbstractIceCreamShopDataModels.Models
{
public interface IComponentModel : IId
{
string ComponentName { get; }
double Cost { get; }
}
}

View File

@ -1,13 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AbstractIceCreamShopDataModels
{
public interface IId
{
int Id { get; }
}
}

View File

@ -1,19 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AbstractIceCreamShopDataModels.Models
{
public interface IOrderModel : IId
{
int ProductId { get; }
int Count { get; }
double Sum { get; }
OrderStatus Status { get; }
DateTime DateCreate { get; }
DateTime? DateImplement { get; }
}
}

View File

@ -1,15 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AbstractIceCreamShopDataModels.Models
{
public interface IProductModel : IId
{
string ProductName { get; }
double Price { get; }
Dictionary<int, (IComponentModel, int)> ProductComponents { get; }
}
}

View File

@ -1,11 +0,0 @@
namespace AbstractIceCreamShopDataModels
{
public enum OrderStatus
{
Неизвестен = -1,
Принят = 0,
Выполняется = 1,
Готов = 2,
Выдан = 3
}
}

View File

@ -101,7 +101,7 @@ namespace IceCreamBusinessLogic.BusinessLogics
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 });
var element = _componentStorage.GetElement(new ComponentSearchModel { ComponentName = model.ComponentName });
if (element != null && element.Id != model.Id)
{
throw new InvalidOperationException("Компонент с таким названием уже есть");

View File

@ -10,6 +10,7 @@ using IceCreamShopContracts.SearchModels;
using IceCreamShopContracts.StoragesContracts;
using IceCreamShopContracts.ViewModels;
using AbstractIceCreamShopDataModels.Enums;
using AbstractIceCreamShopDataModels.Models;
namespace IceCreamBusinessLogic.BusinessLogics
{
@ -17,11 +18,17 @@ namespace IceCreamBusinessLogic.BusinessLogics
{
private readonly ILogger _logger;
private readonly IOrderStorage _orderStorage;
private readonly IShopStorage _shopStorage;
private readonly IShopLogic _shopLogic;
private readonly IIceCreamStorage _iceCreamStorage;
public OrderLogic(IOrderStorage orderStorage, ILogger<OrderLogic> logger)
public OrderLogic(IOrderStorage orderStorage, IShopStorage shopStorage, IShopLogic shopLogic, IIceCreamStorage iceCreamStorage, ILogger<OrderLogic> logger)
{
_orderStorage = orderStorage;
_shopStorage = shopStorage;
_logger = logger;
_shopLogic = shopLogic;
_iceCreamStorage = iceCreamStorage;
}
public bool CreateOrder(OrderBindingModel model)
@ -104,27 +111,42 @@ namespace IceCreamBusinessLogic.BusinessLogics
if (viewModel == null)
{
_logger.LogWarning("Order model not found");
return false;
throw new ArgumentNullException(nameof(orderModel));
}
OrderBindingModel model = new OrderBindingModel
{
Id = viewModel.Id,
IceCreamId = viewModel.IceCreamId,
IceCreamName = viewModel.IceCreamName,
Status = viewModel.Status,
DateCreate = viewModel.DateCreate,
DateImplement = viewModel.DateImplement,
Count = viewModel.Count,
Sum = viewModel.Sum
};
CheckModel(model);
if (model.Status + 1 != newStatus)
{
_logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Order status incorrect.");
return false;
}
if (newStatus == OrderStatus.Готов)
{
var icecream = _iceCreamStorage.GetElement(new IceCreamSearchModel() { Id = model.IceCreamId });
if (icecream == null)
{
_logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Document not found.");
return false;
}
if (CheckSupply(icecream, model.Count) == false)
{
_logger.LogWarning("Status update to " + newStatus.ToString() + " operation failed. Shop supply error.");
return false;
}
}
model.Status = newStatus;
if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now;
if (_orderStorage.Update(model) == null)
@ -135,5 +157,66 @@ namespace IceCreamBusinessLogic.BusinessLogics
}
return true;
}
public bool CheckSupply(IIceCreamModel iceCream, int count)
{
if (count <= 0)
{
_logger.LogWarning("Check then supply operation error. IceCream count < 0.");
return false;
}
int freeSpace = 0;
foreach (var shop in _shopStorage.GetFullList())
{
freeSpace += shop.IceCreamMaxCount;
foreach (var doc in shop.ShopIceCreams)
{
freeSpace -= doc.Value.Item2;
}
}
if (freeSpace - count < 0)
{
_logger.LogWarning("Check then supply operation error. There's no place for new IceCream in shops.");
return false;
}
foreach (var shop in _shopStorage.GetFullList())
{
freeSpace = shop.IceCreamMaxCount;
foreach (var doc in shop.ShopIceCreams)
{
freeSpace -= doc.Value.Item2;
}
if (freeSpace == 0)
{
continue;
}
if (freeSpace - count >= 0)
{
if (_shopLogic.SupplyIceCreams(new() { Id = shop.Id }, iceCream, count)) count = 0;
else
{
_logger.LogWarning("Supply error");
return false;
}
}
if (freeSpace - count < 0)
{
if (_shopLogic.SupplyIceCreams(new() { Id = shop.Id }, iceCream, freeSpace)) count -= freeSpace;
else
{
_logger.LogWarning("Supply error");
return false;
}
}
if (count <= 0)
{
return true;
}
}
return false;
}
}
}

View File

@ -10,6 +10,9 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Reflection.Metadata;
using System.Xml.Linq;
using System.Reflection;
namespace IceCreamBusinessLogic.BusinessLogics
{
@ -70,7 +73,7 @@ namespace IceCreamBusinessLogic.BusinessLogics
if (count <= 0)
{
throw new ArgumentNullException("Count of icecreams in supply must be more than 0", nameof(count));
throw new ArgumentNullException("Count of iceCreams in supply myst be more than 0", nameof(count));
}
var shopElement = _shopStorage.GetElement(model);
@ -81,29 +84,46 @@ namespace IceCreamBusinessLogic.BusinessLogics
}
_logger.LogInformation("Shop element found. ID: {0}, Name: {1}", shopElement.Id, shopElement.Name);
if (shopElement.ShopIceCreams.TryGetValue(iceCream.Id, out var sameDocument))
var countDocs = 0;
foreach (var doc in shopElement.ShopIceCreams)
{
shopElement.ShopIceCreams[iceCream.Id] = (iceCream, sameDocument.Item2 + count);
_logger.LogInformation("Same icecream found by supply. Added {0} of {1} in {2} shop", count, iceCream.IceCreamName, shopElement.Name);
countDocs += doc.Value.Item2;
}
if (shopElement.IceCreamMaxCount - countDocs >= count)
{
if (shopElement.ShopIceCreams.TryGetValue(iceCream.Id, out var sameDocument))
{
shopElement.ShopIceCreams[iceCream.Id] = (iceCream, sameDocument.Item2 + count);
_logger.LogInformation("Same iceCream found by supply. Added {0} of {1} in {2} shop", count, iceCream.IceCreamName, shopElement.Name);
}
else
{
shopElement.ShopIceCreams[iceCream.Id] = (iceCream, count);
_logger.LogInformation("New iceCream added by supply. Added {0} of {1} in {2} shop", count, iceCream.IceCreamName, shopElement.Name);
}
_shopStorage.Update(new()
{
Id = shopElement.Id,
Name = shopElement.Name,
Adress = shopElement.Adress,
OpeningDate = shopElement.OpeningDate,
ShopIceCreams = shopElement.ShopIceCreams,
IceCreamMaxCount = shopElement.IceCreamMaxCount
});
}
else
{
shopElement.ShopIceCreams[iceCream.Id] = (iceCream, count);
_logger.LogInformation("New icecream added by supply. Added {0} of {1} in {2} shop", count, iceCream.IceCreamName, shopElement.Name);
_logger.LogWarning("Required shop is overflowed");
return false;
}
_shopStorage.Update(new()
{
Id = shopElement.Id,
Name = shopElement.Name,
Adress = shopElement.Adress,
OpeningDate = shopElement.OpeningDate,
ShopIceCreams = shopElement.ShopIceCreams
});
return true;
}
public bool SellIceCreams(IIceCreamModel iceCream, int count)
{
return _shopStorage.SellIceCreams(iceCream, count);
}
public bool Create(ShopBindingModel model)
{
CheckModel(model);

View File

@ -11,7 +11,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IceCreamShopContracts", "Ic
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IceCreamBusinessLogic", "IceCreamBusinessLogic\IceCreamBusinessLogic.csproj", "{E4C64BCD-22DF-43B5-8324-AE64F9237DFF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IceCreamShopListImplement", "IceCreamShopListImplement\IceCreamShopListImplement.csproj", "{EBB0BAF6-8DEE-42EF-8AF5-571B4E0DE95E}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IceCreamShopListImplement", "IceCreamShopListImplement\IceCreamShopListImplement.csproj", "{EBB0BAF6-8DEE-42EF-8AF5-571B4E0DE95E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IceCreamShopFileImplement", "IceCreamShopFileImplement\IceCreamShopFileImplement.csproj", "{382E618C-D833-4E98-9786-7A831953ABD0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -39,6 +41,10 @@ Global
{EBB0BAF6-8DEE-42EF-8AF5-571B4E0DE95E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EBB0BAF6-8DEE-42EF-8AF5-571B4E0DE95E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EBB0BAF6-8DEE-42EF-8AF5-571B4E0DE95E}.Release|Any CPU.Build.0 = Release|Any CPU
{382E618C-D833-4E98-9786-7A831953ABD0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{382E618C-D833-4E98-9786-7A831953ABD0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{382E618C-D833-4E98-9786-7A831953ABD0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{382E618C-D833-4E98-9786-7A831953ABD0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -67,6 +67,7 @@
this.buttonEdit.TabIndex = 8;
this.buttonEdit.Text = "Изменить";
this.buttonEdit.UseVisualStyleBackColor = true;
this.buttonEdit.Click += new System.EventHandler(this.buttonEdit_Click);
//
// buttonAdd
//

View File

@ -40,6 +40,7 @@
this.мороженоеToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.магазиныToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.buttonSupplyShop = new System.Windows.Forms.Button();
this.SellIceCreamButton = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
this.menuStrip.SuspendLayout();
this.SuspendLayout();
@ -135,21 +136,21 @@
// компонентыToolStripMenuItem
//
this.компонентыToolStripMenuItem.Name = омпонентыToolStripMenuItem";
this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.компонентыToolStripMenuItem.Size = new System.Drawing.Size(145, 22);
this.компонентыToolStripMenuItem.Text = "Компоненты";
this.компонентыToolStripMenuItem.Click += new System.EventHandler(this.компонентыToolStripMenuItem_Click);
//
// мороженоеToolStripMenuItem
//
this.мороженоеToolStripMenuItem.Name = ороженоеToolStripMenuItem";
this.мороженоеToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.мороженоеToolStripMenuItem.Size = new System.Drawing.Size(145, 22);
this.мороженоеToolStripMenuItem.Text = "Мороженое";
this.мороженоеToolStripMenuItem.Click += new System.EventHandler(this.мороженоеToolStripMenuItem_Click);
//
// магазиныToolStripMenuItem
//
this.магазиныToolStripMenuItem.Name = агазиныToolStripMenuItem";
this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.магазиныToolStripMenuItem.Size = new System.Drawing.Size(145, 22);
this.магазиныToolStripMenuItem.Text = "Магазины";
this.магазиныToolStripMenuItem.Click += new System.EventHandler(this.магазиныToolStripMenuItem_Click);
//
@ -164,11 +165,23 @@
this.buttonSupplyShop.UseVisualStyleBackColor = true;
this.buttonSupplyShop.Click += new System.EventHandler(this.buttonSupplyShop_Click);
//
// SellIceCreamButton
//
this.SellIceCreamButton.Location = new System.Drawing.Point(878, 231);
this.SellIceCreamButton.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.SellIceCreamButton.Name = "SellIceCreamButton";
this.SellIceCreamButton.Size = new System.Drawing.Size(170, 37);
this.SellIceCreamButton.TabIndex = 15;
this.SellIceCreamButton.Text = "Продажа мороженого";
this.SellIceCreamButton.UseVisualStyleBackColor = true;
this.SellIceCreamButton.Click += new System.EventHandler(this.SellIceCreamButton_Click);
//
// FormMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1072, 347);
this.Controls.Add(this.SellIceCreamButton);
this.Controls.Add(this.buttonSupplyShop);
this.Controls.Add(this.buttonUpdate);
this.Controls.Add(this.buttonSetToFinish);
@ -202,5 +215,6 @@
private ToolStripMenuItem мороженоеToolStripMenuItem;
private ToolStripMenuItem магазиныToolStripMenuItem;
private Button buttonSupplyShop;
private Button SellIceCreamButton;
}
}

View File

@ -181,5 +181,15 @@ namespace IceCreamShopView
form.ShowDialog();
}
}
private void SellIceCreamButton_Click(object sender, EventArgs e)
{
var service = Program.ServiceProvider?.GetService(typeof(FormSellIceCream));
if (service is FormSellIceCream form)
{
form.ShowDialog();
}
}
}
}

View File

@ -0,0 +1,120 @@
namespace IceCreamShopView
{
partial class FormSellIceCream
{
/// <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.ButtonCancel = new System.Windows.Forms.Button();
this.SaveButton = new System.Windows.Forms.Button();
this.QuantityTextBox = new System.Windows.Forms.TextBox();
this.IceCreamСomboBox = new System.Windows.Forms.ComboBox();
this.QuantityLabel = new System.Windows.Forms.Label();
this.IceCreamLabel = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// ButtonCancel
//
this.ButtonCancel.Location = new System.Drawing.Point(169, 97);
this.ButtonCancel.Name = "ButtonCancel";
this.ButtonCancel.Size = new System.Drawing.Size(97, 29);
this.ButtonCancel.TabIndex = 11;
this.ButtonCancel.Text = "Отмена";
this.ButtonCancel.UseVisualStyleBackColor = true;
this.ButtonCancel.Click += new System.EventHandler(this.ButtonCancel_Click);
//
// SaveButton
//
this.SaveButton.Location = new System.Drawing.Point(66, 97);
this.SaveButton.Name = "SaveButton";
this.SaveButton.Size = new System.Drawing.Size(97, 29);
this.SaveButton.TabIndex = 10;
this.SaveButton.Text = "Сохранить";
this.SaveButton.UseVisualStyleBackColor = true;
this.SaveButton.Click += new System.EventHandler(this.SaveButton_Click);
//
// QuantityTextBox
//
this.QuantityTextBox.Location = new System.Drawing.Point(82, 45);
this.QuantityTextBox.Name = "QuantityTextBox";
this.QuantityTextBox.Size = new System.Drawing.Size(184, 23);
this.QuantityTextBox.TabIndex = 9;
//
// IceCreamСomboBox
//
this.IceCreamСomboBox.FormattingEnabled = true;
this.IceCreamСomboBox.Location = new System.Drawing.Point(82, 12);
this.IceCreamСomboBox.Name = "IceCreamСomboBox";
this.IceCreamСomboBox.Size = new System.Drawing.Size(184, 23);
this.IceCreamСomboBox.TabIndex = 8;
//
// QuantityLabel
//
this.QuantityLabel.AutoSize = true;
this.QuantityLabel.Location = new System.Drawing.Point(6, 48);
this.QuantityLabel.Name = "QuantityLabel";
this.QuantityLabel.Size = new System.Drawing.Size(75, 15);
this.QuantityLabel.TabIndex = 7;
this.QuantityLabel.Text = "Количество:";
//
// IceCreamLabel
//
this.IceCreamLabel.AutoSize = true;
this.IceCreamLabel.Location = new System.Drawing.Point(6, 15);
this.IceCreamLabel.Name = "IceCreamLabel";
this.IceCreamLabel.Size = new System.Drawing.Size(74, 15);
this.IceCreamLabel.TabIndex = 6;
this.IceCreamLabel.Text = "Мороженое";
//
// FormSellIceCream
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(278, 135);
this.Controls.Add(this.ButtonCancel);
this.Controls.Add(this.SaveButton);
this.Controls.Add(this.QuantityTextBox);
this.Controls.Add(this.IceCreamСomboBox);
this.Controls.Add(this.QuantityLabel);
this.Controls.Add(this.IceCreamLabel);
this.Name = "FormSellIceCream";
this.Text = "Продать мороженое";
this.Load += new System.EventHandler(this.FormSellIceCream_Load);
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private Button ButtonCancel;
private Button SaveButton;
private TextBox QuantityTextBox;
private ComboBox IceCreamСomboBox;
private Label QuantityLabel;
private Label IceCreamLabel;
}
}

View File

@ -0,0 +1,92 @@
using IceCreamShopContracts.SearchModels;
using IceCreamShopContracts.BusinessLogicsContracts;
using Microsoft.Extensions.Logging;
using IceCreamShopContracts.BindingModels;
namespace IceCreamShopView
{
public partial class FormSellIceCream : Form
{
private readonly ILogger _logger;
private readonly IIceCreamLogic _logicI;
private readonly IShopLogic _logicS;
public FormSellIceCream(ILogger<FormSellIceCream> logger, IIceCreamLogic logicIceCream, IShopLogic logicShop)
{
InitializeComponent();
_logger = logger;
_logicI = logicIceCream;
_logicS = logicShop;
}
private void SaveButton_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(QuantityTextBox.Text))
{
MessageBox.Show("Укажите количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (IceCreamСomboBox.SelectedValue == null)
{
MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
_logger.LogInformation("Product sale.");
try
{
var operationResult = _logicS.SellIceCreams(
new IceCreamBindingModel
{
Id = Convert.ToInt32(IceCreamСomboBox.SelectedValue)
},
Convert.ToInt32(QuantityTextBox.Text)
);
if (!operationResult)
{
throw new Exception("Ошибка при продаже изделия. Дополнительная информация в логах.");
}
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK;
Close();
}
catch (Exception ex)
{
_logger.LogError(ex, "Product sale error.");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ButtonCancel_Click(object sender, EventArgs e)
{
DialogResult = DialogResult.Cancel;
Close();
}
private void FormSellIceCream_Load(object sender, EventArgs e)
{
_logger.LogInformation("Loading icecream for sale.");
try
{
var list = _logicI.ReadList(null);
if (list != null)
{
IceCreamСomboBox.DisplayMember = "IceCreamName";
IceCreamСomboBox.ValueMember = "Id";
IceCreamСomboBox.DataSource = list;
IceCreamСomboBox.SelectedItem = null;
}
}
catch (Exception ex)
{
_logger.LogError(ex, "List loading error.");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}

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

@ -31,21 +31,25 @@
this.buttonCancel = new System.Windows.Forms.Button();
this.buttonSave = new System.Windows.Forms.Button();
this.dataGridView = new System.Windows.Forms.DataGridView();
this.ColumnId = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.ColumnDocumentName = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.dateTimePicker = new System.Windows.Forms.DateTimePicker();
this.labelOpeningDate = new System.Windows.Forms.Label();
this.textBoxAddress = new System.Windows.Forms.TextBox();
this.textBoxName = new System.Windows.Forms.TextBox();
this.labelAddress = new System.Windows.Forms.Label();
this.labelName = new System.Windows.Forms.Label();
this.IceCreamMaxCountLable = new System.Windows.Forms.Label();
this.VolumeNumericUpDown = new System.Windows.Forms.NumericUpDown();
this.ColumnId = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.ColumnDocumentName = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.PriceIceCream = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.ColumnCount = new System.Windows.Forms.DataGridViewTextBoxColumn();
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.VolumeNumericUpDown)).BeginInit();
this.SuspendLayout();
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(197, 338);
this.buttonCancel.Location = new System.Drawing.Point(332, 389);
this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(136, 22);
@ -56,7 +60,7 @@
//
// buttonSave
//
this.buttonSave.Location = new System.Drawing.Point(39, 338);
this.buttonSave.Location = new System.Drawing.Point(39, 387);
this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(136, 22);
@ -71,43 +75,22 @@
this.dataGridView.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.ColumnId,
this.ColumnDocumentName,
this.PriceIceCream,
this.ColumnCount});
this.dataGridView.Location = new System.Drawing.Point(9, 106);
this.dataGridView.Location = new System.Drawing.Point(9, 155);
this.dataGridView.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.dataGridView.Name = "dataGridView";
this.dataGridView.RowHeadersWidth = 51;
this.dataGridView.RowTemplate.Height = 29;
this.dataGridView.Size = new System.Drawing.Size(351, 225);
this.dataGridView.Size = new System.Drawing.Size(504, 225);
this.dataGridView.TabIndex = 19;
//
// ColumnId
//
this.ColumnId.HeaderText = "ID";
this.ColumnId.MinimumWidth = 6;
this.ColumnId.Name = "ColumnId";
this.ColumnId.Visible = false;
this.ColumnId.Width = 125;
//
// ColumnDocumentName
//
this.ColumnDocumentName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
this.ColumnDocumentName.HeaderText = "Документ";
this.ColumnDocumentName.MinimumWidth = 6;
this.ColumnDocumentName.Name = "ColumnDocumentName";
//
// ColumnCount
//
this.ColumnCount.HeaderText = "Количество";
this.ColumnCount.MinimumWidth = 6;
this.ColumnCount.Name = "ColumnCount";
this.ColumnCount.Width = 125;
//
// dateTimePicker
//
this.dateTimePicker.Location = new System.Drawing.Point(141, 63);
this.dateTimePicker.Location = new System.Drawing.Point(155, 63);
this.dateTimePicker.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.dateTimePicker.Name = "dateTimePicker";
this.dateTimePicker.Size = new System.Drawing.Size(219, 23);
this.dateTimePicker.Size = new System.Drawing.Size(205, 23);
this.dateTimePicker.TabIndex = 18;
//
// labelOpeningDate
@ -153,11 +136,56 @@
this.labelName.TabIndex = 13;
this.labelName.Text = "Название:";
//
// IceCreamMaxCountLable
//
this.IceCreamMaxCountLable.AutoSize = true;
this.IceCreamMaxCountLable.Location = new System.Drawing.Point(9, 107);
this.IceCreamMaxCountLable.Name = "IceCreamMaxCountLable";
this.IceCreamMaxCountLable.Size = new System.Drawing.Size(140, 15);
this.IceCreamMaxCountLable.TabIndex = 22;
this.IceCreamMaxCountLable.Text = "Вместимость магазина: ";
//
// VolumeNumericUpDown
//
this.VolumeNumericUpDown.Location = new System.Drawing.Point(155, 105);
this.VolumeNumericUpDown.Name = "VolumeNumericUpDown";
this.VolumeNumericUpDown.Size = new System.Drawing.Size(205, 23);
this.VolumeNumericUpDown.TabIndex = 23;
//
// ColumnId
//
this.ColumnId.HeaderText = "ID";
this.ColumnId.MinimumWidth = 6;
this.ColumnId.Name = "ColumnId";
this.ColumnId.Visible = false;
this.ColumnId.Width = 125;
//
// ColumnDocumentName
//
this.ColumnDocumentName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
this.ColumnDocumentName.HeaderText = "Мороженое";
this.ColumnDocumentName.MinimumWidth = 6;
this.ColumnDocumentName.Name = "ColumnDocumentName";
//
// PriceIceCream
//
this.PriceIceCream.HeaderText = "Цена";
this.PriceIceCream.Name = "PriceIceCream";
//
// ColumnCount
//
this.ColumnCount.HeaderText = "Количество";
this.ColumnCount.MinimumWidth = 6;
this.ColumnCount.Name = "ColumnCount";
this.ColumnCount.Width = 125;
//
// FormShop
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(376, 372);
this.ClientSize = new System.Drawing.Size(525, 422);
this.Controls.Add(this.VolumeNumericUpDown);
this.Controls.Add(this.IceCreamMaxCountLable);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonSave);
this.Controls.Add(this.dataGridView);
@ -171,6 +199,7 @@
this.Text = "Магазин";
this.Load += new System.EventHandler(this.FormShop_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGridView)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.VolumeNumericUpDown)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
@ -181,14 +210,17 @@
private Button buttonCancel;
private Button buttonSave;
private DataGridView dataGridView;
private DataGridViewTextBoxColumn ColumnId;
private DataGridViewTextBoxColumn ColumnDocumentName;
private DataGridViewTextBoxColumn ColumnCount;
private DateTimePicker dateTimePicker;
private Label labelOpeningDate;
private TextBox textBoxAddress;
private TextBox textBoxName;
private Label labelAddress;
private Label labelName;
private Label IceCreamMaxCountLable;
private NumericUpDown VolumeNumericUpDown;
private DataGridViewTextBoxColumn ColumnId;
private DataGridViewTextBoxColumn ColumnDocumentName;
private DataGridViewTextBoxColumn PriceIceCream;
private DataGridViewTextBoxColumn ColumnCount;
}
}

View File

@ -47,6 +47,7 @@ namespace IceCreamShopView
textBoxAddress.Text = view.Adress;
dateTimePicker.Text = view.OpeningDate.ToString();
_shopIceCreams = view.ShopIceCreams ?? new Dictionary<int, (IIceCreamModel, int)>();
VolumeNumericUpDown.Value = view.IceCreamMaxCount;
LoadData();
}
}
@ -72,6 +73,7 @@ namespace IceCreamShopView
{
pc.Key,
pc.Value.Item1.IceCreamName,
pc.Value.Item1.Price,
pc.Value.Item2
}
);
@ -106,7 +108,8 @@ namespace IceCreamShopView
Id = _id ?? 0,
Name = textBoxName.Text,
Adress = textBoxAddress.Text,
OpeningDate = dateTimePicker.Value.Date
OpeningDate = dateTimePicker.Value.Date,
IceCreamMaxCount = (int)VolumeNumericUpDown.Value
};
var operationResult = _id.HasValue ? _logic.Update(model) : _logic.Create(model);
if (!operationResult)

View File

@ -63,6 +63,9 @@
<metadata name="ColumnDocumentName.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="PriceIceCream.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>
<metadata name="ColumnCount.UserAddedColumn" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<value>True</value>
</metadata>

View File

@ -31,7 +31,7 @@
this.buttonCancel = new System.Windows.Forms.Button();
this.buttonSave = new System.Windows.Forms.Button();
this.textBoxCount = new System.Windows.Forms.TextBox();
this.comboBoxDocument = new System.Windows.Forms.ComboBox();
this.comboBoxIceCream = new System.Windows.Forms.ComboBox();
this.comboBoxShop = new System.Windows.Forms.ComboBox();
this.labelDocumentCount = new System.Windows.Forms.Label();
this.labelDocument = new System.Windows.Forms.Label();
@ -40,9 +40,10 @@
//
// buttonCancel
//
this.buttonCancel.Location = new System.Drawing.Point(288, 179);
this.buttonCancel.Location = new System.Drawing.Point(252, 134);
this.buttonCancel.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonCancel.Name = "buttonCancel";
this.buttonCancel.Size = new System.Drawing.Size(94, 29);
this.buttonCancel.Size = new System.Drawing.Size(82, 22);
this.buttonCancel.TabIndex = 17;
this.buttonCancel.Text = "Отмена";
this.buttonCancel.UseVisualStyleBackColor = true;
@ -50,9 +51,10 @@
//
// buttonSave
//
this.buttonSave.Location = new System.Drawing.Point(187, 179);
this.buttonSave.Location = new System.Drawing.Point(164, 134);
this.buttonSave.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.buttonSave.Name = "buttonSave";
this.buttonSave.Size = new System.Drawing.Size(94, 29);
this.buttonSave.Size = new System.Drawing.Size(82, 22);
this.buttonSave.TabIndex = 16;
this.buttonSave.Text = "Сохранить";
this.buttonSave.UseVisualStyleBackColor = true;
@ -60,71 +62,73 @@
//
// textBoxCount
//
this.textBoxCount.Location = new System.Drawing.Point(131, 119);
this.textBoxCount.Location = new System.Drawing.Point(115, 89);
this.textBoxCount.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.textBoxCount.Name = "textBoxCount";
this.textBoxCount.Size = new System.Drawing.Size(125, 27);
this.textBoxCount.Size = new System.Drawing.Size(110, 23);
this.textBoxCount.TabIndex = 15;
//
// comboBoxDocument
// comboBoxIceCream
//
this.comboBoxDocument.FormattingEnabled = true;
this.comboBoxDocument.Location = new System.Drawing.Point(131, 65);
this.comboBoxDocument.Name = "comboBoxDocument";
this.comboBoxDocument.Size = new System.Drawing.Size(251, 28);
this.comboBoxDocument.TabIndex = 14;
this.comboBoxIceCream.FormattingEnabled = true;
this.comboBoxIceCream.Location = new System.Drawing.Point(115, 49);
this.comboBoxIceCream.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.comboBoxIceCream.Name = "comboBoxIceCream";
this.comboBoxIceCream.Size = new System.Drawing.Size(220, 23);
this.comboBoxIceCream.TabIndex = 14;
//
// comboBoxShop
//
this.comboBoxShop.FormattingEnabled = true;
this.comboBoxShop.Location = new System.Drawing.Point(131, 15);
this.comboBoxShop.Location = new System.Drawing.Point(115, 11);
this.comboBoxShop.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.comboBoxShop.Name = "comboBoxShop";
this.comboBoxShop.Size = new System.Drawing.Size(251, 28);
this.comboBoxShop.Size = new System.Drawing.Size(220, 23);
this.comboBoxShop.TabIndex = 13;
//
// labelDocumentCount
//
this.labelDocumentCount.AutoSize = true;
this.labelDocumentCount.Location = new System.Drawing.Point(9, 119);
this.labelDocumentCount.Location = new System.Drawing.Point(8, 89);
this.labelDocumentCount.Name = "labelDocumentCount";
this.labelDocumentCount.Size = new System.Drawing.Size(93, 20);
this.labelDocumentCount.Size = new System.Drawing.Size(75, 15);
this.labelDocumentCount.TabIndex = 12;
this.labelDocumentCount.Text = "Количество:";
//
// labelDocument
//
this.labelDocument.AutoSize = true;
this.labelDocument.Location = new System.Drawing.Point(9, 68);
this.labelDocument.Location = new System.Drawing.Point(8, 51);
this.labelDocument.Name = "labelDocument";
this.labelDocument.Size = new System.Drawing.Size(97, 20);
this.labelDocument.Size = new System.Drawing.Size(77, 15);
this.labelDocument.TabIndex = 11;
this.labelDocument.Text = "Мороженое:";
//
// labelShop
//
this.labelShop.AutoSize = true;
this.labelShop.Location = new System.Drawing.Point(9, 15);
this.labelShop.Location = new System.Drawing.Point(8, 11);
this.labelShop.Name = "labelShop";
this.labelShop.RightToLeft = System.Windows.Forms.RightToLeft.No;
this.labelShop.Size = new System.Drawing.Size(72, 20);
this.labelShop.Size = new System.Drawing.Size(57, 15);
this.labelShop.TabIndex = 10;
this.labelShop.Text = "Магазин:";
//
// FormShopSupply
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(405, 220);
this.ClientSize = new System.Drawing.Size(354, 165);
this.Controls.Add(this.buttonCancel);
this.Controls.Add(this.buttonSave);
this.Controls.Add(this.textBoxCount);
this.Controls.Add(this.comboBoxDocument);
this.Controls.Add(this.comboBoxIceCream);
this.Controls.Add(this.comboBoxShop);
this.Controls.Add(this.labelDocumentCount);
this.Controls.Add(this.labelDocument);
this.Controls.Add(this.labelShop);
this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
this.Name = "FormShopSupply";
this.Text = "FormShopSupply";
this.Text = "Пополнение магазина";
this.Load += new System.EventHandler(this.FormShopSupply_Load);
this.ResumeLayout(false);
this.PerformLayout();
@ -136,7 +140,7 @@
private Button buttonCancel;
private Button buttonSave;
private TextBox textBoxCount;
private ComboBox comboBoxDocument;
private ComboBox comboBoxIceCream;
private ComboBox comboBoxShop;
private Label labelDocumentCount;
private Label labelDocument;

View File

@ -33,7 +33,7 @@ namespace IceCreamShopView
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
if (comboBoxDocument.SelectedValue == null)
if (comboBoxIceCream.SelectedValue == null)
{
MessageBox.Show("Выберите мороженое", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
@ -54,8 +54,8 @@ namespace IceCreamShopView
},
new IceCreamBindingModel
{
Id = Convert.ToInt32(comboBoxDocument.SelectedValue),
IceCreamName = comboBoxDocument.Text
Id = Convert.ToInt32(comboBoxIceCream.SelectedValue),
IceCreamName = comboBoxIceCream.Text
},
Convert.ToInt32(textBoxCount.Text)
);
@ -88,10 +88,10 @@ namespace IceCreamShopView
var list = _logicI.ReadList(null);
if (list != null)
{
comboBoxDocument.DisplayMember = "IceCreamName";
comboBoxDocument.ValueMember = "Id";
comboBoxDocument.DataSource = list;
comboBoxDocument.SelectedItem = null;
comboBoxIceCream.DisplayMember = "IceCreamName";
comboBoxIceCream.ValueMember = "Id";
comboBoxIceCream.DataSource = list;
comboBoxIceCream.SelectedItem = null;
}
}

View File

@ -16,6 +16,7 @@
<ItemGroup>
<ProjectReference Include="..\IceCreamBusinessLogic\IceCreamBusinessLogic.csproj" />
<ProjectReference Include="..\IceCreamShopContracts\IceCreamShopContracts.csproj" />
<ProjectReference Include="..\IceCreamShopFileImplement\IceCreamShopFileImplement.csproj" />
<ProjectReference Include="..\IceCreamShopListImplement\IceCreamShopListImplement.csproj" />
</ItemGroup>

View File

@ -1,11 +1,11 @@
using IceCreamShopContracts.BusinessLogicsContracts;
using IceCreamShopContracts.StoragesContracts;
using IceCreamShopListImplement.Implements;
using IceCreamBusinessLogic.BusinessLogics;
using IceCreamShopView;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using NLog.Extensions.Logging;
using IceCreamShopFileImplement.Implements;
namespace IceCreamShop
{
@ -54,6 +54,7 @@ namespace IceCreamShop
services.AddTransient<FormShop>();
services.AddTransient<FormShops>();
services.AddTransient<FormShopSupply>();
services.AddTransient<FormSellIceCream>();
}
}
}

View File

@ -1,122 +0,0 @@
using AbstractShopContracts.BindingModels;
using AbstractShopContracts.BusinessLogicsContracts;
using AbstractShopContracts.SearchModels;
using AbstractShopContracts.StoragesContracts;
using AbstractShopContracts.ViewModels;
using Microsoft.Extensions.Logging;
using IceCreamShopContracts.BindingModels;
namespace IceCreamShopBusinessLogic.BusinessLogics
{
public class ComponentLogic : IComponentLogic
{
private readonly ILogger _logger;
private readonly IComponentStorage _componentStorage;
public ComponentLogic(ILogger<ComponentLogic> logger, IComponentStorage
componentStorage)
{
_logger = logger;
_componentStorage = componentStorage;
}
public List<ComponentViewModel>? ReadList(ComponentSearchModel? model)
{
_logger.LogInformation("ReadList. ComponentName:{ComponentName}.
Id:{ Id}
", model?.ComponentName, model?.Id);
var list = model == null ? _componentStorage.GetFullList() :
_componentStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
return list;
}
public ComponentViewModel? ReadElement(ComponentSearchModel model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
_logger.LogInformation("ReadElement. ComponentName:{ComponentName}.
Id:{ Id}
", model.ComponentName, model.Id);
var element = _componentStorage.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(ComponentBindingModel model)
{
CheckModel(model);
if (_componentStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
return true;
}
public bool Update(ComponentBindingModel model)
{
CheckModel(model);
if (_componentStorage.Update(model) == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
return true;
}
public bool Delete(ComponentBindingModel model)
{
CheckModel(model, false);
_logger.LogInformation("Delete. Id:{Id}", model.Id);
if (_componentStorage.Delete(model) == null)
{
_logger.LogWarning("Delete operation failed");
return false;
}
return true;
}
private void CheckModel(ComponentBindingModel model, bool withParams =
true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.ComponentName))
{
throw new ArgumentNullException("Нет названия компонента",
nameof(model.ComponentName));
}
if (model.Cost <= 0)
{
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("Компонент с таким названием
уже есть");
}
}
}
}

View File

@ -17,5 +17,6 @@ namespace IceCreamShopContracts.BindingModels
public DateTime OpeningDate { get; set; }
public Dictionary<int, (IIceCreamModel, int)> ShopIceCreams { get; set; } = new();
public int IceCreamMaxCount { get; set; }
}
}

View File

@ -18,5 +18,6 @@ namespace IceCreamShopContracts.BusinessLogicsContracts
bool Update(ShopBindingModel model);
bool Delete(ShopBindingModel model);
bool SupplyIceCreams(ShopSearchModel model, IIceCreamModel iceCream, int count);
bool SellIceCreams(IIceCreamModel iceCream, int count);
}
}

View File

@ -1,4 +1,5 @@
using IceCreamShopContracts.BindingModels;
using AbstractIceCreamShopDataModels.Models;
using IceCreamShopContracts.BindingModels;
using IceCreamShopContracts.SearchModels;
using IceCreamShopContracts.ViewModels;
using System;
@ -17,5 +18,6 @@ namespace IceCreamShopContracts.StoragesContracts
ShopViewModel? Insert(ShopBindingModel model);
ShopViewModel? Update(ShopBindingModel model);
ShopViewModel? Delete(ShopBindingModel model);
bool SellIceCreams(IIceCreamModel iceCream, int count);
}
}

View File

@ -17,6 +17,8 @@ namespace IceCreamShopContracts.ViewModels
public string Adress { get; set; } = string.Empty;
[DisplayName("Дата открытия")]
public DateTime OpeningDate { get; set; }
[DisplayName("Вместимость магазина")]
public int IceCreamMaxCount { get; set; }
public Dictionary<int, (IIceCreamModel, int)> ShopIceCreams { get; set; } = new();
}

View File

@ -14,5 +14,6 @@ namespace AbstractIceCreamShopDataModels.Models
String Adress { get; }
DateTime OpeningDate { get; }
Dictionary<int, (IIceCreamModel, int)> ShopIceCreams { get; }
public int IceCreamMaxCount { get; }
}
}

View File

@ -0,0 +1,53 @@
using IceCreamShopFileImplement.Models;
using System.Xml.Linq;
namespace IceCreamShopFileImplement
{
public class DataFileSingleton
{
private static DataFileSingleton? instance;
private readonly string ComponentFileName = "Component.xml";
private readonly string OrderFileName = "Order.xml";
private readonly string IceCreamFileName = "IceCream.xml";
private readonly string ShopFileName = "Shop.xml";
public List<Component> Components { get; private set; }
public List<Order> Orders { get; private set; }
public List<IceCream> IceCreams { 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 SaveIceCreams() => SaveData(IceCreams, IceCreamFileName, "IceCreams", 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)!)!;
IceCreams = LoadData(IceCreamFileName, "IceCream", x => IceCream.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

@ -1,7 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
@ -9,6 +8,7 @@
<ItemGroup>
<ProjectReference Include="..\IceCreamShopContracts\IceCreamShopContracts.csproj" />
<ProjectReference Include="..\IceCreamShopDataModels\IceCreamShopDataModels.csproj" />
</ItemGroup>
</Project>

View File

@ -0,0 +1,78 @@
using IceCreamShopContracts.BindingModels;
using IceCreamShopContracts.SearchModels;
using IceCreamShopContracts.StoragesContracts;
using IceCreamShopContracts.ViewModels;
using IceCreamShopFileImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace IceCreamShopFileImplement.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 IceCreamShopContracts.BindingModels;
using IceCreamShopContracts.SearchModels;
using IceCreamShopContracts.StoragesContracts;
using IceCreamShopContracts.ViewModels;
using IceCreamShopFileImplement.Models;
using System;
using System.Collections.Generic;
using System.Diagnostics.SymbolStore;
using System.Linq;
using System.Reflection.Metadata;
using System.Text;
using System.Threading.Tasks;
namespace IceCreamShopFileImplement.Implements
{
public class IceCreamStorage : IIceCreamStorage
{
private readonly DataFileSingleton source;
public IceCreamStorage()
{
source = DataFileSingleton.GetInstance();
}
public IceCreamViewModel? GetElement(IceCreamSearchModel model)
{
if (string.IsNullOrEmpty(model.IceCreamName) && !model.Id.HasValue)
{
return null;
}
return source.IceCreams.FirstOrDefault(x => (!string.IsNullOrEmpty(model.IceCreamName) && x.IceCreamName == model.IceCreamName) || (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public List<IceCreamViewModel> GetFilteredList(IceCreamSearchModel model)
{
if (string.IsNullOrEmpty(model.IceCreamName))
{
return new();
}
return source.IceCreams.Where(x => x.IceCreamName.Contains(model.IceCreamName)).Select(x => x.GetViewModel).ToList();
}
public List<IceCreamViewModel> GetFullList()
{
return source.IceCreams.Select(x => x.GetViewModel).ToList();
}
public IceCreamViewModel? Insert(IceCreamBindingModel model)
{
model.Id = source.IceCreams.Count > 0 ? source.IceCreams.Max(x => x.Id) + 1 : 1;
var newDoc = IceCream.Create(model);
if (newDoc == null)
{
return null;
}
source.IceCreams.Add(newDoc);
source.SaveIceCreams();
return newDoc.GetViewModel;
}
public IceCreamViewModel? Update(IceCreamBindingModel model)
{
var iceCream = source.IceCreams.FirstOrDefault(x => x.Id == model.Id);
if (iceCream == null)
{
return null;
}
iceCream.Update(model);
source.SaveIceCreams();
return iceCream.GetViewModel;
}
public IceCreamViewModel? Delete(IceCreamBindingModel model)
{
var document = source.IceCreams.FirstOrDefault(x => x.Id == model.Id);
if (document == null)
{
return null;
}
document.Update(model);
source.SaveIceCreams();
return document.GetViewModel;
}
}
}

View File

@ -0,0 +1,97 @@
using IceCreamShopContracts.BindingModels;
using IceCreamShopContracts.SearchModels;
using IceCreamShopContracts.StoragesContracts;
using IceCreamShopContracts.ViewModels;
using IceCreamShopFileImplement.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace IceCreamShopFileImplement.Implements
{
public class OrderStorage : IOrderStorage
{
private readonly DataFileSingleton source;
public OrderStorage()
{
source = DataFileSingleton.GetInstance();
}
public OrderViewModel? GetElement(OrderSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
return source.Orders
.FirstOrDefault(x => (model.Id.HasValue && x.Id == model.Id))?.GetViewModel;
}
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
{
if (!model.Id.HasValue)
{
return new();
}
return source.Orders
.Where(x => x.Id == model.Id)
.Select(x => x.GetViewModel)
.ToList();
}
public List<OrderViewModel> GetFullList()
{
return source.Orders.Select(x => GetViewModel(x)).ToList();
}
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 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 order.GetViewModel;
}
public OrderViewModel? Delete(OrderBindingModel model)
{
var order = source.Orders.FirstOrDefault(x => x.Id == model.Id);
if (order == null)
{
return null;
}
order.Update(model);
source.SaveOrders();
return order.GetViewModel;
}
private OrderViewModel GetViewModel(Order order)
{
var viewModel = order.GetViewModel;
var document = source.IceCreams.FirstOrDefault(x => x.Id == order.IceCreamId);
if (document != null)
{
viewModel.IceCreamName = document.IceCreamName;
}
return viewModel;
}
}
}

View File

@ -0,0 +1,152 @@
using IceCreamShopContracts.StoragesContracts;
using IceCreamShopContracts.BindingModels;
using IceCreamShopContracts.SearchModels;
using IceCreamShopContracts.ViewModels;
using AbstractIceCreamShopDataModels.Models;
using IceCreamShopFileImplement.Models;
using System.Reflection.Metadata;
using System.Reflection;
namespace IceCreamShopFileImplement.Implements
{
public class ShopStorage : IShopStorage
{
private readonly DataFileSingleton source;
public ShopStorage()
{
source = DataFileSingleton.GetInstance();
}
public ShopViewModel? Delete(ShopBindingModel model)
{
var element = source.Shops.FirstOrDefault(x => x.Id == model.Id);
if (element == null)
{
return null;
}
source.Shops.Remove(element);
source.SaveShops();
return element.GetViewModel;
}
public ShopViewModel? GetElement(ShopSearchModel model)
{
if (!model.Id.HasValue)
{
return null;
}
return source.Shops.FirstOrDefault(x => model.Id.HasValue && x.Id == model.Id)?.GetViewModel;
}
public List<ShopViewModel> GetFilteredList(ShopSearchModel model)
{
if (string.IsNullOrEmpty(model.Name))
{
return new();
}
return source.Shops
.Select(x => x.GetViewModel)
.Where(x => x.Name.Contains(model.Name ?? string.Empty))
.ToList();
}
public List<ShopViewModel> GetFullList()
{
return source.Shops.Select(x => x.GetViewModel).ToList();
}
public ShopViewModel? Insert(ShopBindingModel model)
{
model.Id = source.Shops.Count > 0 ? source.Shops.Max(x => x.Id) + 1 : 1;
var newStore = Shop.Create(model);
if (newStore == null)
{
return null;
}
source.Shops.Add(newStore);
source.SaveShops();
return newStore.GetViewModel;
}
public ShopViewModel? Update(ShopBindingModel model)
{
var store = source.Shops.FirstOrDefault(x => x.Id == model.Id);
if (store == null)
{
return null;
}
store.Update(model);
source.SaveShops();
return store.GetViewModel;
}
public bool SellIceCreams(IIceCreamModel model, int count)
{
var iceCream = source.IceCreams.FirstOrDefault(x => x.Id == model.Id);
var countStore = count;
if (iceCream == null)
{
return false;
}
foreach (var shop in source.Shops)
Review

Значение можно получить через LINQ-запрос

Значение можно получить через LINQ-запрос
{
foreach (var icecream in shop.ShopIceCreams)
{
if (icecream.Value.Item1.Id == iceCream.Id)
{
count -= icecream.Value.Item2;
}
if (count <= 0)
{
break;
}
}
}
if (count > 0)
{
return false;
}
count = countStore;
for (int i = 0; i < source.Shops.Count; i++)
{
var shop = source.Shops[i];
var icecreams = shop.ShopIceCreams;
foreach (var icecream in icecreams.Where(x => x.Value.Item1.Id == iceCream.Id))
{
var min = Math.Min(icecream.Value.Item2, count);
icecreams[icecream.Value.Item1.Id] = (icecream.Value.Item1, icecream.Value.Item2 - min);
count -= min;
if (count <= 0)
{
break;
}
}
shop.Update(new ShopBindingModel
{
Id = shop.Id,
Name = shop.Name,
Adress = shop.Adress,
OpeningDate = shop.OpeningDate,
IceCreamMaxCount = shop.IceCreamMaxCount,
ShopIceCreams = icecreams
});
source.SaveShops();
}
if (count > 0)
{
return false;
}
return true;
}
}
}

View File

@ -0,0 +1,64 @@
using IceCreamShopContracts.BindingModels;
using IceCreamShopContracts.ViewModels;
using AbstractIceCreamShopDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace IceCreamShopFileImplement.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,88 @@
using IceCreamShopContracts.BindingModels;
using IceCreamShopContracts.ViewModels;
using AbstractIceCreamShopDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace IceCreamShopFileImplement.Models
{
public class IceCream : IIceCreamModel
{
public int Id { get; private set; }
public string IceCreamName { 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)>? _iceCreamComponents = null;
public Dictionary<int, (IComponentModel, int)> IceCreamComponents
{
get
{
if (_iceCreamComponents == null)
{
var source = DataFileSingleton.GetInstance();
_iceCreamComponents = Components.ToDictionary(x => x.Key, y =>
((source.Components.FirstOrDefault(z => z.Id == y.Key) as IComponentModel)!, y.Value));
}
return _iceCreamComponents;
}
}
public static IceCream? Create(IceCreamBindingModel model)
{
if (model == null)
{
return null;
}
return new IceCream()
{
Id = model.Id,
IceCreamName = model.IceCreamName,
Price = model.Price,
Components = model.IceCreamComponents.ToDictionary(x => x.Key, x => x.Value.Item2)
};
}
public static IceCream? Create(XElement element)
{
if (element == null)
{
return null;
}
return new IceCream()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
IceCreamName = element.Element("IceCreamName")!.Value,
Price = Convert.ToDouble(element.Element("Price")!.Value),
Components = element.Element("IceCreamComponents")!.Elements("IceCreamComponent")
.ToDictionary(x => Convert.ToInt32(x.Element("Key")?.Value), x =>
Convert.ToInt32(x.Element("Value")?.Value))
};
}
public void Update(IceCreamBindingModel model)
{
if (model == null)
{
return;
}
IceCreamName = model.IceCreamName;
Price = model.Price;
Components = model.IceCreamComponents.ToDictionary(x => x.Key, x => x.Value.Item2);
_iceCreamComponents = null;
}
public IceCreamViewModel GetViewModel => new()
{
Id = Id,
IceCreamName = IceCreamName,
Price = Price,
IceCreamComponents = IceCreamComponents
};
public XElement GetXElement => new("IceCream",
new XAttribute("Id", Id),
new XElement("IceCreamName", IceCreamName),
new XElement("Price", Price.ToString()),
new XElement("IceCreamComponents", Components.Select(x =>
new XElement("IceCreamComponent", new XElement("Key", x.Key), new XElement("Value", x.Value))).ToArray()));
}
}

View File

@ -0,0 +1,104 @@
using IceCreamShopContracts.BindingModels;
using IceCreamShopContracts.ViewModels;
using AbstractIceCreamShopDataModels.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using AbstractIceCreamShopDataModels.Enums;
using System.Xml.Linq;
using System.Reflection.Metadata;
namespace IceCreamShopFileImplement.Models
{
public class Order : IOrderModel
{
public int Id { get; private set; }
public int IceCreamId { get; private set; }
public string IceCreamName { get; private set; } = string.Empty;
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,
IceCreamId = model.IceCreamId,
IceCreamName = model.IceCreamName,
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;
}
return new Order()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
IceCreamId = Convert.ToInt32(element.Element("IceCreamId")!.Value),
IceCreamName = element.Element("IceCreamName")!.Value,
Sum = Convert.ToDouble(element.Element("Sum")!.Value),
Count = Convert.ToInt32(element.Element("Count")!.Value),
Status = (OrderStatus)Enum.Parse(typeof(OrderStatus), element.Element("Status")!.Value),
DateCreate = Convert.ToDateTime(element.Element("DateCreate")!.Value),
DateImplement = string.IsNullOrEmpty(element.Element("DateImplement")!.Value) ? null : Convert.ToDateTime(element.Element("DateImplement")!.Value)
};
}
public void Update(OrderBindingModel? model)
{
if (model == null)
{
return;
}
Id = model.Id;
IceCreamId = model.IceCreamId;
IceCreamName = model.IceCreamName;
Count = model.Count;
Sum = model.Sum;
Status = model.Status;
DateCreate = model.DateCreate;
DateImplement = model.DateImplement;
}
public OrderViewModel GetViewModel => new()
{
Id = Id,
IceCreamId = IceCreamId,
IceCreamName = IceCreamName,
Count = Count,
Sum = Sum,
Status = Status,
DateCreate = DateCreate,
DateImplement = DateImplement,
};
public XElement GetXElement => new(
"Order",
new XAttribute("Id", Id),
new XElement("IceCreamId", IceCreamId.ToString()),
new XElement("IceCreamName", IceCreamName),
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,116 @@
using IceCreamShopContracts.BindingModels;
using IceCreamShopContracts.ViewModels;
using AbstractIceCreamShopDataModels.Models;
using System.Xml.Linq;
using System.Reflection.Metadata;
namespace IceCreamShopFileImplement.Models
{
public class Shop : IShopModel
{
public int Id { get; private set; }
public string Name { get; private set; } = string.Empty;
public string Adress { get; private set; } = string.Empty;
public DateTime OpeningDate { get; private set; }
public int IceCreamMaxCount { get; private set; }
public Dictionary<int, int> IceCreams { get; private set; } = new();
private Dictionary<int, (IIceCreamModel, int)>? _shopIceCreams = null;
public Dictionary<int, (IIceCreamModel, int)> ShopIceCreams
{
get
{
if(_shopIceCreams == null)
{
var source = DataFileSingleton.GetInstance();
_shopIceCreams = IceCreams.ToDictionary(
x => x.Key,
y => ((source.IceCreams.FirstOrDefault(z => z.Id == y.Key) as IIceCreamModel)!, y.Value));
}
return _shopIceCreams;
}
}
public static Shop? Create(ShopBindingModel? model)
{
if (model == null)
{
return null;
}
return new Shop()
{
Id = model.Id,
Name = model.Name,
Adress = model.Adress,
IceCreamMaxCount = model.IceCreamMaxCount,
OpeningDate = model.OpeningDate,
IceCreams = model.ShopIceCreams.ToDictionary(x => x.Key, x => x.Value.Item2)
};
}
public static Shop? Create(XElement element)
{
if (element == null)
{
return null;
}
return new()
{
Id = Convert.ToInt32(element.Attribute("Id")!.Value),
Name = element.Element("Name")!.Value,
Adress = element.Element("Adress")!.Value,
IceCreamMaxCount = Convert.ToInt32(element.Element("IceCreamMaxCount")!.Value),
OpeningDate = Convert.ToDateTime(element.Element("OpeningDate")!.Value),
IceCreams = element.Element("ShopIceCreams")!.Elements("ShopIceCream").ToDictionary(
x => Convert.ToInt32(x.Element("Key")?.Value),
x => Convert.ToInt32(x.Element("Value")?.Value))
};
}
public void Update(ShopBindingModel? model)
{
if (model == null)
{
return;
}
Name = model.Name;
Adress = model.Adress;
OpeningDate = model.OpeningDate;
IceCreamMaxCount = model.IceCreamMaxCount;
if(model.ShopIceCreams.Count > 0)
{
IceCreams = model.ShopIceCreams.ToDictionary(x => x.Key, x => x.Value.Item2);
_shopIceCreams = null;
}
}
public ShopViewModel GetViewModel => new()
{
Id = Id,
Name = Name,
Adress = Adress,
OpeningDate = OpeningDate,
IceCreamMaxCount = IceCreamMaxCount,
ShopIceCreams = ShopIceCreams
};
public XElement GetXElement => new("Shop",
new XAttribute("Id", Id),
new XElement("Name", Name),
new XElement("Adress", Adress),
new XElement("OpeningDate", OpeningDate),
new XElement("IceCreamMaxCount", IceCreamMaxCount),
new XElement("ShopIceCreams", IceCreams
.Select(x => new XElement("ShopIceCream",
new XElement("Key", x.Key),
new XElement("Value", x.Value))
).ToArray()));
}
}

View File

@ -1,4 +1,5 @@
using IceCreamShopContracts.BindingModels;
using AbstractIceCreamShopDataModels.Models;
using IceCreamShopContracts.BindingModels;
using IceCreamShopContracts.SearchModels;
using IceCreamShopContracts.StoragesContracts;
using IceCreamShopContracts.ViewModels;
@ -114,5 +115,10 @@ namespace IceCreamShopListImplement.Implements
}
return null;
}
public bool SellIceCreams(IIceCreamModel iceCream, int count)
{
throw new NotImplementedException();
}
}
}

View File

@ -57,5 +57,7 @@ namespace IceCreamShopListImplement.Models
OpeningDate = OpeningDate,
ShopIceCreams = ShopIceCreams
};
public int IceCreamMaxCount => throw new NotImplementedException();
}
}