Lisov N.A LabWork1 #1
@ -16,17 +16,17 @@ namespace DressAtelierBusinessLogic.BusinessLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
|
||||
private readonly IDressStorage _productStorage;
|
||||
private readonly IDressStorage _dressStorage;
|
||||
|
||||
public DressLogic(ILogger<DressLogic> logger, IDressStorage productStorage)
|
||||
public DressLogic(ILogger<DressLogic> logger, IDressStorage dressStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_productStorage = productStorage;
|
||||
_dressStorage = dressStorage;
|
||||
}
|
||||
public bool Create(DressBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if(_productStorage.Insert(model) == null)
|
||||
if(_dressStorage.Insert(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
@ -37,7 +37,7 @@ namespace DressAtelierBusinessLogic.BusinessLogic
|
||||
public bool Update(DressBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
if (_productStorage.Update(model) == null)
|
||||
if (_dressStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
@ -49,7 +49,7 @@ namespace DressAtelierBusinessLogic.BusinessLogic
|
||||
{
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Delete. ID:{ID}", model.ID);
|
||||
if (_productStorage.Delete(model) == null)
|
||||
if (_dressStorage.Delete(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Delete operation failed");
|
||||
return false;
|
||||
@ -64,9 +64,9 @@ namespace DressAtelierBusinessLogic.BusinessLogic
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
|
||||
_logger.LogInformation("ReadElement. ProductName:{ProductName}.ID:{ ID}", model.DressName, model.ID);
|
||||
_logger.LogInformation("ReadElement. DressName:{DressName}.ID:{ ID}", model.DressName, model.ID);
|
||||
|
||||
var element = _productStorage.GetElement(model);
|
||||
var element = _dressStorage.GetElement(model);
|
||||
|
||||
if (element == null)
|
||||
{
|
||||
@ -80,9 +80,9 @@ namespace DressAtelierBusinessLogic.BusinessLogic
|
||||
|
||||
public List<DressViewModel>? ReadList(DressSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. ProductName:{ProductName}. ID:{ ID}", model?.DressName, model?.ID);
|
||||
_logger.LogInformation("ReadList. DressName:{DressName}. ID:{ ID}", model?.DressName, model?.ID);
|
||||
|
||||
var list = model == null ? _productStorage.GetFullList() : _productStorage.GetFilteredList(model);
|
||||
var list = model == null ? _dressStorage.GetFullList() : _dressStorage.GetFilteredList(model);
|
||||
|
||||
if (list == null)
|
||||
{
|
||||
@ -105,15 +105,15 @@ namespace DressAtelierBusinessLogic.BusinessLogic
|
||||
}
|
||||
if (string.IsNullOrEmpty(model.DressName))
|
||||
{
|
||||
throw new ArgumentNullException("Invalid name of product",nameof(model.DressName));
|
||||
throw new ArgumentNullException("Invalid name of dress",nameof(model.DressName));
|
||||
}
|
||||
if (model.Price <= 0)
|
||||
{
|
||||
throw new ArgumentNullException("Price of product should be higher than 0", nameof(model.Price));
|
||||
throw new ArgumentNullException("Price of dress should be higher than 0", nameof(model.Price));
|
||||
}
|
||||
_logger.LogInformation("Product. ProductName:{ProductName}. Cost:{Cost}. ID: {ID}", model.DressName, model.Price, model.ID);
|
||||
_logger.LogInformation("Product. DressName:{DressName}. Cost:{Cost}. ID: {ID}", model.DressName, model.Price, model.ID);
|
||||
|
||||
var element = _productStorage.GetElement(new DressSearchModel
|
||||
var element = _dressStorage.GetElement(new DressSearchModel
|
||||
{
|
||||
DressName = model.DressName,
|
||||
});
|
||||
|
@ -46,42 +46,47 @@ namespace DressAtelierBusinessLogic.BusinessLogic
|
||||
|
||||
public bool GivenOrder(OrderBindingModel model)
|
||||
|
||||
{
|
||||
CheckModel(model);
|
||||
CheckModel(model, false);
|
||||
_logger.LogInformation("Update to given status. ID:{ID}", model.ID);
|
||||
if (_orderStorage.Update(model) == null || model.Status == OrderStatus.Ready)
|
||||
if (model.Status != OrderStatus.Ready)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
model.Status = OrderStatus.Given;
|
||||
model.DateImplement = DateTime.Now;
|
||||
_orderStorage.Update(model);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool ReadyOrder(OrderBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
CheckModel(model,false);
|
||||
_logger.LogInformation("Update to ready status. ID:{ID}", model.ID);
|
||||
if (_orderStorage.Update(model) == null || model.Status == OrderStatus.InProcess)
|
||||
if ( model.Status != OrderStatus.InProcess)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
model.Status = OrderStatus.Ready;
|
||||
model.DateImplement = DateTime.Now;
|
||||
|
||||
_orderStorage.Update(model);
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool TakeOrderInWork(OrderBindingModel model)
|
||||
{
|
||||
CheckModel(model);
|
||||
_logger.LogInformation("Update to ready status. ID:{ID}", model.ID);
|
||||
if (_orderStorage.Update(model) == null || model.Status == OrderStatus.Accepted)
|
||||
CheckModel(model,false);
|
||||
_logger.LogInformation("Update to in process status. ID:{ID}", model.ID);
|
||||
if (model.Status != OrderStatus.Accepted)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
model.Status = OrderStatus.InProcess;
|
||||
|
||||
_orderStorage.Update(model);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -100,12 +105,16 @@ namespace DressAtelierBusinessLogic.BusinessLogic
|
||||
return list;
|
||||
}
|
||||
|
||||
public void CheckModel(OrderBindingModel model)
|
||||
public void CheckModel(OrderBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
if (!withParams)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_logger.LogInformation("Order. OrderID: { ID} ",model.ID);
|
||||
|
||||
var element = _orderStorage.GetElement(new OrderSearchModel
|
||||
|
@ -10,6 +10,8 @@ namespace DressAtelierContracts.BindingModels
|
||||
{
|
||||
public class OrderBindingModel : IOrderModel
|
||||
{
|
||||
public int ID { get; set; }
|
||||
|
||||
public int DressID { get; set; }
|
||||
|
||||
public int Count { get; set; }
|
||||
@ -21,7 +23,5 @@ namespace DressAtelierContracts.BindingModels
|
||||
public DateTime DateCreate { get; set; } = DateTime.Now;
|
||||
|
||||
public DateTime? DateImplement { get; set; }
|
||||
|
||||
public int ID { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -16,7 +16,7 @@ namespace DressAtelierContracts.ViewModels
|
||||
public int DressID { get; set; }
|
||||
|
||||
[DisplayName("DressName")]
|
||||
public string DressName { get; set; } = string.Empty;
|
||||
public string DressName { get; set; }
|
||||
|
||||
[DisplayName("Quantity")]
|
||||
public int Count { get; set; }
|
||||
|
@ -12,12 +12,12 @@ namespace DressAtelierListImplement
|
||||
private static DataListSingleton? _instance;
|
||||
public List<Material> Components { get; set; }
|
||||
public List<Order> Orders { get; set; }
|
||||
public List<Dress> Products { get; set; }
|
||||
public List<Dress> Dresses { get; set; }
|
||||
private DataListSingleton()
|
||||
{
|
||||
Components = new List<Material>();
|
||||
Orders = new List<Order>();
|
||||
Products = new List<Dress>();
|
||||
Dresses = new List<Dress>();
|
||||
}
|
||||
public static DataListSingleton GetInstance()
|
||||
{
|
||||
|
@ -23,7 +23,7 @@ namespace DressAtelierListImplement.Implements
|
||||
public List<DressViewModel> GetFullList()
|
||||
{
|
||||
var result = new List<DressViewModel>();
|
||||
foreach (var material in _source.Products)
|
||||
foreach (var material in _source.Dresses)
|
||||
{
|
||||
result.Add(material.GetViewModel);
|
||||
}
|
||||
@ -37,11 +37,11 @@ namespace DressAtelierListImplement.Implements
|
||||
{
|
||||
return result;
|
||||
}
|
||||
foreach (var product in _source.Products)
|
||||
foreach (var dress in _source.Dresses)
|
||||
{
|
||||
if (product.DressName.Contains(model.DressName))
|
||||
if (dress.DressName.Contains(model.DressName))
|
||||
{
|
||||
result.Add(product.GetViewModel);
|
||||
result.Add(dress.GetViewModel);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@ -54,11 +54,11 @@ namespace DressAtelierListImplement.Implements
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach (var product in _source.Products)
|
||||
foreach (var dress in _source.Dresses)
|
||||
{
|
||||
if ((!string.IsNullOrEmpty(model.DressName) && product.DressName == model.DressName) || (model.ID.HasValue && product.ID == model.ID))
|
||||
if ((!string.IsNullOrEmpty(model.DressName) && dress.DressName == model.DressName) || (model.ID.HasValue && dress.ID == model.ID))
|
||||
{
|
||||
return product.GetViewModel;
|
||||
return dress.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@ -67,11 +67,11 @@ namespace DressAtelierListImplement.Implements
|
||||
public DressViewModel? Insert(DressBindingModel model)
|
||||
{
|
||||
model.ID = 1;
|
||||
foreach (var component in _source.Products)
|
||||
foreach (var dress in _source.Dresses)
|
||||
{
|
||||
if (model.ID <= component.ID)
|
||||
if (model.ID <= dress.ID)
|
||||
{
|
||||
model.ID = component.ID + 1;
|
||||
model.ID = dress.ID + 1;
|
||||
}
|
||||
}
|
||||
var newComponent = Dress.Create(model);
|
||||
@ -79,18 +79,18 @@ namespace DressAtelierListImplement.Implements
|
||||
{
|
||||
return null;
|
||||
}
|
||||
_source.Products.Add(newComponent);
|
||||
_source.Dresses.Add(newComponent);
|
||||
return newComponent.GetViewModel;
|
||||
}
|
||||
|
||||
public DressViewModel? Update(DressBindingModel model)
|
||||
{
|
||||
foreach (var component in _source.Products)
|
||||
foreach (var dress in _source.Dresses)
|
||||
{
|
||||
if (component.ID == model.ID)
|
||||
if (dress.ID == model.ID)
|
||||
{
|
||||
component.Update(model);
|
||||
return component.GetViewModel;
|
||||
dress.Update(model);
|
||||
return dress.GetViewModel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@ -98,12 +98,12 @@ namespace DressAtelierListImplement.Implements
|
||||
|
||||
public DressViewModel? Delete(DressBindingModel model)
|
||||
{
|
||||
for (int i = 0; i < _source.Products.Count; ++i)
|
||||
for (int i = 0; i < _source.Dresses.Count; ++i)
|
||||
{
|
||||
if (_source.Products[i].ID == model.ID)
|
||||
if (_source.Dresses[i].ID == model.ID)
|
||||
{
|
||||
var element = _source.Products[i];
|
||||
_source.Products.RemoveAt(i);
|
||||
var element = _source.Dresses[i];
|
||||
_source.Dresses.RemoveAt(i);
|
||||
return element.GetViewModel;
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ namespace DressAtelierListImplement.Implements
|
||||
var result = new List<OrderViewModel>();
|
||||
foreach (var order in _source.Orders)
|
||||
{
|
||||
result.Add(order.GetViewModel);
|
||||
result.Add(ReceiveDressName(order.GetViewModel));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -36,11 +36,11 @@ namespace DressAtelierListImplement.Implements
|
||||
{
|
||||
return result;
|
||||
}
|
||||
foreach (var component in _source.Orders)
|
||||
foreach (var order in _source.Orders)
|
||||
{
|
||||
if (component.ID == model.ID)
|
||||
if (order.ID == model.ID)
|
||||
{
|
||||
result.Add(component.GetViewModel);
|
||||
result.Add(ReceiveDressName(order.GetViewModel));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
@ -53,11 +53,11 @@ namespace DressAtelierListImplement.Implements
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach (var component in _source.Orders)
|
||||
foreach (var order in _source.Orders)
|
||||
{
|
||||
if (model.ID.HasValue && component.ID == model.ID)
|
||||
if (model.ID.HasValue && order.ID == model.ID)
|
||||
{
|
||||
return component.GetViewModel;
|
||||
return ReceiveDressName(order.GetViewModel);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@ -66,11 +66,11 @@ namespace DressAtelierListImplement.Implements
|
||||
public OrderViewModel? Insert(OrderBindingModel model)
|
||||
{
|
||||
model.ID = 1;
|
||||
foreach (var component in _source.Orders)
|
||||
foreach (var order in _source.Orders)
|
||||
{
|
||||
if (model.ID <= component.ID)
|
||||
if (model.ID <= order.ID)
|
||||
{
|
||||
model.ID = component.ID + 1;
|
||||
model.ID = order.ID + 1;
|
||||
}
|
||||
}
|
||||
var newComponent = Order.Create(model);
|
||||
@ -79,17 +79,17 @@ namespace DressAtelierListImplement.Implements
|
||||
return null;
|
||||
}
|
||||
_source.Orders.Add(newComponent);
|
||||
return newComponent.GetViewModel;
|
||||
return ReceiveDressName(newComponent.GetViewModel);
|
||||
}
|
||||
|
||||
public OrderViewModel? Update(OrderBindingModel model)
|
||||
{
|
||||
foreach (var component in _source.Orders)
|
||||
foreach (var order in _source.Orders)
|
||||
{
|
||||
if (component.ID == model.ID)
|
||||
if (order.ID == model.ID)
|
||||
{
|
||||
component.Update(model);
|
||||
return component.GetViewModel;
|
||||
order.Update(model);
|
||||
return ReceiveDressName(order.GetViewModel);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@ -103,10 +103,17 @@ namespace DressAtelierListImplement.Implements
|
||||
{
|
||||
var element = _source.Orders[i];
|
||||
_source.Orders.RemoveAt(i);
|
||||
return element.GetViewModel;
|
||||
return ReceiveDressName(element.GetViewModel);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private OrderViewModel? ReceiveDressName(OrderViewModel model)
|
||||
{
|
||||
var dress = _source.Dresses.Find(un => un.ID == model.ID);
|
||||
model.DressName = dress == null ? "" : dress.DressName;
|
||||
return model;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ namespace SewingDresses
|
||||
{
|
||||
var view = _logic.ReadElement(new DressSearchModel
|
||||
{
|
||||
ID = _id.Value
|
||||
ID = _id.Value,
|
||||
});
|
||||
if (view != null)
|
||||
{
|
||||
|
1
SewingDresses/FormDressMaterial.Designer.cs
generated
1
SewingDresses/FormDressMaterial.Designer.cs
generated
@ -58,6 +58,7 @@
|
||||
//
|
||||
// materialComboBox
|
||||
//
|
||||
this.materialComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.materialComboBox.FormattingEnabled = true;
|
||||
this.materialComboBox.Location = new System.Drawing.Point(123, 19);
|
||||
this.materialComboBox.Name = "materialComboBox";
|
||||
|
@ -1,5 +1,6 @@
|
||||
using DressAtelierContracts.BindingModels;
|
||||
using DressAtelierContracts.BusinessLogicContracts;
|
||||
using DressAtelierDataModels.Enums;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@ -91,11 +92,17 @@ namespace SewingDresses
|
||||
var operationResult = _orderLogic.TakeOrderInWork(new OrderBindingModel
|
||||
{
|
||||
//TODO
|
||||
ID = id
|
||||
ID = id,
|
||||
DressID = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["DressID"].Value),
|
||||
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
|
||||
Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
|
||||
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
|
||||
DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()),
|
||||
});
|
||||
|
||||
if (!operationResult)
|
||||
{
|
||||
MessageBox.Show("Order must be in 'Accepted' state.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
throw new Exception("Saving Error. Extra information in logs.");
|
||||
}
|
||||
LoadData();
|
||||
@ -120,11 +127,17 @@ namespace SewingDresses
|
||||
var operationResult = _orderLogic.ReadyOrder(new OrderBindingModel
|
||||
{
|
||||
//TODO
|
||||
ID = id
|
||||
ID = id,
|
||||
DressID = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["DressID"].Value),
|
||||
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
|
||||
Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
|
||||
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
|
||||
DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()),
|
||||
});
|
||||
|
||||
if (!operationResult)
|
||||
{
|
||||
MessageBox.Show("Order must be in 'InProcess' state.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
throw new Exception("Saving error. Extra information in logs.");
|
||||
}
|
||||
LoadData();
|
||||
@ -149,10 +162,16 @@ namespace SewingDresses
|
||||
var operationResult = _orderLogic.GivenOrder(new OrderBindingModel
|
||||
{
|
||||
//TODO
|
||||
ID = id
|
||||
ID = id,
|
||||
DressID = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["DressID"].Value),
|
||||
Status = Enum.Parse<OrderStatus>(dataGridView.SelectedRows[0].Cells["Status"].Value.ToString()),
|
||||
Count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value),
|
||||
Sum = double.Parse(dataGridView.SelectedRows[0].Cells["Sum"].Value.ToString()),
|
||||
DateCreate = DateTime.Parse(dataGridView.SelectedRows[0].Cells["DateCreate"].Value.ToString()),
|
||||
});
|
||||
if (!operationResult)
|
||||
{
|
||||
MessageBox.Show("Order must be in 'Ready' state.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
throw new Exception("Saving error. Extra information in logs.");
|
||||
}
|
||||
_logger.LogInformation("Order №{id} is given", id);
|
||||
|
1
SewingDresses/FormOrderCreation.Designer.cs
generated
1
SewingDresses/FormOrderCreation.Designer.cs
generated
@ -70,6 +70,7 @@
|
||||
//
|
||||
// dressComboBox
|
||||
//
|
||||
this.dressComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
|
||||
this.dressComboBox.FormattingEnabled = true;
|
||||
this.dressComboBox.Location = new System.Drawing.Point(114, 12);
|
||||
this.dressComboBox.Name = "dressComboBox";
|
||||
|
@ -58,13 +58,12 @@ namespace SewingDresses
|
||||
try
|
||||
{
|
||||
int id = Convert.ToInt32(dressComboBox.SelectedValue);
|
||||
var product = _logicDress.ReadElement(new DressSearchModel
|
||||
var dress = _logicDress.ReadElement(new DressSearchModel
|
||||
{
|
||||
ID = id
|
||||
ID = id,
|
||||
});
|
||||
int count = Convert.ToInt32(quantityTextBox.Text);
|
||||
priceTextBox.Text = Math.Round(count * (product?.Price ?? 0),
|
||||
2).ToString();
|
||||
priceTextBox.Text = Math.Round(count * (dress?.Price ?? 0), 2).ToString();
|
||||
_logger.LogInformation("Calculating total of order");
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
@ -14,6 +14,16 @@
|
||||
<None Remove="BusinessLogic\**" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="nlog.config" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="nlog.config">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user
Логика методов передачи заказа в работу, выполнении заказ и выдачи заказа схожа, нужно это учитывать