Исправления (но нужно проверить)
This commit is contained in:
parent
4e0ca60e92
commit
a6c28cd37e
@ -195,18 +195,12 @@ namespace FurnitureAssembly
|
|||||||
|
|
||||||
var modelShop = new ShopBindingModel
|
var modelShop = new ShopBindingModel
|
||||||
{
|
{
|
||||||
Id = form.Id,
|
Id = form.Id
|
||||||
ShopName = form.ShopModel.ShopName,
|
|
||||||
Address = form.ShopModel.Address,
|
|
||||||
DateOpening = form.ShopModel.DateOpening,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var modelFurn = new FurnitureBindingModel
|
var modelFurn = new FurnitureBindingModel
|
||||||
{
|
{
|
||||||
Id = form.FurnitureId,
|
Id = form.FurnitureId
|
||||||
FurnitureName = form.FurnitureModel.FurnitureName,
|
|
||||||
Price = form.FurnitureModel.Price,
|
|
||||||
FurnitureComponents = form.FurnitureModel.FurnitureComponents
|
|
||||||
};
|
};
|
||||||
|
|
||||||
var operationResult = _shopLogic.AddFurniture(modelShop, modelFurn, form.Count);
|
var operationResult = _shopLogic.AddFurniture(modelShop, modelFurn, form.Count);
|
||||||
|
@ -96,7 +96,6 @@ namespace FurnitureAssembly
|
|||||||
dateTimePicker.Value = view.DateOpening;
|
dateTimePicker.Value = view.DateOpening;
|
||||||
_shopFurnitures = view.Furnitures ?? new
|
_shopFurnitures = view.Furnitures ?? new
|
||||||
Dictionary<int, (IFurnitureModel, int)>();
|
Dictionary<int, (IFurnitureModel, int)>();
|
||||||
dta
|
|
||||||
LoadData();
|
LoadData();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,11 +16,13 @@ namespace FurnitureAssemblyBusinessLogic
|
|||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IShopStorage _shopStorage;
|
private readonly IShopStorage _shopStorage;
|
||||||
|
private readonly IFurnitureStorage _furnitureStorage;
|
||||||
|
|
||||||
public ShopLogic(ILogger<ShopLogic> logger, IShopStorage shopStorage)
|
public ShopLogic(ILogger<ShopLogic> logger, IShopStorage shopStorage, IFurnitureStorage furnitureStorage)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_shopStorage = shopStorage;
|
_shopStorage = shopStorage;
|
||||||
|
_furnitureStorage = furnitureStorage;
|
||||||
}
|
}
|
||||||
public ShopViewModel? ReadElement(ShopSearchModel model)
|
public ShopViewModel? ReadElement(ShopSearchModel model)
|
||||||
{
|
{
|
||||||
@ -117,9 +119,27 @@ namespace FurnitureAssemblyBusinessLogic
|
|||||||
|
|
||||||
public bool AddFurniture(ShopBindingModel model, FurnitureBindingModel furnitureModel, int count)
|
public bool AddFurniture(ShopBindingModel model, FurnitureBindingModel furnitureModel, int count)
|
||||||
{
|
{
|
||||||
CheckModel(model);
|
var shop = _shopStorage.GetElement(new ShopSearchModel { Id = model.Id });
|
||||||
|
var furniture = _furnitureStorage.GetElement(new FurnitureSearchModel { Id = furnitureModel.Id });
|
||||||
|
|
||||||
if (_shopStorage.AddFurniture(model, furnitureModel, count) == null)
|
if (shop == null || furniture == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (shop.Furnitures.ContainsKey(furniture.Id))
|
||||||
|
{
|
||||||
|
int prev_count = shop.Furnitures[furniture.Id].Item2;
|
||||||
|
shop.Furnitures[furniture.Id] = (furniture, prev_count + count);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
shop.Furnitures[furniture.Id] = (furniture, count);
|
||||||
|
}
|
||||||
|
model.Furnitures = shop.Furnitures;
|
||||||
|
model.DateOpening = shop.DateOpening;
|
||||||
|
model.Address = shop.Address;
|
||||||
|
model.ShopName = shop.ShopName;
|
||||||
|
if (_shopStorage.Update(model) == null)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Replenishment operation failed");
|
_logger.LogWarning("Replenishment operation failed");
|
||||||
return false;
|
return false;
|
||||||
|
@ -13,6 +13,5 @@ namespace FurnitureAssemblyContracts.StoragesContracts
|
|||||||
ShopViewModel? Insert(ShopBindingModel model);
|
ShopViewModel? Insert(ShopBindingModel model);
|
||||||
ShopViewModel? Update(ShopBindingModel model);
|
ShopViewModel? Update(ShopBindingModel model);
|
||||||
ShopViewModel? Delete(ShopBindingModel model);
|
ShopViewModel? Delete(ShopBindingModel model);
|
||||||
ShopViewModel? AddFurniture(ShopBindingModel model, FurnitureBindingModel furniture, int count);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -109,18 +109,5 @@ namespace FurnitureAssemblyListImplement.Implements
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ShopViewModel? AddFurniture(ShopBindingModel model, FurnitureBindingModel furniture, int count)
|
|
||||||
{
|
|
||||||
foreach (var shop in _source.Shops)
|
|
||||||
{
|
|
||||||
if (shop.Id == model.Id)
|
|
||||||
{
|
|
||||||
shop.AddFurniture(model, furniture, count);
|
|
||||||
return shop.GetViewModel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,21 +49,6 @@ namespace FurnitureAssemblyListImplement.Models
|
|||||||
Furnitures = model.Furnitures;
|
Furnitures = model.Furnitures;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddFurniture(ShopBindingModel? model, FurnitureBindingModel furniture, int count)
|
|
||||||
{
|
|
||||||
if (model == null)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (Furnitures.ContainsKey(furniture.Id))
|
|
||||||
{
|
|
||||||
int prev_count = Furnitures[furniture.Id].Item2;
|
|
||||||
Furnitures[furniture.Id] = (furniture, prev_count + count);
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
Furnitures[furniture.Id] = (furniture, count);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public ShopViewModel GetViewModel => new()
|
public ShopViewModel GetViewModel => new()
|
||||||
{
|
{
|
||||||
Id = Id,
|
Id = Id,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user