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