This commit is contained in:
Николай 2023-03-12 12:23:46 +04:00
parent 655a9190c9
commit 1ee31d1267
4 changed files with 14 additions and 21 deletions

View File

@ -6,13 +6,13 @@ namespace FoodOrdersView
public partial class FormDeliveryDishes : Form public partial class FormDeliveryDishes : Form
{ {
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IDishLogic _logicC; private readonly IDishLogic _logicD;
private readonly IShopLogic _logicS; private readonly IShopLogic _logicS;
public FormDeliveryDishes(ILogger<FormDeliveryDishes> logger, IDishLogic logicC, IShopLogic logicS) public FormDeliveryDishes(ILogger<FormDeliveryDishes> logger, IDishLogic logicC, IShopLogic logicS)
{ {
InitializeComponent(); InitializeComponent();
_logger = logger; _logger = logger;
_logicC = logicC; _logicD = logicC;
_logicS = logicS; _logicS = logicS;
} }
private void FormDeliveryDishes_Load(object sender, EventArgs e) private void FormDeliveryDishes_Load(object sender, EventArgs e)
@ -37,7 +37,7 @@ namespace FoodOrdersView
_logger.LogInformation("Загрузка блюд"); _logger.LogInformation("Загрузка блюд");
try try
{ {
var list = _logicC.ReadList(null); var list = _logicD.ReadList(null);
if (list != null) if (list != null)
{ {
comboBoxDish.DisplayMember = "DishName"; comboBoxDish.DisplayMember = "DishName";
@ -72,24 +72,23 @@ namespace FoodOrdersView
_logger.LogInformation("Пополнение магазина"); _logger.LogInformation("Пополнение магазина");
try try
{ {
var operationResult = _logicS.DeliveryDishes(new ShopSearchModel var operationResult = _logicS.DeliveryDishes(
{ new ShopSearchModel { ShopName = comboBoxShop.Text,},
ShopName = comboBoxShop.Text, _logicD.ReadElement(new DishSearchModel{ DishName = comboBoxDish.Text })!,
}, _logicC.ReadElement(new DishSearchModel{ DishName = comboBoxDish.Text })!, Convert.ToInt32(textBoxCount.Text)); Convert.ToInt32(textBoxCount.Text)
);
if (!operationResult) if (!operationResult)
{ {
throw new Exception("Ошибка при пополнении магазина. Дополнительная информация в логах."); throw new Exception("Ошибка при пополнении магазина. Дополнительная информация в логах.");
} }
MessageBox.Show("Пополнение прошло успешно", "Сообщение", MessageBox.Show("Пополнение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK; DialogResult = DialogResult.OK;
Close(); Close();
} }
catch (Exception ex) catch (Exception ex)
{ {
_logger.LogError(ex, "Ошибка пополнения магазина"); _logger.LogError(ex, "Ошибка пополнения магазина");
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBoxIcon.Error);
} }
} }
} }

View File

@ -62,7 +62,7 @@ namespace FoodOrdersBusinessLogic.BusinessLogics
} }
if (element.ShopDishes.ContainsKey(dish.Id)) if (element.ShopDishes.ContainsKey(dish.Id))
{ {
element.ShopDishes[dish.Id] = (element.ShopDishes[dish.Id].Item1, element.ShopDishes[dish.Id].Item2 + count); element.ShopDishes[dish.Id] = (dish, element.ShopDishes[dish.Id].Item2 + count);
} }
else else
{ {

View File

@ -34,9 +34,7 @@ namespace FoodOrdersListImplement.Implements
} }
foreach (var shop in _source.Shops) foreach (var shop in _source.Shops)
{ {
if ((!string.IsNullOrEmpty(model.ShopName) && if ((!string.IsNullOrEmpty(model.ShopName) && shop.ShopName == model.ShopName) || (model.Id.HasValue && shop.Id == model.Id))
shop.ShopName == model.ShopName) ||
(model.Id.HasValue && shop.Id == model.Id))
{ {
return shop.GetViewModel; return shop.GetViewModel;
} }

View File

@ -8,15 +8,11 @@ namespace FoodOrdersListImplement.Models
{ {
public class Shop : IShopModel public class Shop : IShopModel
{ {
public int Id { get; private set; }
public string ShopName { get; private set; } = string.Empty; public string ShopName { get; private set; } = string.Empty;
public string Address { get; private set; } = string.Empty; public string Address { get; private set; } = string.Empty;
public DateTime DateOfOpening { get; private set; } = DateTime.Now; public DateTime DateOfOpening { get; private set; } = DateTime.Now;
public int Id { get; private set; } public Dictionary<int, (IDishModel, int)> ShopDishes { get; private set; } = new Dictionary<int, (IDishModel, int)>();
public Dictionary<int, (IDishModel, int)> ShopDishes
{
get;
private set;
} = new Dictionary<int, (IDishModel, int)>();
public static Shop? Create(ShopBindingModel? model) public static Shop? Create(ShopBindingModel? model)
{ {
if (model == null) if (model == null)