BaseUpdate
This commit is contained in:
parent
f134d1fb63
commit
ac8618e3e5
@ -161,6 +161,7 @@ namespace SewingDressesBusinessLogic.BusinessLogic
|
|||||||
Id = curModel.Id,
|
Id = curModel.Id,
|
||||||
ShopName = curModel.ShopName,
|
ShopName = curModel.ShopName,
|
||||||
DateOpen = curModel.DateOpen,
|
DateOpen = curModel.DateOpen,
|
||||||
|
MaxCount = curModel.MaxCount,
|
||||||
Adress = curModel.Adress,
|
Adress = curModel.Adress,
|
||||||
ShopDresses = curModel.ShopDresses,
|
ShopDresses = curModel.ShopDresses,
|
||||||
});
|
});
|
||||||
|
@ -83,7 +83,7 @@ namespace SewingDressesFileImplement.Implements
|
|||||||
{
|
{
|
||||||
var dres = _source.Dresses.FirstOrDefault(x => x.Id == model.Id);
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -107,44 +107,10 @@ namespace SewingDressesListImplement.Implements
|
|||||||
|
|
||||||
public bool CheckAvailability(int dressId, int count)
|
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 true;
|
||||||
return store >= count;
|
|
||||||
}
|
}
|
||||||
public bool SellDresses(IDressModel model, int count)
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,15 +90,13 @@ namespace SewingDressesView
|
|||||||
{
|
{
|
||||||
if (dataGridView.SelectedRows.Count == 1)
|
if (dataGridView.SelectedRows.Count == 1)
|
||||||
{
|
{
|
||||||
int id =
|
int id = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
||||||
Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Id"].Value);
|
var dressId = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["DressId"].Value);
|
||||||
_logger.LogInformation("Order №{id}. Change status on 'Ready'",
|
var count = Convert.ToInt32(dataGridView.SelectedRows[0].Cells["Count"].Value);
|
||||||
id);
|
_logger.LogInformation("Order №{id}. Change status on 'Ready'", id);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var operationResult = _orderLogic.FinishOrder(new
|
var operationResult = _orderLogic.FinishOrder(new OrderBindingModel { Id = id, DressId = dressId, Count = count });
|
||||||
OrderBindingModel
|
|
||||||
{ Id = id });
|
|
||||||
if (!operationResult)
|
if (!operationResult)
|
||||||
{
|
{
|
||||||
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
throw new Exception("Ошибка при сохранении. Дополнительная информация в логах.");
|
||||||
|
Loading…
Reference in New Issue
Block a user