пользовательские интерфейсы для почты

This commit is contained in:
bekodeg 2024-05-22 08:59:54 +04:00
parent 2480e8c0a6
commit 729cba5416
3 changed files with 104 additions and 13 deletions

View File

@ -22,6 +22,7 @@ namespace SushiBarClientApp.Controllers
return return
View(APIClient.GetRequest<List<OrderViewModel>>($"api/main/getorders?clientId={APIClient.Client.Id}")); View(APIClient.GetRequest<List<OrderViewModel>>($"api/main/getorders?clientId={APIClient.Client.Id}"));
} }
[HttpGet] [HttpGet]
public IActionResult Privacy() public IActionResult Privacy()
{ {
@ -31,6 +32,7 @@ namespace SushiBarClientApp.Controllers
} }
return View(APIClient.Client); return View(APIClient.Client);
} }
[HttpPost] [HttpPost]
public void Privacy(string login, string password, string fio) public void Privacy(string login, string password, string fio)
{ {
@ -38,8 +40,7 @@ namespace SushiBarClientApp.Controllers
{ {
throw new Exception("Вы как суда попали? Суда вход только авторизованным"); throw new Exception("Вы как суда попали? Суда вход только авторизованным");
} }
if (string.IsNullOrEmpty(login) || if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio))
string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio))
{ {
throw new Exception("Введите логин, пароль и ФИО"); throw new Exception("Введите логин, пароль и ФИО");
} }
@ -56,6 +57,7 @@ namespace SushiBarClientApp.Controllers
APIClient.Client.Password = password; APIClient.Client.Password = password;
Response.Redirect("Index"); Response.Redirect("Index");
} }
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)] [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error() public IActionResult Error()
{ {
@ -65,16 +67,17 @@ namespace SushiBarClientApp.Controllers
Activity.Current?.Id ?? HttpContext.TraceIdentifier Activity.Current?.Id ?? HttpContext.TraceIdentifier
}); });
} }
[HttpGet] [HttpGet]
public IActionResult Enter() public IActionResult Enter()
{ {
return View(); return View();
} }
[HttpPost] [HttpPost]
public void Enter(string login, string password) public void Enter(string login, string password)
{ {
if (string.IsNullOrEmpty(login) || if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password))
string.IsNullOrEmpty(password))
{ {
throw new Exception("Введите логин и пароль"); throw new Exception("Введите логин и пароль");
} }
@ -85,16 +88,17 @@ namespace SushiBarClientApp.Controllers
} }
Response.Redirect("Index"); Response.Redirect("Index");
} }
[HttpGet] [HttpGet]
public IActionResult Register() public IActionResult Register()
{ {
return View(); return View();
} }
[HttpPost] [HttpPost]
public void Register(string login, string password, string fio) public void Register(string login, string password, string fio)
{ {
if (string.IsNullOrEmpty(login) || if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio))
string.IsNullOrEmpty(password) || string.IsNullOrEmpty(fio))
{ {
throw new Exception("Введите логин, пароль и ФИО"); throw new Exception("Введите логин, пароль и ФИО");
} }
@ -108,12 +112,14 @@ namespace SushiBarClientApp.Controllers
Response.Redirect("Enter"); Response.Redirect("Enter");
return; return;
} }
[HttpGet] [HttpGet]
public IActionResult Create() public IActionResult Create()
{ {
ViewBag.Sushis = APIClient.GetRequest<List<SushiViewModel>>("api/main/getsushilist"); ViewBag.Sushis = APIClient.GetRequest<List<SushiViewModel>>("api/main/getsushilist");
return View(); return View();
} }
[HttpPost] [HttpPost]
public void Create(int sushi, int count) public void Create(int sushi, int count)
{ {
@ -125,8 +131,7 @@ namespace SushiBarClientApp.Controllers
{ {
throw new Exception("Количество и сумма должны быть больше 0"); throw new Exception("Количество и сумма должны быть больше 0");
} }
APIClient.PostRequest("api/main/createorder", new APIClient.PostRequest("api/main/createorder", new OrderBindingModel
OrderBindingModel
{ {
ClientId = APIClient.Client.Id, ClientId = APIClient.Client.Id,
SushiId = sushi, SushiId = sushi,
@ -135,13 +140,23 @@ namespace SushiBarClientApp.Controllers
}); });
Response.Redirect("Index"); Response.Redirect("Index");
} }
[HttpPost] [HttpPost]
public double Calc(int count, int sushi) public double Calc(int count, int sushi)
{ {
var _sushi = var _sushi = APIClient.GetRequest<SushiViewModel>($"api/main/getsushi?sushiid={sushi}");
APIClient.GetRequest<SushiViewModel>($"api/main/getsushi?sushiid={sushi}"
);
return Math.Round(count * (_sushi?.Price ?? 1), 2); return Math.Round(count * (_sushi?.Price ?? 1), 2);
} }
}
[HttpGet]
public IActionResult Mails()
{
if (APIClient.Client == null)
{
return Redirect("~/Home/Enter");
}
return
View(APIClient.GetRequest<List<MessageInfoViewModel>>($"api/client/getmessages?clientId={APIClient.Client.Id}"));
}
}
} }

View File

@ -0,0 +1,54 @@
@using SushiBarContracts.ViewModels
@model List<MessageInfoViewModel>
@{
ViewData["Title"] = "Mails";
}
<div class="text-center">
<h1 class="display-4">Заказы</h1>
</div>
<div class="text-center">
@{
if (Model == null)
{
<h3 class="display-4">Авторизируйтесь</h3>
return;
}
<table class="table">
<thead>
<tr>
<th>
Дата письма
</th>
<th>
Заголовок
</th>
<th>
Текст
</th>
</tr>
</thead>
<tbody>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.DateDelivery)
</td>
<td>
@Html.DisplayFor(modelItem => item.Subject)
</td>
<td>
@Html.DisplayFor(modelItem => item.Body)
</td>
</tr>
}
</tbody>
</table>
}
</div>

View File

@ -12,11 +12,14 @@ namespace SushiBarRestApi.Controllers
{ {
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IClientLogic _logic; private readonly IClientLogic _logic;
public ClientController(IClientLogic logic, ILogger<ClientController> logger) private readonly IMessageInfoLogic _mailLogic;
public ClientController(IClientLogic logic, IMessageInfoLogic mailLogic, ILogger<ClientController> logger)
{ {
_logger = logger; _logger = logger;
_logic = logic; _logic = logic;
_mailLogic = mailLogic;
} }
[HttpGet] [HttpGet]
public ClientViewModel? Login(string login, string password) public ClientViewModel? Login(string login, string password)
{ {
@ -34,6 +37,24 @@ namespace SushiBarRestApi.Controllers
throw; throw;
} }
} }
[HttpGet]
public List<MessageInfoViewModel>? GetMessages(int clientId)
{
try
{
return _mailLogic.ReadList(new MessageInfoSearchModel
{
ClientId = clientId
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Ошибка получения писем клиента");
throw;
}
}
[HttpPost] [HttpPost]
public void Register(ClientBindingModel model) public void Register(ClientBindingModel model)
{ {
@ -47,6 +68,7 @@ namespace SushiBarRestApi.Controllers
throw; throw;
} }
} }
[HttpPost] [HttpPost]
public void UpdateData(ClientBindingModel model) public void UpdateData(ClientBindingModel model)
{ {