Фикс способа получения названия блюда в заказе.
This commit is contained in:
parent
0cd61aa427
commit
f14c91fa8c
@ -111,12 +111,11 @@ namespace AbstractFoodOrdersClientApp.Controllers
|
||||
[HttpGet]
|
||||
public IActionResult Create()
|
||||
{
|
||||
ViewBag.Dishes =
|
||||
APIClient.GetRequest<List<DishViewModel>>("api/main/getproductlist");
|
||||
ViewBag.Dishes = APIClient.GetRequest<List<DishViewModel>>("api/main/getdishlist");
|
||||
return View();
|
||||
}
|
||||
[HttpPost]
|
||||
public void Create(int dish, int count)
|
||||
public void Create(int product, int count)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
@ -130,17 +129,16 @@ namespace AbstractFoodOrdersClientApp.Controllers
|
||||
OrderBindingModel
|
||||
{
|
||||
ClientId = APIClient.Client.Id,
|
||||
DishId = dish,
|
||||
DishId = product,
|
||||
Count = count,
|
||||
Sum = Calc(count, dish)
|
||||
Sum = Calc(count, product)
|
||||
});
|
||||
Response.Redirect("Index");
|
||||
}
|
||||
[HttpPost]
|
||||
public double Calc(int count, int dish)
|
||||
public double Calc(int count, int product)
|
||||
{
|
||||
var prod =
|
||||
APIClient.GetRequest<DishViewModel>($"api/main/getproduct?productId={dish}"
|
||||
var prod = APIClient.GetRequest<DishViewModel>($"api/main/getdish?dishId={product}"
|
||||
);
|
||||
return count * (prod?.Price ?? 1);
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
<div class="row">
|
||||
<div class="col-4">Блюдо:</div>
|
||||
<div class="col-8">
|
||||
<select id="product" name="product" class="form-control" aspitems="@(new SelectList(@ViewBag.Dishes,"Id", "DishName"))"></select>
|
||||
<select id="product" name="product" class="form-control" asp-items="@(new SelectList(@ViewBag.Dishes, "Id", "DishName"))"></select>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
@ -26,8 +26,7 @@
|
||||
<div class="row">
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4">
|
||||
<input type="submit" value="Создать" class="btn
|
||||
btn-primary" />
|
||||
<input type="submit" value="Создать" class="btn btn-primary" />
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
|
@ -23,19 +23,35 @@ namespace AbstractFoodOrdersDatabaseImplement.Implements
|
||||
}
|
||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||
{
|
||||
if ((!model.DateFrom.HasValue || !model.DateTo.HasValue) && !model.ClientId.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
using var context = new AbstractFoodOrdersDatabase();
|
||||
return context.Orders
|
||||
.Include(x => x.Dish)
|
||||
.Include(x => x.Client)
|
||||
.Where(x => (model.DateFrom.HasValue && model.DateTo.HasValue && x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo) ||
|
||||
(x.ClientId == model.ClientId))
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
if (!model.Id.HasValue && !model.DateFrom.HasValue && !model.DateTo.HasValue && !model.ClientId.HasValue)
|
||||
{
|
||||
return new();
|
||||
}
|
||||
if (model.ClientId.HasValue)
|
||||
{
|
||||
using var context = new AbstractFoodOrdersDatabase();
|
||||
return context.Orders.Include(x => x.Client)
|
||||
.Where(x => x.ClientId == model.ClientId)
|
||||
.Select(x => AccessDishStorage(x.GetViewModel, context))
|
||||
.ToList();
|
||||
}
|
||||
else if (!model.DateFrom.HasValue || !model.DateTo.HasValue)
|
||||
{
|
||||
using var context = new AbstractFoodOrdersDatabase();
|
||||
return context.Orders.Include(x => x.Client)
|
||||
.Where(x => x.Id == model.Id)
|
||||
.Select(x => AccessDishStorage(x.GetViewModel, context))
|
||||
.ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
using var context = new AbstractFoodOrdersDatabase();
|
||||
return context.Orders.Include(x => x.Client)
|
||||
.Where(x => x.DateCreate >= model.DateFrom && x.DateCreate <= model.DateTo)
|
||||
.Select(x => AccessDishStorage(x.GetViewModel, context))
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||
{
|
||||
if (!model.Id.HasValue)
|
||||
|
@ -41,8 +41,7 @@ namespace AbstractFoodOrdersRestApi.Controllers
|
||||
{
|
||||
return _dish.ReadElement(new DishSearchModel
|
||||
{
|
||||
Id =
|
||||
dishId
|
||||
Id = dishId
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
Loading…
Reference in New Issue
Block a user