ShopRepairs saving fix
This commit is contained in:
parent
5d703cb615
commit
ad9847c51c
@ -102,7 +102,7 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics
|
||||
if (Model.Count <= 0)
|
||||
throw new ArgumentException("Количество ремонтов должно быть больше 0");
|
||||
|
||||
var Shop = _shopStorage.GetElement(new ShopSearchModel
|
||||
ShopViewModel? Shop = _shopStorage.GetElement(new ShopSearchModel
|
||||
{
|
||||
Id = Model.ShopId
|
||||
});
|
||||
@ -112,9 +112,9 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics
|
||||
|
||||
if (Shop.ShopRepairs.ContainsKey(Model.RepairId))
|
||||
{
|
||||
var OldValue = Shop.ShopRepairs[Model.RepairId];
|
||||
OldValue.Item2 += Model.Count;
|
||||
Shop.ShopRepairs[Model.RepairId] = OldValue;
|
||||
var RepairsNum = Shop.ShopRepairs[Model.RepairId];
|
||||
RepairsNum.Item2 += Model.Count;
|
||||
Shop.ShopRepairs[Model.RepairId] = RepairsNum;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -124,11 +124,20 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics
|
||||
});
|
||||
|
||||
if (Repair == null)
|
||||
throw new ArgumentException($"Поставка: Товар с id:{Model.RepairId} не найденн");
|
||||
throw new ArgumentException($"Поставка: Товар с id {Model.RepairId} не найден");
|
||||
|
||||
Shop.ShopRepairs.Add(Model.RepairId, (Repair, Model.Count));
|
||||
}
|
||||
|
||||
|
||||
_shopStorage.Update(new ShopBindingModel()
|
||||
{
|
||||
Id = Shop.Id,
|
||||
ShopName = Shop.ShopName,
|
||||
Address = Shop.Address,
|
||||
OpeningDate = Shop.OpeningDate,
|
||||
ShopRepairs = Shop.ShopRepairs,
|
||||
RepairsMaxCount = Shop.RepairsMaxCount,
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -159,14 +168,14 @@ namespace AutoWorkshopBusinessLogic.BusinessLogics
|
||||
}
|
||||
}
|
||||
|
||||
public bool Sale(SupplySearchModel Model)
|
||||
public bool MakeSell(SupplySearchModel Model)
|
||||
{
|
||||
if (!Model.RepairId.HasValue || !Model.Count.HasValue)
|
||||
return false;
|
||||
|
||||
_logger.LogInformation("Проверка ремонтов во всех магазинах");
|
||||
|
||||
if (_shopStorage.Sale(Model))
|
||||
if (_shopStorage.Sell(Model))
|
||||
{
|
||||
_logger.LogInformation("Продажа выполнена успешно");
|
||||
return true;
|
||||
|
@ -18,6 +18,6 @@ namespace AutoWorkshopContracts.BusinessLogicsContracts
|
||||
|
||||
bool MakeSupply(SupplyBindingModel Model);
|
||||
|
||||
bool Sale(SupplySearchModel Model);
|
||||
bool MakeSell(SupplySearchModel Model);
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
public class SupplySearchModel
|
||||
{
|
||||
public int? RepairId { get; set; }
|
||||
|
||||
public int? Count { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -17,8 +17,8 @@ namespace AutoWorkshopContracts.StoragesContracts
|
||||
ShopViewModel? Update(ShopBindingModel Model);
|
||||
|
||||
ShopViewModel? Delete(ShopBindingModel Model);
|
||||
|
||||
bool Sale(SupplySearchModel Model);
|
||||
|
||||
bool Sell(SupplySearchModel Model);
|
||||
|
||||
bool RestockingShops(SupplyBindingModel Model);
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ namespace AutoWorkshopFileImplement
|
||||
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
|
||||
Repairs = LoadData(RepairFileName, "Repair", x => Repair.Create(x)!)!;
|
||||
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
|
||||
Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!;
|
||||
Shops = LoadData(ShopFileName, "Shop", x => Shop.Create(x)!)!;
|
||||
}
|
||||
|
||||
public static DataFileSingleton GetInstance()
|
||||
|
@ -25,7 +25,11 @@ namespace AutoWorkshopFileImplement.Implements
|
||||
if (string.IsNullOrEmpty(Model.ShopName))
|
||||
return new();
|
||||
|
||||
return _source.Shops.Where(x => x.ShopName.Contains(Model.ShopName)).Select(x => x.GetViewModel).ToList();
|
||||
return _source.Shops
|
||||
.Where(x => x.ShopName
|
||||
.Contains(Model.ShopName))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public ShopViewModel? GetElement(ShopSearchModel Model)
|
||||
@ -35,7 +39,8 @@ namespace AutoWorkshopFileImplement.Implements
|
||||
|
||||
return _source.Shops.FirstOrDefault(x =>
|
||||
(!string.IsNullOrEmpty(Model.ShopName) && x.ShopName == Model.ShopName) ||
|
||||
(Model.Id.HasValue && x.Id == Model.Id))?.GetViewModel;
|
||||
(Model.Id.HasValue && x.Id == Model.Id))?
|
||||
.GetViewModel;
|
||||
}
|
||||
|
||||
public ShopViewModel? Insert(ShopBindingModel Model)
|
||||
@ -77,7 +82,7 @@ namespace AutoWorkshopFileImplement.Implements
|
||||
return Shop.GetViewModel;
|
||||
}
|
||||
|
||||
public bool Sale(SupplySearchModel Model)
|
||||
public bool Sell(SupplySearchModel Model)
|
||||
{
|
||||
if (Model == null || !Model.RepairId.HasValue || !Model.Count.HasValue)
|
||||
return false;
|
||||
@ -92,21 +97,21 @@ namespace AutoWorkshopFileImplement.Implements
|
||||
|
||||
foreach (var Shop in Shops)
|
||||
{
|
||||
int Residue = Model.Count.Value - Shop.Repairs[Model.RepairId.Value];
|
||||
int Slack = Model.Count.Value - Shop.Repairs[Model.RepairId.Value];
|
||||
|
||||
if (Residue > 0)
|
||||
if (Slack > 0)
|
||||
{
|
||||
Shop.Repairs.Remove(Model.RepairId.Value);
|
||||
Shop.RepairsUpdate();
|
||||
|
||||
Model.Count = Residue;
|
||||
Model.Count = Slack;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Residue == 0)
|
||||
if (Slack == 0)
|
||||
Shop.Repairs.Remove(Model.RepairId.Value);
|
||||
else
|
||||
Shop.Repairs[Model.RepairId.Value] = -Residue;
|
||||
Shop.Repairs[Model.RepairId.Value] = -Slack;
|
||||
|
||||
Shop.RepairsUpdate();
|
||||
_source.SaveShops();
|
||||
@ -124,9 +129,9 @@ namespace AutoWorkshopFileImplement.Implements
|
||||
if (Model == null || _source.Shops.Select(x => x.RepairsMaxCount - x.ShopRepairs.Select(y => y.Value.Item2).Sum()).Sum() < Model.Count)
|
||||
return false;
|
||||
|
||||
foreach (Shop shop in _source.Shops)
|
||||
foreach (Shop Shop in _source.Shops)
|
||||
{
|
||||
int FreeSpaceNum = shop.RepairsMaxCount - shop.ShopRepairs.Select(x => x.Value.Item2).Sum();
|
||||
int FreeSpaceNum = Shop.RepairsMaxCount - Shop.ShopRepairs.Select(x => x.Value.Item2).Sum();
|
||||
|
||||
if (FreeSpaceNum <= 0)
|
||||
continue;
|
||||
@ -134,12 +139,12 @@ namespace AutoWorkshopFileImplement.Implements
|
||||
FreeSpaceNum = Math.Min(FreeSpaceNum, Model.Count);
|
||||
Model.Count -= FreeSpaceNum;
|
||||
|
||||
if (shop.Repairs.ContainsKey(Model.RepairId))
|
||||
shop.Repairs[Model.RepairId] += FreeSpaceNum;
|
||||
if (Shop.Repairs.ContainsKey(Model.RepairId))
|
||||
Shop.Repairs[Model.RepairId] += FreeSpaceNum;
|
||||
else
|
||||
shop.Repairs.Add(Model.RepairId, FreeSpaceNum);
|
||||
Shop.Repairs.Add(Model.RepairId, FreeSpaceNum);
|
||||
|
||||
shop.RepairsUpdate();
|
||||
Shop.RepairsUpdate();
|
||||
|
||||
if (Model.Count == 0)
|
||||
{
|
||||
|
@ -56,7 +56,7 @@ namespace AutoWorkshopFileImplement.Models
|
||||
if (Element == null)
|
||||
return null;
|
||||
|
||||
return new()
|
||||
return new Shop()
|
||||
{
|
||||
Id = Convert.ToInt32(Element.Attribute("Id")!.Value),
|
||||
ShopName = Element.Element("ShopName")!.Value,
|
||||
|
@ -109,7 +109,7 @@ namespace AutoWorkshopListImplement.Implements
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool Sale(SupplySearchModel Model)
|
||||
public bool Sell(SupplySearchModel Model)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ namespace AutoWorkshopView.Forms.Shop
|
||||
|
||||
try
|
||||
{
|
||||
bool Result = _shopLogic.Sale(new SupplySearchModel
|
||||
bool Result = _shopLogic.MakeSell(new SupplySearchModel
|
||||
{
|
||||
RepairId = Convert.ToInt32(RepairComboBox.SelectedValue),
|
||||
Count = Convert.ToInt32(CountTextBox.Text)
|
||||
|
@ -190,6 +190,7 @@ namespace AutoWorkshopView
|
||||
private void SellToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
var Service = Program.ServiceProvider?.GetService(typeof(FormSellRepair));
|
||||
|
||||
if (Service is FormSellRepair Form)
|
||||
{
|
||||
Form.ShowDialog();
|
||||
|
Loading…
Reference in New Issue
Block a user