fix
This commit is contained in:
parent
b0fbd900d3
commit
da162462b5
@ -8,6 +8,16 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="nlog.config" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="nlog.config">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
||||
|
@ -74,10 +74,7 @@ namespace FoodOrdersView
|
||||
_logger.LogInformation("Удаление блюда");
|
||||
try
|
||||
{
|
||||
if (!_logic.Delete(new ComponentBindingModel
|
||||
{
|
||||
Id = id
|
||||
}))
|
||||
if (!_logic.Delete(new ComponentBindingModel { Id = id }))
|
||||
{
|
||||
throw new Exception("Ошибка при удалении. Дополнительная информация в логах.");
|
||||
}
|
||||
|
@ -45,10 +45,7 @@ namespace FoodOrdersView
|
||||
try
|
||||
{
|
||||
int id = Convert.ToInt32(comboBoxDish.SelectedValue);
|
||||
var product = _logicS.ReadElement(new DishSearchModel
|
||||
{
|
||||
Id = id
|
||||
});
|
||||
var product = _logicS.ReadElement(new DishSearchModel { Id = id });
|
||||
int count = Convert.ToInt32(textBoxCount.Text);
|
||||
textBoxSum.Text = Math.Round(count * (product?.Price ?? 0), 2).ToString();
|
||||
_logger.LogInformation("Расчет суммы заказа");
|
||||
|
1
FoodOrders/FoodOrders/FormDish.Designer.cs
generated
1
FoodOrders/FoodOrders/FormDish.Designer.cs
generated
@ -52,6 +52,7 @@
|
||||
this.textBoxPrice.Location = new System.Drawing.Point(90, 36);
|
||||
this.textBoxPrice.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
|
||||
this.textBoxPrice.Name = "textBoxPrice";
|
||||
this.textBoxPrice.ReadOnly = true;
|
||||
this.textBoxPrice.Size = new System.Drawing.Size(138, 23);
|
||||
this.textBoxPrice.TabIndex = 7;
|
||||
//
|
||||
|
@ -35,6 +35,7 @@ namespace FoodOrdersView
|
||||
{
|
||||
textBoxName.Text = view.DishName;
|
||||
textBoxPrice.Text = view.Price.ToString();
|
||||
//если не null то слева, если null то справа
|
||||
_dishComponents = view.DishComponents ?? new Dictionary<int, (IComponentModel, int)>();
|
||||
LoadData();
|
||||
}
|
||||
@ -82,13 +83,11 @@ namespace FoodOrdersView
|
||||
_logger.LogInformation("Добавление нового блюда: { ComponentName} - { Count}", form.ComponentModel.ComponentName, form.Count);
|
||||
if (_dishComponents.ContainsKey(form.Id))
|
||||
{
|
||||
_dishComponents[form.Id] = (form.ComponentModel,
|
||||
form.Count);
|
||||
_dishComponents[form.Id] = (form.ComponentModel, form.Count);
|
||||
}
|
||||
else
|
||||
{
|
||||
_dishComponents.Add(form.Id, (form.ComponentModel,
|
||||
form.Count));
|
||||
_dishComponents.Add(form.Id, (form.ComponentModel, form.Count));
|
||||
}
|
||||
LoadData();
|
||||
}
|
||||
@ -101,8 +100,7 @@ namespace FoodOrdersView
|
||||
var service = Program.ServiceProvider?.GetService(typeof(FormDishComponents));
|
||||
if (service is FormDishComponents form)
|
||||
{
|
||||
int id =
|
||||
Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
|
||||
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value);
|
||||
form.Id = id;
|
||||
form.Count = _dishComponents[id].Item2;
|
||||
if (form.ShowDialog() == DialogResult.OK)
|
||||
@ -127,8 +125,8 @@ namespace FoodOrdersView
|
||||
{
|
||||
try
|
||||
{
|
||||
_logger.LogInformation("Удаление блюда: { ComponentName} - { Count} ",
|
||||
dataGridView.SelectedRows[0].Cells[1].Value); _dishComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value));
|
||||
_logger.LogInformation("Удаление блюда: { ComponentName} - { Count} ", dataGridView.SelectedRows[0].Cells[1].Value, dataGridView.SelectedRows[0].Cells[2].Value);
|
||||
_dishComponents?.Remove(Convert.ToInt32(dataGridView.SelectedRows[0].Cells[0].Value));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
15
FoodOrders/FoodOrders/nlog.config
Normal file
15
FoodOrders/FoodOrders/nlog.config
Normal file
@ -0,0 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
autoReload="true" internalLogLevel="Info">
|
||||
|
||||
<targets>
|
||||
<target xsi:type="File" name="tofile" fileName="log-${shortdate}.log" />
|
||||
</targets>
|
||||
|
||||
<rules>
|
||||
<logger name="*" minlevel="Debug" writeTo="tofile" />
|
||||
</rules>
|
||||
</nlog>
|
||||
</configuration>
|
@ -19,10 +19,8 @@ namespace FoodOrdersBusinessLogic.BusinessLogics
|
||||
}
|
||||
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);
|
||||
_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");
|
||||
@ -38,7 +36,7 @@ namespace FoodOrdersBusinessLogic.BusinessLogics
|
||||
throw new ArgumentNullException(nameof(model));
|
||||
}
|
||||
_logger.LogInformation("ReadElement. ComponentName:{ComponentName}. Id:{Id}", model.ComponentName, model.Id);
|
||||
var element = _componentStorage.GetElement(model);
|
||||
var element = _componentStorage.GetElement(model);
|
||||
if (element == null)
|
||||
{
|
||||
_logger.LogWarning("ReadElement element not found");
|
||||
@ -78,8 +76,7 @@ namespace FoodOrdersBusinessLogic.BusinessLogics
|
||||
}
|
||||
return true;
|
||||
}
|
||||
private void CheckModel(ComponentBindingModel model, bool withParams =
|
||||
true)
|
||||
private void CheckModel(ComponentBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
@ -99,10 +96,10 @@ namespace FoodOrdersBusinessLogic.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("Компонент с таким названием уже есть");
|
||||
|
@ -111,7 +111,7 @@ namespace FoodOrdersBusinessLogic.BusinessLogics
|
||||
});
|
||||
if (element != null && element.Id != model.Id)
|
||||
{
|
||||
throw new InvalidOperationException("Прдукт с таким названием уже есть");
|
||||
throw new InvalidOperationException("Продукт с таким названием уже есть");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ namespace FoodOrdersBusinessLogic.BusinessLogics
|
||||
|
||||
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
||||
{
|
||||
_logger.LogInformation("ReadList. ComponentName:{ComponentName}. Id:{Id}", model?.Id);
|
||||
_logger.LogInformation("ReadList. Id:{Id}", model?.Id);
|
||||
var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
@ -89,7 +89,6 @@ namespace FoodOrdersBusinessLogic.BusinessLogics
|
||||
_logger.LogInformation("Order. OrderID:{Id}. Sum:{ Sum}. DishId: { DishId}", model.Id, model.Sum, model.Id);
|
||||
}
|
||||
|
||||
//???
|
||||
public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus)
|
||||
{
|
||||
var viewModel = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id });
|
||||
@ -111,7 +110,7 @@ namespace FoodOrdersBusinessLogic.BusinessLogics
|
||||
{
|
||||
model.DateImplement = viewModel.DateImplement;
|
||||
}
|
||||
CheckModel(model);
|
||||
CheckModel(model, false);
|
||||
if (_orderStorage.Update(model) == null)
|
||||
{
|
||||
_logger.LogWarning("Change status operation failed");
|
||||
|
@ -7,10 +7,6 @@ namespace FoodOrdersContracts.BindingModels
|
||||
public int Id { get; set; }
|
||||
public string DishName { get; set; } = string.Empty;
|
||||
public double Price { get; set; }
|
||||
public Dictionary<int, (IComponentModel, int)> DishComponents
|
||||
{
|
||||
get;
|
||||
set;
|
||||
} = new();
|
||||
public Dictionary<int, (IComponentModel, int)> DishComponents { get; set; } = new();
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,8 @@ namespace FoodOrdersContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IComponentLogic
|
||||
{
|
||||
//чтение листа, если модель есть то с фильтром, если модели нет то весь
|
||||
// знак вопроса так как модет вернуть null, а в качестве параметра, так как модель может не передаваться
|
||||
List<ComponentViewModel>? ReadList(ComponentSearchModel? model);
|
||||
ComponentViewModel? ReadElement(ComponentSearchModel model);
|
||||
bool Create(ComponentBindingModel model);
|
||||
|
@ -3,6 +3,8 @@ namespace FoodOrdersDataModels.Models
|
||||
{
|
||||
public interface IDishModel : IId
|
||||
{
|
||||
//в словаре первый int это id, то есть по id компонента найдём сам компонент
|
||||
//дальше идёт кортеж в котором находиться уже копмонент и то сколько таких компонентов в данном блюде
|
||||
string DishName { get; }
|
||||
double Price { get; }
|
||||
Dictionary<int, (IComponentModel, int)> DishComponents { get; }
|
||||
|
@ -9,6 +9,7 @@ namespace FoodOrdersDataModels.Models
|
||||
double Sum { get; }
|
||||
OrderStatus Status { get; }
|
||||
DateTime DateCreate { get; }
|
||||
//через "?" обозначается что поле может быть null
|
||||
DateTime? DateImplement { get; }
|
||||
}
|
||||
}
|
||||
|
@ -88,6 +88,8 @@ namespace FoodOrdersListImplement.Implements
|
||||
}
|
||||
public ComponentViewModel? Delete(ComponentBindingModel model)
|
||||
{
|
||||
// не юзаем foreach так как при изменении данных (добавление и удаление записей) коллекции foreach ломается
|
||||
// если бы просто меняли значение записи всё было бы в порядке
|
||||
for (int i = 0; i < _source.Components.Count; ++i)
|
||||
{
|
||||
if (_source.Components[i].Id == model.Id)
|
||||
|
@ -4,11 +4,14 @@ using FoodOrdersDataModels.Models;
|
||||
|
||||
namespace FoodOrdersListImplement.Models
|
||||
{
|
||||
//класс отвечает не только за хранение данных но также и за их изменение
|
||||
public class Component : IComponentModel
|
||||
{
|
||||
public int Id { get; private set; }
|
||||
public string ComponentName { get; private set; } = string.Empty;
|
||||
public double Cost { get; set; }
|
||||
|
||||
//создаём из ComponentBindingModel Component
|
||||
public static Component? Create(ComponentBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
@ -22,6 +25,8 @@ namespace FoodOrdersListImplement.Models
|
||||
Cost = model.Cost
|
||||
};
|
||||
}
|
||||
|
||||
//изменённые данные из бизнес-логики передаём в поля Component
|
||||
public void Update(ComponentBindingModel? model)
|
||||
{
|
||||
if (model == null)
|
||||
@ -31,6 +36,8 @@ namespace FoodOrdersListImplement.Models
|
||||
ComponentName = model.ComponentName;
|
||||
Cost = model.Cost;
|
||||
}
|
||||
|
||||
//получение ComponentViewModel из Component
|
||||
public ComponentViewModel GetViewModel => new()
|
||||
{
|
||||
Id = Id,
|
||||
|
Loading…
Reference in New Issue
Block a user