BaseUpdate

This commit is contained in:
Sergey Kozyrev 2024-03-09 09:52:08 +04:00
parent f134d1fb63
commit ac8618e3e5
4 changed files with 8 additions and 43 deletions

View File

@ -161,6 +161,7 @@ namespace SewingDressesBusinessLogic.BusinessLogic
Id = curModel.Id,
ShopName = curModel.ShopName,
DateOpen = curModel.DateOpen,
MaxCount = curModel.MaxCount,
Adress = curModel.Adress,
ShopDresses = curModel.ShopDresses,
});

View File

@ -83,7 +83,7 @@ namespace SewingDressesFileImplement.Implements
{
var dres = _source.Dresses.FirstOrDefault(x => x.Id == model.Id);
if (dres == null || CheckAvailability(model.Id, count))
if (dres == null || !CheckAvailability(model.Id, count))
{
return false;
}

View File

@ -107,44 +107,10 @@ namespace SewingDressesListImplement.Implements
public bool CheckAvailability(int dressId, int count)
{
int store = _source.Shops.Select(x => x.ShopDresses.Select(y => (y.Value.Item1.Id == dressId ? y.Value.Item2 : 0)).Sum()).Sum();
return store >= count;
return true;
}
public bool SellDresses(IDressModel model, int count)
{
var dres = _source.Dresses.FirstOrDefault(x => x.Id == model.Id);
if (dres == null || CheckAvailability(model.Id, count))
{
return false;
}
for (int i = 0; i < _source.Shops.Count; i++)
{
var shop = _source.Shops[i];
var dresses = shop.ShopDresses;
foreach( var dress in dresses.Where(x => x.Value.Item1.Id == dres.Id))
{
var selling = Math.Min(dress.Value.Item2, count);
dresses[dress.Value.Item1.Id] = (dress.Value.Item1, dress.Value.Item2 - selling);
count -= selling;
if (count <= 0)
{
break;
}
}
shop.Update(new ShopBindingModel
{
Id = model.Id,
ShopName = shop.ShopName,
Adress = shop.Adress,
MaxCount = shop.MaxCount,
DateOpen = shop.DateOpen,
ShopDresses = dresses
});
}
return true;
}
}

View File

@ -90,15 +90,13 @@ namespace SewingDressesView
{
if (dataGridView.SelectedRows.Count == 1)
{
int id =
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
_logger.LogInformation("Order №{id}. Change status on 'Ready'",
id);
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
var dressId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["DressId"].Value);
var count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value);
_logger.LogInformation("Order №{id}. Change status on 'Ready'", id);
try
{
var operationResult = _orderLogic.FinishOrder(new
OrderBindingModel
{ Id = id });
var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id, DressId = dressId, Count = count });
if (!operationResult)
{
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");