diff --git a/CarShowroom/CarShowroomDatabaseStorage/Storages/CarStorage.cs b/CarShowroom/CarShowroomDatabaseStorage/Storages/CarStorage.cs index d36ded9..103a142 100644 --- a/CarShowroom/CarShowroomDatabaseStorage/Storages/CarStorage.cs +++ b/CarShowroom/CarShowroomDatabaseStorage/Storages/CarStorage.cs @@ -26,7 +26,7 @@ namespace CarShowroomDatabaseStorage.Storages public List GetFilteredList(CarSearch model) { - if (!model.Id.HasValue) + if (!model.Id.HasValue && !model.IsSaled.HasValue) { return new(); } diff --git a/CarShowroom/CarShowroomDatabaseStorage/Storages/SaleStorage.cs b/CarShowroom/CarShowroomDatabaseStorage/Storages/SaleStorage.cs index ad92b77..b7e9e88 100644 --- a/CarShowroom/CarShowroomDatabaseStorage/Storages/SaleStorage.cs +++ b/CarShowroom/CarShowroomDatabaseStorage/Storages/SaleStorage.cs @@ -57,8 +57,8 @@ namespace CarShowroomDatabaseStorage.Storages var newSale = Sale.Create(model); if (newSale == null) throw new InvalidOperationException("SaleId is incorrect"); - int saleId = context.Sales.Add(newSale).CurrentValues.GetValue("Id"); context.SaveChanges(); + int saleId = context.Sales.Add(newSale).CurrentValues.GetValue("Id"); SaleView result = UpdateCarsAndServices(context, model, saleId); transaction.Commit(); return result; diff --git a/CarShowroom/CarShowroomManagerApp/Controllers/HomeController.cs b/CarShowroom/CarShowroomManagerApp/Controllers/HomeController.cs index ec32675..33c8c1c 100644 --- a/CarShowroom/CarShowroomManagerApp/Controllers/HomeController.cs +++ b/CarShowroom/CarShowroomManagerApp/Controllers/HomeController.cs @@ -80,27 +80,22 @@ namespace CarShowroomManagerApp.Controllers return View(); } - //[HttpPost] - //public void SaleCreate(int manufacture, int count) - //{ - // if (APIClient.Client == null) - // { - // throw new Exception("Вы как суда попали? Суда вход только авторизованным"); - // } - // if (count <= 0) - // { - // throw new Exception("Количество и сумма должны быть больше 0"); - // } - // APIClient.PostRequest("api/main/createorder", new - // OrderBindingModel - // { - // ClientId = APIClient.Client.Id, - // ManufactureId = manufacture, - // Count = count, - // Sum = Calc(count, manufacture) - // }); - // Response.Redirect("Index"); - //} + [HttpPost] + public void SaleCreate(int client, List cars, List services) + { + if (ApiClient.Client == null) + { + Redirect("~/Home/Enter"); + } + ApiClient.PostRequest("api/sale/createsale", new + SaleDto + { + ClientId = client, + CarIds = cars, + ServiceIds = services + }); + Response.Redirect("Index"); + } public IActionResult ClientCreate() { @@ -137,7 +132,7 @@ namespace CarShowroomManagerApp.Controllers } [HttpPost] - public void ClientUpdate(string phonenumber, string name) + public void ClientUpdate(int client, string phonenumber, string name) { if (ApiClient.Client == null) { @@ -150,7 +145,7 @@ namespace CarShowroomManagerApp.Controllers } ApiClient.PostRequest("api/client/updateclient", new ClientDto { - Id = ApiClient.Client.Id, + Id = client, Name = name, PhoneNumber = phonenumber });