complete
This commit is contained in:
parent
d5b4f75b15
commit
a6b496e8e1
@ -1,32 +1,153 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using SushiBar.BindingModels;
|
||||||
|
using SushiBar.ViewModels;
|
||||||
using SushiBarClientApp.Models;
|
using SushiBarClientApp.Models;
|
||||||
|
using SushiBarContracts.BindingModels;
|
||||||
|
using SushiBarContracts.ViewModels;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
|
||||||
namespace SushiBarClientApp.Controllers
|
namespace SushiBarClientApp.Controllers
|
||||||
{
|
{
|
||||||
public class HomeController : Controller
|
public class HomeController : Controller
|
||||||
{
|
{
|
||||||
private readonly ILogger<HomeController> _logger;
|
private readonly ILogger<HomeController> _logger;
|
||||||
|
public HomeController(ILogger<HomeController> logger)
|
||||||
public HomeController(ILogger<HomeController> logger)
|
{
|
||||||
{
|
_logger = logger;
|
||||||
_logger = logger;
|
}
|
||||||
|
public IActionResult Index()
|
||||||
|
{
|
||||||
|
if (APIClient.Client == null)
|
||||||
|
{
|
||||||
|
return Redirect("~/Home/Enter");
|
||||||
|
}
|
||||||
|
return
|
||||||
|
View(APIClient.GetRequest<List<OrderViewModel>>($"api/main/getorders?clientId={APIClient.Client.Id}"));
|
||||||
|
}
|
||||||
|
[HttpGet]
|
||||||
|
public IActionResult Privacy()
|
||||||
|
{
|
||||||
|
if (APIClient.Client == null)
|
||||||
|
{
|
||||||
|
return Redirect("~/Home/Enter");
|
||||||
|
}
|
||||||
|
return View(APIClient.Client);
|
||||||
|
}
|
||||||
|
[HttpPost]
|
||||||
|
public void Privacy(string login, string password, string fio)
|
||||||
|
{
|
||||||
|
if (APIClient.Client == null)
|
||||||
|
{
|
||||||
|
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(login) ||
|
||||||
|
string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio))
|
||||||
|
{
|
||||||
|
throw new Exception("Введите логин, пароль и ФИО");
|
||||||
|
}
|
||||||
|
APIClient.PostRequest("api/client/updatedata", new
|
||||||
|
ClientBindingModel
|
||||||
|
{
|
||||||
|
Id = APIClient.Client.Id,
|
||||||
|
ClientFIO = fio,
|
||||||
|
Email = login,
|
||||||
|
Password = password
|
||||||
|
});
|
||||||
|
APIClient.Client.ClientFIO = fio;
|
||||||
|
APIClient.Client.Email = login;
|
||||||
|
APIClient.Client.Password = password;
|
||||||
|
Response.Redirect("Index");
|
||||||
|
}
|
||||||
|
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None,
|
||||||
|
NoStore = true)]
|
||||||
|
public IActionResult Error()
|
||||||
|
{
|
||||||
|
return View(new ErrorViewModel
|
||||||
|
{
|
||||||
|
RequestId =
|
||||||
|
Activity.Current?.Id ?? HttpContext.TraceIdentifier
|
||||||
|
});
|
||||||
|
}
|
||||||
|
[HttpGet]
|
||||||
|
public IActionResult Enter()
|
||||||
|
{
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
[HttpPost]
|
||||||
|
public void Enter(string login, string password)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(login) ||
|
||||||
|
string.IsNullOrEmpty(password))
|
||||||
|
{
|
||||||
|
throw new Exception("Введите логин и пароль");
|
||||||
|
}
|
||||||
|
APIClient.Client =
|
||||||
|
APIClient.GetRequest<ClientViewModel>($"api/client/login?login={login}&password={password}");
|
||||||
|
if (APIClient.Client == null)
|
||||||
|
{
|
||||||
|
throw new Exception("Неверный логин/пароль");
|
||||||
|
}
|
||||||
|
Response.Redirect("Index");
|
||||||
|
}
|
||||||
|
[HttpGet]
|
||||||
|
public IActionResult Register()
|
||||||
|
{
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
[HttpPost]
|
||||||
|
public void Register(string login, string password, string fio)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(login) ||
|
||||||
|
string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio))
|
||||||
|
{
|
||||||
|
throw new Exception("Введите логин, пароль и ФИО");
|
||||||
|
}
|
||||||
|
APIClient.PostRequest("api/client/register", new
|
||||||
|
ClientBindingModel
|
||||||
|
{
|
||||||
|
ClientFIO = fio,
|
||||||
|
Email = login,
|
||||||
|
Password = password
|
||||||
|
});
|
||||||
|
Response.Redirect("Enter");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
[HttpGet]
|
||||||
|
public IActionResult Create()
|
||||||
|
{
|
||||||
|
ViewBag.Sushis =
|
||||||
|
APIClient.GetRequest<List<SushiViewModel>>("api/main/getsushilist");
|
||||||
|
return View();
|
||||||
|
}
|
||||||
|
[HttpPost]
|
||||||
|
public void Create(int sushi, 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,
|
||||||
|
SushiId = sushi,
|
||||||
|
Count = count,
|
||||||
|
Sum = Calc(count, sushi)
|
||||||
|
});
|
||||||
|
Response.Redirect("Index");
|
||||||
|
}
|
||||||
|
[HttpPost]
|
||||||
|
public double Calc(int count, int sushi)
|
||||||
|
{
|
||||||
|
var prod =
|
||||||
|
APIClient.GetRequest<SushiViewModel>($"api/main/getsushi?sushiId={sushi}"
|
||||||
|
);
|
||||||
|
return count * (prod?.Price ?? 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IActionResult Index()
|
|
||||||
{
|
|
||||||
return View();
|
|
||||||
}
|
|
||||||
|
|
||||||
public IActionResult Privacy()
|
|
||||||
{
|
|
||||||
return View();
|
|
||||||
}
|
|
||||||
|
|
||||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
|
||||||
public IActionResult Error()
|
|
||||||
{
|
|
||||||
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@ -1,27 +1,23 @@
|
|||||||
|
using SushiBarClientApp;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using SushiBarClientApp;
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
// Add services to the container.
|
// Add services to the container.
|
||||||
builder.Services.AddControllersWithViews();
|
builder.Services.AddControllersWithViews();
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
APIClient.Connect(builder.Configuration);
|
||||||
// Configure the HTTP request pipeline.
|
// Configure the HTTP request pipeline.
|
||||||
if (!app.Environment.IsDevelopment())
|
if (!app.Environment.IsDevelopment())
|
||||||
{
|
{
|
||||||
app.UseExceptionHandler("/Home/Error");
|
app.UseExceptionHandler("/Home/Error");
|
||||||
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
|
// The default HSTS value is 30 days. You may want to change this for sushiion scenarios, see https://aka.ms/aspnetcore-hsts.
|
||||||
app.UseHsts();
|
app.UseHsts();
|
||||||
}
|
}
|
||||||
|
|
||||||
app.UseHttpsRedirection();
|
app.UseHttpsRedirection();
|
||||||
app.UseStaticFiles();
|
app.UseStaticFiles();
|
||||||
|
|
||||||
app.UseRouting();
|
app.UseRouting();
|
||||||
|
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
|
|
||||||
app.MapControllerRoute(
|
app.MapControllerRoute(
|
||||||
name: "default",
|
name: "default",
|
||||||
pattern: "{controller=Home}/{action=Index}/{id?}");
|
pattern: "{controller=Home}/{action=Index}/{id?}");
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
50
SushiBar/SushiBarClientApp/Views/Home/Create.cshtml
Normal file
50
SushiBar/SushiBarClientApp/Views/Home/Create.cshtml
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
@{
|
||||||
|
ViewData["Title"] = "Create";
|
||||||
|
}
|
||||||
|
<div class="text-center">
|
||||||
|
<h2 class="display-4">Создание заказа</h2>
|
||||||
|
</div>
|
||||||
|
<form method="post">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-4">Изделие:</div>
|
||||||
|
<div class="col-8">
|
||||||
|
<select id="sushi" name="sushi" class="form-control" asp-items="@(new SelectList(@ViewBag.Sushis,"Id", "SushiName"))"></select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-4">Количество:</div>
|
||||||
|
<div class="col-8"><input type="text" name="count" id="count" /></div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-4">Сумма:</div>
|
||||||
|
<div class="col-8"><input type="text" id="sum" name="sum" readonly /></div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-8"></div>
|
||||||
|
<div class="col-4"><input type="submit" value="Создать" class="btn btn-primary" /></div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
$('#sushi').on('change', function () {
|
||||||
|
check();
|
||||||
|
});
|
||||||
|
$('#count').on('change', function () {
|
||||||
|
check();
|
||||||
|
});
|
||||||
|
|
||||||
|
function check() {
|
||||||
|
var count = $('#count').val();
|
||||||
|
var sushi = $('#sushi').val();
|
||||||
|
if (count && sushi) {
|
||||||
|
$.ajax({
|
||||||
|
method: "POST",
|
||||||
|
url: "/Home/Calc",
|
||||||
|
data: { count: count, sushi: sushi },
|
||||||
|
success: function (result) {
|
||||||
|
$("#sum").val(result);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
</script>
|
21
SushiBar/SushiBarClientApp/Views/Home/Enter.cshtml
Normal file
21
SushiBar/SushiBarClientApp/Views/Home/Enter.cshtml
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
@{
|
||||||
|
ViewData["Title"] = "Enter";
|
||||||
|
}
|
||||||
|
|
||||||
|
<div class="text-center">
|
||||||
|
<h2 class="display-4">Вход в приложение</h2>
|
||||||
|
</div>
|
||||||
|
<form method="post">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-4">Логин:</div>
|
||||||
|
<div class="col-8"><input type="text" name="login" /></div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-4">Пароль:</div>
|
||||||
|
<div class="col-8"><input type="password" name="password" /></div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-8"></div>
|
||||||
|
<div class="col-4"><input type="submit" value="Вход" class="btn btn-primary" /></div>
|
||||||
|
</div>
|
||||||
|
</form>
|
@ -1,8 +1,75 @@
|
|||||||
@{
|
@using SushiBarContracts.ViewModels
|
||||||
ViewData["Title"] = "Home Page";
|
|
||||||
|
@model List<OrderViewModel>
|
||||||
|
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Home Page";
|
||||||
}
|
}
|
||||||
|
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
<h1 class="display-4">Welcome</h1>
|
<h1 class="display-4">Заказы</h1>
|
||||||
<p>Learn about <a href="https://docs.microsoft.com/aspnet/core">building Web apps with ASP.NET Core</a>.</p>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="text-center">
|
||||||
|
@{
|
||||||
|
if (Model == null)
|
||||||
|
{
|
||||||
|
<h3 class="display-4">Авторизируйтесь</h3>
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<a asp-action="Create">Создать заказ</a>
|
||||||
|
</p>
|
||||||
|
<table class="table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>
|
||||||
|
Номер
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
Суши
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
Дата создания
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
Количество
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
Сумма
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
Статус
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach (var item in Model)
|
||||||
|
{
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
@Html.DisplayFor(modelItem => item.Id)
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@Html.DisplayFor(modelItem => item.SushiName)
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@Html.DisplayFor(modelItem => item.DateCreate)
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@Html.DisplayFor(modelItem => item.Count)
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@Html.DisplayFor(modelItem => item.Sum)
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@Html.DisplayFor(modelItem => item.Status)
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
}
|
||||||
</div>
|
</div>
|
@ -1,6 +1,28 @@
|
|||||||
@{
|
@using SushiBar.ViewModels
|
||||||
ViewData["Title"] = "Privacy Policy";
|
@using SushiBarContracts.ViewModels
|
||||||
}
|
@model ClientViewModel
|
||||||
<h1>@ViewData["Title"]</h1>
|
|
||||||
|
|
||||||
<p>Use this page to detail your site's privacy policy.</p>
|
@{
|
||||||
|
ViewData["Title"] = "Privacy Policy";
|
||||||
|
}
|
||||||
|
<div class="text-center">
|
||||||
|
<h2 class="display-4">Личные данные</h2>
|
||||||
|
</div>
|
||||||
|
<form method="post">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-4">Логин:</div>
|
||||||
|
<div class="col-8"><input type="text" name="login" value="@Model.Email" /></div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-4">Пароль:</div>
|
||||||
|
<div class="col-8"><input type="password" name="password" value="@Model.Password" /></div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-4">ФИО:</div>
|
||||||
|
<div class="col-8"><input type="text" name="fio" value="@Model.ClientFIO" /></div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-8"></div>
|
||||||
|
<div class="col-4"><input type="submit" value="Сохранить" class="btn btn-primary" /></div>
|
||||||
|
</div>
|
||||||
|
</form>
|
25
SushiBar/SushiBarClientApp/Views/Home/Register.cshtml
Normal file
25
SushiBar/SushiBarClientApp/Views/Home/Register.cshtml
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
@{
|
||||||
|
ViewData["Title"] = "Register";
|
||||||
|
}
|
||||||
|
|
||||||
|
<div class="text-center">
|
||||||
|
<h2 class="display-4">Регистрация</h2>
|
||||||
|
</div>
|
||||||
|
<form method="post">
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-4">Логин:</div>
|
||||||
|
<div class="col-8"><input type="text" name="login" /></div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-4">Пароль:</div>
|
||||||
|
<div class="col-8"><input type="password" name="password" /></div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-4">ФИО:</div>
|
||||||
|
<div class="col-8"><input type="text" name="fio" /></div>
|
||||||
|
</div>
|
||||||
|
<div class="row">
|
||||||
|
<div class="col-8"></div>
|
||||||
|
<div class="col-4"><input type="submit" value="Регистрация" class="btn btn-primary" /></div>
|
||||||
|
</div>
|
||||||
|
</form>
|
@ -7,23 +7,31 @@
|
|||||||
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
|
<link rel="stylesheet" href="~/lib/bootstrap/dist/css/bootstrap.min.css" />
|
||||||
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
|
<link rel="stylesheet" href="~/css/site.css" asp-append-version="true" />
|
||||||
<link rel="stylesheet" href="~/SushiBarClientApp.styles.css" asp-append-version="true" />
|
<link rel="stylesheet" href="~/SushiBarClientApp.styles.css" asp-append-version="true" />
|
||||||
|
<script src="~/lib/jquery/dist/jquery.min.js"></script>
|
||||||
|
<script src="~/lib/bootstrap/dist/js/bootstrap.bundle.min.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<header>
|
<header>
|
||||||
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
|
<nav class="navbar navbar-expand-sm navbar-toggleable-sm navbar-light bg-white border-bottom box-shadow mb-3">
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">SushiBarClientApp</a>
|
<a class="navbar-brand" asp-area="" asp-controller="Home" asp-action="Index">Суши-Бар</a>
|
||||||
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target=".navbar-collapse" aria-controls="navbarSupportedContent"
|
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target=".navbar-collapse" aria-controls="navbarSupportedContent"
|
||||||
aria-expanded="false" aria-label="Toggle navigation">
|
aria-expanded="false" aria-label="Toggle navigation">
|
||||||
<span class="navbar-toggler-icon"></span>
|
<span class="navbar-toggler-icon"></span>
|
||||||
</button>
|
</button>
|
||||||
<div class="navbar-collapse collapse d-sm-inline-flex justify-content-between">
|
<div class="navbar-collapse collapse d-sm-inline-flex flex-sm-row-reverse">
|
||||||
<ul class="navbar-nav flex-grow-1">
|
<ul class="navbar-nav flex-grow-1">
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Home</a>
|
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Index">Заказы</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Privacy</a>
|
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Личные данные</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Enter">Вход</a>
|
||||||
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Register">Регистрация</a>
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
@ -6,5 +6,5 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"AllowedHosts": "*",
|
"AllowedHosts": "*",
|
||||||
"IPAddress": "http://localhost:7100/"
|
"IPAddress": "http://localhost:5037/"
|
||||||
}
|
}
|
@ -22,10 +22,6 @@ namespace SushiBarDatabaseImplement.Implements
|
|||||||
|
|
||||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||||
{
|
{
|
||||||
if (!model.DateFrom.HasValue || !model.DateTo.HasValue)
|
|
||||||
{
|
|
||||||
return new();
|
|
||||||
}
|
|
||||||
using var context = new SushiBarDatabase();
|
using var context = new SushiBarDatabase();
|
||||||
if (model.DateFrom.HasValue)
|
if (model.DateFrom.HasValue)
|
||||||
{
|
{
|
||||||
@ -35,6 +31,10 @@ namespace SushiBarDatabaseImplement.Implements
|
|||||||
{
|
{
|
||||||
return context.Orders.Include(x => x.Sushi).Where(x => x.ClientId == model.ClientId).Select(x => x.GetViewModel).ToList();
|
return context.Orders.Include(x => x.Sushi).Where(x => x.ClientId == model.ClientId).Select(x => x.GetViewModel).ToList();
|
||||||
}
|
}
|
||||||
|
if (model.ClientId.HasValue)
|
||||||
|
{
|
||||||
|
return context.Orders.Include(x => x.Sushi).Where(x => x.ClientId == model.ClientId).Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
return context.Orders.Include(x => x.Sushi).Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList();
|
return context.Orders.Include(x => x.Sushi).Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,6 +67,8 @@ namespace SushiBarDatabaseImplement.Models
|
|||||||
public OrderViewModel GetViewModel => new()
|
public OrderViewModel GetViewModel => new()
|
||||||
{
|
{
|
||||||
Id = Id,
|
Id = Id,
|
||||||
|
ClientId = ClientId,
|
||||||
|
ClientFIO = Client.ClientFIO,
|
||||||
SushiId = SushiId,
|
SushiId = SushiId,
|
||||||
SushiName = Sushi.SushiName,
|
SushiName = Sushi.SushiName,
|
||||||
Count = Count,
|
Count = Count,
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
using PizzeriaFileImplement.Models;
|
using SushiBarFileImplement.Models;
|
||||||
using SushiBarFileImplement.Models;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
@ -105,12 +105,12 @@ namespace SushiBarFileImplement.Implements
|
|||||||
{
|
{
|
||||||
var viewModel = order.GetViewModel;
|
var viewModel = order.GetViewModel;
|
||||||
|
|
||||||
var pizza = source.Sushis.FirstOrDefault(x => x.Id == order.SushiId);
|
var sushi = source.Sushis.FirstOrDefault(x => x.Id == order.SushiId);
|
||||||
var client = source.Clients.FirstOrDefault(x => x.Id == order.ClientId);
|
var client = source.Clients.FirstOrDefault(x => x.Id == order.ClientId);
|
||||||
|
|
||||||
if (pizza != null)
|
if (sushi != null)
|
||||||
{
|
{
|
||||||
viewModel.SushiName = pizza.SushiName;
|
viewModel.SushiName = sushi.SushiName;
|
||||||
}
|
}
|
||||||
if (client != null)
|
if (client != null)
|
||||||
{
|
{
|
||||||
|
@ -5,7 +5,7 @@ using SushiBarContracts.ViewModels;
|
|||||||
using SushiBarDataModels.Models;
|
using SushiBarDataModels.Models;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
|
|
||||||
namespace PizzeriaFileImplement.Models
|
namespace SushiBarFileImplement.Models
|
||||||
{
|
{
|
||||||
public class Client : IClientModel
|
public class Client : IClientModel
|
||||||
{
|
{
|
||||||
|
@ -13,19 +13,19 @@ namespace SushiBarRestApi.Controllers
|
|||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IOrderLogic _order;
|
private readonly IOrderLogic _order;
|
||||||
private readonly ISushiLogic _product;
|
private readonly ISushiLogic _sushi;
|
||||||
public MainController(ILogger<MainController> logger, IOrderLogic order, ISushiLogic product)
|
public MainController(ILogger<MainController> logger, IOrderLogic order, ISushiLogic sushi)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_order = order;
|
_order = order;
|
||||||
_product = product;
|
_sushi = sushi;
|
||||||
}
|
}
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public List<SushiViewModel>? GetProductList()
|
public List<SushiViewModel>? GetSushiList()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return _product.ReadList(null);
|
return _sushi.ReadList(null);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@ -34,20 +34,19 @@ namespace SushiBarRestApi.Controllers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public SushiViewModel? GetProduct(int productId)
|
public SushiViewModel? GetSushi(int sushiId)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return _product.ReadElement(new SushiSearchModel
|
return _sushi.ReadElement(new SushiSearchModel
|
||||||
{
|
{
|
||||||
Id =
|
Id =
|
||||||
productId
|
sushiId
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogError(ex, "Ошибка получения продукта по id={Id}",
|
_logger.LogError(ex, "Ошибка получения продукта по id={Id}", sushiId);
|
||||||
productId);
|
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,33 +0,0 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
|
||||||
|
|
||||||
namespace SushiBarRestApi.Controllers
|
|
||||||
{
|
|
||||||
[ApiController]
|
|
||||||
[Route("[controller]")]
|
|
||||||
public class WeatherForecastController : ControllerBase
|
|
||||||
{
|
|
||||||
private static readonly string[] Summaries = new[]
|
|
||||||
{
|
|
||||||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
|
|
||||||
};
|
|
||||||
|
|
||||||
private readonly ILogger<WeatherForecastController> _logger;
|
|
||||||
|
|
||||||
public WeatherForecastController(ILogger<WeatherForecastController> logger)
|
|
||||||
{
|
|
||||||
_logger = logger;
|
|
||||||
}
|
|
||||||
|
|
||||||
[HttpGet(Name = "GetWeatherForecast")]
|
|
||||||
public IEnumerable<WeatherForecast> Get()
|
|
||||||
{
|
|
||||||
return Enumerable.Range(1, 5).Select(index => new WeatherForecast
|
|
||||||
{
|
|
||||||
Date = DateTime.Now.AddDays(index),
|
|
||||||
TemperatureC = Random.Shared.Next(-20, 55),
|
|
||||||
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
|
|
||||||
})
|
|
||||||
.ToArray();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
namespace SushiBarRestApi
|
|
||||||
{
|
|
||||||
public class WeatherForecast
|
|
||||||
{
|
|
||||||
public DateTime Date { get; set; }
|
|
||||||
|
|
||||||
public int TemperatureC { get; set; }
|
|
||||||
|
|
||||||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
|
|
||||||
|
|
||||||
public string? Summary { get; set; }
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user