Compare commits
3 Commits
c5b726ffc9
...
95a10df89d
Author | SHA1 | Date | |
---|---|---|---|
95a10df89d | |||
32f0c536d1 | |||
c5f4b3caf6 |
@ -18,6 +18,6 @@ namespace AutomobilePlantContracts.BusinessLogicContracts
|
|||||||
bool Update(ShopBindingModel model);
|
bool Update(ShopBindingModel model);
|
||||||
bool Delete(ShopBindingModel model);
|
bool Delete(ShopBindingModel model);
|
||||||
bool SupplyCars(ShopSearchModel model, ICarModel car, int count);
|
bool SupplyCars(ShopSearchModel model, ICarModel car, int count);
|
||||||
bool SellCar(ICarModel document, int count);
|
bool SellCar(ICarModel car, int count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -100,6 +100,7 @@ namespace AutomobilePlantDatabaseImplement.Implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
car.Update(model);
|
car.Update(model);
|
||||||
|
car.UpdateComponents(context, model);
|
||||||
|
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
context.Database.CommitTransaction();
|
context.Database.CommitTransaction();
|
||||||
|
@ -77,14 +77,17 @@ namespace AutomobilePlantDatabaseImplement.Implements
|
|||||||
using var transaction = context.Database.BeginTransaction();
|
using var transaction = context.Database.BeginTransaction();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var shop = context.Shops.FirstOrDefault(x => x.Id == model.Id);
|
var shop = context.Shops.Include(x => x.Cars).FirstOrDefault(x => x.Id == model.Id);
|
||||||
if (shop == null)
|
if (shop == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
shop.Update(model);
|
shop.Update(model);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
shop.UpdateCars(context, model);
|
if (model.ShopCars.Count > 0)
|
||||||
|
{
|
||||||
|
shop.UpdateCars(context, model);
|
||||||
|
}
|
||||||
transaction.Commit();
|
transaction.Commit();
|
||||||
return shop.GetViewModel;
|
return shop.GetViewModel;
|
||||||
}
|
}
|
||||||
|
@ -83,29 +83,24 @@ namespace AutomobilePlantFileImplement.Implements
|
|||||||
|
|
||||||
public bool SellCar(ICarModel model, int count)
|
public bool SellCar(ICarModel model, int count)
|
||||||
{
|
{
|
||||||
// переделать под linq
|
|
||||||
|
|
||||||
var car = source.Cars.FirstOrDefault(x => x.Id == model.Id);
|
var car = source.Cars.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
|
||||||
var countStore = count;
|
|
||||||
|
|
||||||
if (car == null)
|
if (car == null)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var shop in source.Shops)
|
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 c in shop.ShopCars)
|
count -= c.Value.Item2;
|
||||||
|
|
||||||
|
if (count <= 0)
|
||||||
{
|
{
|
||||||
if (c.Value.Item1.Id == car.Id)
|
break;
|
||||||
{
|
|
||||||
count -= c.Value.Item2;
|
|
||||||
}
|
|
||||||
if (count <= 0)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,9 +111,8 @@ namespace AutomobilePlantFileImplement.Implements
|
|||||||
|
|
||||||
count = countStore;
|
count = countStore;
|
||||||
|
|
||||||
for (int i = 0; i < source.Shops.Count; i++)
|
foreach (var shop in source.Shops)
|
||||||
{
|
{
|
||||||
var shop = source.Shops[i];
|
|
||||||
var cars = shop.ShopCars;
|
var cars = shop.ShopCars;
|
||||||
|
|
||||||
foreach (var c in cars.Where(x => x.Value.Item1.Id == car.Id))
|
foreach (var c in cars.Where(x => x.Value.Item1.Id == car.Id))
|
||||||
@ -142,14 +136,13 @@ namespace AutomobilePlantFileImplement.Implements
|
|||||||
MaxCountCars = shop.MaxCountCars,
|
MaxCountCars = shop.MaxCountCars,
|
||||||
ShopCars = cars
|
ShopCars = cars
|
||||||
});
|
});
|
||||||
|
|
||||||
source.SaveShops();
|
source.SaveShops();
|
||||||
|
|
||||||
|
if (count <= 0) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count > 0)
|
return count <= 0;
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user