Исправления (но нужно проверить)

This commit is contained in:
pgirl111 2023-02-13 10:37:45 +04:00 committed by prodigygirl
parent 4e0ca60e92
commit a6c28cd37e
6 changed files with 28 additions and 44 deletions

View File

@ -195,18 +195,12 @@ namespace FurnitureAssembly
var modelShop = new ShopBindingModel
{
Id = form.Id,
ShopName = form.ShopModel.ShopName,
Address = form.ShopModel.Address,
DateOpening = form.ShopModel.DateOpening,
Id = form.Id
};
var modelFurn = new FurnitureBindingModel
{
Id = form.FurnitureId,
FurnitureName = form.FurnitureModel.FurnitureName,
Price = form.FurnitureModel.Price,
FurnitureComponents = form.FurnitureModel.FurnitureComponents
Id = form.FurnitureId
};
var operationResult = _shopLogic.AddFurniture(modelShop, modelFurn, form.Count);

View File

@ -96,7 +96,6 @@ namespace FurnitureAssembly
dateTimePicker.Value = view.DateOpening;
_shopFurnitures = view.Furnitures ?? new
Dictionary<int, (IFurnitureModel, int)>();
dta
LoadData();
}
}

View File

@ -16,11 +16,13 @@ namespace FurnitureAssemblyBusinessLogic
{
private readonly ILogger _logger;
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;
_shopStorage = shopStorage;
_furnitureStorage = furnitureStorage;
}
public ShopViewModel? ReadElement(ShopSearchModel model)
{
@ -117,9 +119,27 @@ namespace FurnitureAssemblyBusinessLogic
public bool AddFurniture(ShopBindingModel model, FurnitureBindingModel furnitureModel, int count)
{
CheckModel(model);
if (_shopStorage.AddFurniture(model, furnitureModel, count) == null)
var shop = _shopStorage.GetElement(new ShopSearchModel { Id = model.Id });
var furniture = _furnitureStorage.GetElement(new FurnitureSearchModel { Id = furnitureModel.Id });
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");
return false;

View File

@ -12,7 +12,6 @@ namespace FurnitureAssemblyContracts.StoragesContracts
ShopViewModel? GetElement(ShopSearchModel model);
ShopViewModel? Insert(ShopBindingModel model);
ShopViewModel? Update(ShopBindingModel model);
ShopViewModel? Delete(ShopBindingModel model);
ShopViewModel? AddFurniture(ShopBindingModel model, FurnitureBindingModel furniture, int count);
ShopViewModel? Delete(ShopBindingModel model);
}
}

View File

@ -109,18 +109,5 @@ namespace FurnitureAssemblyListImplement.Implements
}
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;
}
}
}

View File

@ -48,22 +48,7 @@ namespace FurnitureAssemblyListImplement.Models
DateOpening = model.DateOpening;
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()
{
Id = Id,