sale works
This commit is contained in:
parent
fcafbcfdac
commit
9899ddddb6
@ -19,6 +19,8 @@ namespace CarShowroomDatabaseStorage.Storages
|
||||
{
|
||||
using var context = new CarShowroomDatabase();
|
||||
return context.Sales
|
||||
.Include(s => s.Client)
|
||||
.Include(s => s.Employee)
|
||||
.Select(x => x.GetView())
|
||||
.ToList();
|
||||
}
|
||||
@ -31,6 +33,8 @@ namespace CarShowroomDatabaseStorage.Storages
|
||||
}
|
||||
using var context = new CarShowroomDatabase();
|
||||
return context.Sales
|
||||
.Include(s => s.Client)
|
||||
.Include(s => s.Employee)
|
||||
.Where(x => !model.Id.HasValue || x.Id == model.Id)
|
||||
.Select(x => x.GetView())
|
||||
.ToList();
|
||||
@ -58,8 +62,8 @@ namespace CarShowroomDatabaseStorage.Storages
|
||||
if (newSale == null)
|
||||
throw new InvalidOperationException("SaleId is incorrect");
|
||||
context.SaveChanges();
|
||||
int saleId = context.Sales.Add(newSale).CurrentValues.GetValue<int>("Id");
|
||||
SaleView result = UpdateCarsAndServices(context, model, saleId);
|
||||
context.Sales.Add(newSale);
|
||||
SaleView result = UpdateCarsAndServices(context, model, newSale);
|
||||
transaction.Commit();
|
||||
return result;
|
||||
}
|
||||
@ -82,7 +86,7 @@ namespace CarShowroomDatabaseStorage.Storages
|
||||
throw new InvalidOperationException("SaleId is incorrect");
|
||||
sale.Update(model);
|
||||
context.SaveChanges();
|
||||
SaleView result = UpdateCarsAndServices(context, model, sale.Id);
|
||||
SaleView result = UpdateCarsAndServices(context, model, sale);
|
||||
transaction.Commit();
|
||||
return result;
|
||||
}
|
||||
@ -108,9 +112,8 @@ namespace CarShowroomDatabaseStorage.Storages
|
||||
}
|
||||
|
||||
private SaleView UpdateCarsAndServices(CarShowroomDatabase context,
|
||||
SaleDto model, int saleId)
|
||||
SaleDto model, Sale sale)
|
||||
{
|
||||
var sale = context.Sales.First(x => x.Id == saleId);
|
||||
var saleCars = context.SaleCars
|
||||
.Where(rec => rec.SaleId == model.Id)
|
||||
.ToList();
|
||||
@ -151,27 +154,20 @@ namespace CarShowroomDatabaseStorage.Storages
|
||||
});
|
||||
context.SaveChanges();
|
||||
}
|
||||
return UpdatePrice(context, saleId);
|
||||
return UpdatePrice(context, sale);
|
||||
}
|
||||
|
||||
private SaleView UpdatePrice(CarShowroomDatabase context, int saleId)
|
||||
private SaleView UpdatePrice(CarShowroomDatabase context, Sale sale)
|
||||
{
|
||||
Sale? sale = context.Sales
|
||||
.FirstOrDefault(rec => rec.Id == saleId);
|
||||
if (sale == null)
|
||||
throw new InvalidOperationException("SaleId is incorrect");
|
||||
List<Car> Cars = context.Cars
|
||||
.Include(c => c.Model)
|
||||
.Include(c => c.SaleCars)
|
||||
.Where(c => c.SaleCars
|
||||
.Select(sc => sc.SaleId)
|
||||
.Contains(saleId))
|
||||
.Where(c => sale.CarIds.Contains(c.Id))
|
||||
.ToList();
|
||||
List<Service> Services = context.Services
|
||||
.Include(s => s.SaleServices)
|
||||
.Where(s => s.SaleServices
|
||||
.Select(ss => ss.SaleId)
|
||||
.Contains(saleId))
|
||||
.Where(s => sale.ServiceIds.Contains(s.Id))
|
||||
.ToList();
|
||||
int price = 0;
|
||||
foreach(Car car in Cars)
|
||||
|
@ -86,10 +86,12 @@ namespace CarShowroomManagerApp.Controllers
|
||||
if (ApiClient.Client == null)
|
||||
{
|
||||
Redirect("~/Home/Enter");
|
||||
return;
|
||||
}
|
||||
ApiClient.PostRequest("api/sale/createsale", new
|
||||
SaleDto
|
||||
{
|
||||
EmployeeId = ApiClient.Client.Id,
|
||||
ClientId = client,
|
||||
CarIds = cars,
|
||||
ServiceIds = services
|
||||
|
@ -22,8 +22,9 @@
|
||||
<tr>
|
||||
<th>Номер</th>
|
||||
<th>Цена</th>
|
||||
<th>Дата открытия</th>
|
||||
<th>Время продажи</th>
|
||||
<th>Менеджер</th>
|
||||
<th>Клиент</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@ -38,6 +39,10 @@
|
||||
@Html.DisplayFor(modelItem =>
|
||||
item.Price)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem =>
|
||||
item.SaleTime)
|
||||
</td>
|
||||
<td>
|
||||
@Html.DisplayFor(modelItem =>
|
||||
item.EmployeeName)
|
||||
|
Loading…
Reference in New Issue
Block a user