Compare commits

..

3 Commits

7 changed files with 15 additions and 19 deletions

View File

@ -75,12 +75,12 @@
this.comboBoxShop.Size = new System.Drawing.Size(220, 23); this.comboBoxShop.Size = new System.Drawing.Size(220, 23);
this.comboBoxShop.TabIndex = 3; this.comboBoxShop.TabIndex = 3;
// //
// comboBoxDocument // comboBoxBouquet
// //
this.comboBoxBouquet.FormattingEnabled = true; this.comboBoxBouquet.FormattingEnabled = true;
this.comboBoxBouquet.Location = new System.Drawing.Point(130, 52); this.comboBoxBouquet.Location = new System.Drawing.Point(130, 52);
this.comboBoxBouquet.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2); this.comboBoxBouquet.Margin = new System.Windows.Forms.Padding(3, 2, 3, 2);
this.comboBoxBouquet.Name = "comboBoxDocument"; this.comboBoxBouquet.Name = "comboBoxBouquet";
this.comboBoxBouquet.Size = new System.Drawing.Size(220, 23); this.comboBoxBouquet.Size = new System.Drawing.Size(220, 23);
this.comboBoxBouquet.TabIndex = 4; this.comboBoxBouquet.TabIndex = 4;
// //

View File

@ -86,23 +86,24 @@ namespace FlowerShopBusinessLogic.BusinessLogics
{ {
CheckModel(model, false); CheckModel(model, false);
if (_orderStorage.GetElement(new OrderSearchModel { Id = model.Id })?.Status != OrderStatus.Выполняется) var order = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id });
if (order?.Status != OrderStatus.Выполняется)
{ {
_logger.LogWarning("Invalid order status"); _logger.LogWarning("Invalid order status");
return false; return false;
} }
var bouquet = _bouquetStorage.GetElement(new BouquetSearchModel() { Id = model.BouquetId }); var bouquet = _bouquetStorage.GetElement(new BouquetSearchModel() { Id = order.BouquetId });
if (bouquet == null) if (bouquet == null)
{ {
_logger.LogWarning("Status update to Готов operation failed. Bouquet not found"); _logger.LogWarning("Status update to Готов operation failed. Bouquet not found");
return false; return false;
} }
if (!CheckThenSupplyMany(bouquet, model.Count)) if (!CheckThenSupplyMany(bouquet, order.Count))
{ {
_logger.LogWarning("Status update to Готов operation failed. Shop supply error."); _logger.LogWarning("Status update to Готов operation failed. Shop supply error.");
return false; throw new Exception("В магазинах не хватает места!");
} }
model.Status = OrderStatus.Готов; model.Status = OrderStatus.Готов;

View File

@ -89,7 +89,7 @@ namespace FlowerShopBusinessLogic.BusinessLogics
countBouquets += bouq.Value.Item2; countBouquets += bouq.Value.Item2;
} }
if (shopElement.MaxCountBouquets - countBouquets > count) if (shopElement.MaxCountBouquets - countBouquets >= count)
{ {
if (shopElement.ShopBouquets.TryGetValue(bouquet.Id, out var sameBouquet)) if (shopElement.ShopBouquets.TryGetValue(bouquet.Id, out var sameBouquet))
{ {
@ -108,7 +108,8 @@ namespace FlowerShopBusinessLogic.BusinessLogics
Name = shopElement.Name, Name = shopElement.Name,
Address = shopElement.Address, Address = shopElement.Address,
OpeningDate = shopElement.OpeningDate, OpeningDate = shopElement.OpeningDate,
ShopBouquets = shopElement.ShopBouquets ShopBouquets = shopElement.ShopBouquets,
MaxCountBouquets = shopElement.MaxCountBouquets
}); });
} }
else else

View File

@ -37,7 +37,7 @@ namespace FlowerShopFileImplement.Implements
public List<OrderViewModel> GetFullList() public List<OrderViewModel> GetFullList()
{ {
return source.Orders.Select(x => x.GetViewModel).ToList(); return source.Orders.Select(x => AttachBouquetName(x.GetViewModel)).ToList();
} }
public OrderViewModel? Update(OrderBindingModel model) public OrderViewModel? Update(OrderBindingModel model)
@ -67,7 +67,7 @@ namespace FlowerShopFileImplement.Implements
source.Orders.Add(newOrder); source.Orders.Add(newOrder);
source.SaveOrders(); source.SaveOrders();
return newOrder.GetViewModel; return AttachBouquetName(newOrder.GetViewModel);
} }
public OrderViewModel? Delete(OrderBindingModel model) public OrderViewModel? Delete(OrderBindingModel model)
@ -81,7 +81,7 @@ namespace FlowerShopFileImplement.Implements
source.Orders.Remove(order); source.Orders.Remove(order);
source.SaveOrders(); source.SaveOrders();
return order.GetViewModel; return AttachBouquetName(order.GetViewModel);
} }
private OrderViewModel AttachBouquetName(OrderViewModel? model) private OrderViewModel AttachBouquetName(OrderViewModel? model)

View File

@ -118,9 +118,8 @@ namespace FlowerShopFileImplement.Implements
count = countStore; count = countStore;
for (int i = 0; i < source.Shops.Count; i++) foreach(var shop in source.Shops)
{ {
var shop = source.Shops[i];
var bouquets = shop.ShopBouquets; var bouquets = shop.ShopBouquets;
foreach (var bouq in bouquets.Where(x => x.Value.Item1.Id == bouquet.Id)) foreach (var bouq in bouquets.Where(x => x.Value.Item1.Id == bouquet.Id))

View File

@ -60,7 +60,7 @@ namespace FlowerShopFileImplement.Models
return new Bouquet() return new Bouquet()
{ {
Id = Convert.ToInt32(element.Attribute("Id")!.Value), Id = Convert.ToInt32(element.Attribute("Id")!.Value),
BouquetName = element.Attribute("BouquetName")!.Value, BouquetName = element.Element("BouquetName")!.Value,
Price = Convert.ToDouble(element.Element("Price")!.Value), Price = Convert.ToDouble(element.Element("Price")!.Value),
Components = element.Element("BouquetComponents")!.Elements("BouquetComponent").ToDictionary( Components = element.Element("BouquetComponents")!.Elements("BouquetComponent").ToDictionary(
x => Convert.ToInt32(x.Element("Key")?.Value), x => Convert.ToInt32(x.Element("Key")?.Value),

View File

@ -67,13 +67,8 @@ namespace FlowerShopFileImplement.Models
return; return;
} }
BouquetId = model.BouquetId;
Count = model.Count;
Sum = model.Sum;
Status = model.Status; Status = model.Status;
DateCreate = model.DateCreate;
DateImplement = model.DateImplement; DateImplement = model.DateImplement;
Id = model.Id;
} }
public OrderViewModel GetViewModel => new() public OrderViewModel GetViewModel => new()