Compare commits

..

No commits in common. "95a10df89d8f95a703fde116cd137deba18c0632" and "c5b726ffc984109690eee89614cd53f25d94a89d" have entirely different histories.

4 changed files with 24 additions and 21 deletions

View File

@ -18,6 +18,6 @@ namespace AutomobilePlantContracts.BusinessLogicContracts
bool Update(ShopBindingModel model);
bool Delete(ShopBindingModel model);
bool SupplyCars(ShopSearchModel model, ICarModel car, int count);
bool SellCar(ICarModel car, int count);
bool SellCar(ICarModel document, int count);
}
}

View File

@ -100,7 +100,6 @@ namespace AutomobilePlantDatabaseImplement.Implements
}
car.Update(model);
car.UpdateComponents(context, model);
context.SaveChanges();
context.Database.CommitTransaction();

View File

@ -77,17 +77,14 @@ namespace AutomobilePlantDatabaseImplement.Implements
using var transaction = context.Database.BeginTransaction();
try
{
var shop = context.Shops.Include(x => x.Cars).FirstOrDefault(x => x.Id == model.Id);
var shop = context.Shops.FirstOrDefault(x => x.Id == model.Id);
if (shop == null)
{
return null;
}
shop.Update(model);
context.SaveChanges();
if (model.ShopCars.Count > 0)
{
shop.UpdateCars(context, model);
}
shop.UpdateCars(context, model);
transaction.Commit();
return shop.GetViewModel;
}

View File

@ -83,24 +83,29 @@ namespace AutomobilePlantFileImplement.Implements
public bool SellCar(ICarModel model, int count)
{
// переделать под linq
var car = source.Cars.FirstOrDefault(x => x.Id == model.Id);
var countStore = count;
if (car == null)
{
return false;
}
var countStore = count;
var shopCars = source.Shops.SelectMany(shop => shop.ShopCars.Where(c => c.Value.Item1.Id == car.Id));
foreach (var c in shopCars)
foreach (var shop in source.Shops)
{
count -= c.Value.Item2;
if (count <= 0)
foreach (var c in shop.ShopCars)
{
break;
if (c.Value.Item1.Id == car.Id)
{
count -= c.Value.Item2;
}
if (count <= 0)
{
break;
}
}
}
@ -111,8 +116,9 @@ namespace AutomobilePlantFileImplement.Implements
count = countStore;
foreach (var shop in source.Shops)
for (int i = 0; i < source.Shops.Count; i++)
{
var shop = source.Shops[i];
var cars = shop.ShopCars;
foreach (var c in cars.Where(x => x.Value.Item1.Id == car.Id))
@ -136,13 +142,14 @@ namespace AutomobilePlantFileImplement.Implements
MaxCountCars = shop.MaxCountCars,
ShopCars = cars
});
source.SaveShops();
if (count <= 0) break;
}
return count <= 0;
if (count > 0)
{
return false;
}
return true;
}
}
}