Bazunov A.I. Lab Work #7 #15

Closed
viltskaa wants to merge 8 commits from LabWork_7 into LabWork_6
7 changed files with 118 additions and 8 deletions
Showing only changes of commit 63ba7d1a44 - Show all commits

View File

@ -95,6 +95,7 @@ namespace SushiBar
services.AddTransient<FormImplementers>();
services.AddTransient<FormImplementer>();
}
private static void MailCheck(object obj) => ServiceProvider?.GetService<AbstractMailWorker>()?.MailCheck();
}
}

View File

@ -106,8 +106,7 @@ namespace SushiBarBusinessLogic.BusinessLogics
}
model.Status = status;
model.DateCreate = order.DateCreate;
if (model.DateImplement == null)
model.DateImplement = order.DateImplement;
model.DateImplement ??= order.DateImplement;
if (order.ImplementerId.HasValue)
model.ImplementerId = order.ImplementerId;
if (model.Status == OrderStatus.Issued)
@ -118,11 +117,16 @@ namespace SushiBarBusinessLogic.BusinessLogics
model.SushiId = order.SushiId;
model.Sum = order.Sum;
model.Count = order.Count;
if (_orderStorage.Update(model) == null)
var result = _orderStorage.Update(model);
if (result == null)
{
_logger.LogWarning("Update operation failed");
return false;
}
SendOrderMessage(result.ClientId,
$"Sushi Bar, Order №{result.Id}",
$"Order №{model.Id} changed status on {result.Status}");
return true;
}

View File

@ -149,5 +149,15 @@ namespace SushiBarClientApi.Controllers
var prod = APIClient.GetRequest<SushiViewModel>($"api/Main/GetProduct?sushiId={sushi}");
return count * (prod?.Price ?? 1);
}
[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,50 @@
@model List<SushiBarContracts.ViewModels.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

@ -23,13 +23,16 @@
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="Index">Orders</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="Privacy">My info</a>
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="Privacy">PM</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="Enter">Sign in</a>
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="Mails">Mails</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="Register">Sign up</a>
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="Enter">Sign In</a>
</li>
<li class="nav-item">
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="Register">Sing Up</a>
</li>
</ul>
</div>

View File

@ -12,9 +12,14 @@ public class ClientController : Controller
{
private readonly ILogger _logger;
private readonly IClientLogic _logic;
public ClientController(IClientLogic logic, ILogger<ClientController> logger)
private readonly IMessageInfoLogic _mailLogic;
public ClientController(IClientLogic logic,
ILogger<ClientController> logger,
IMessageInfoLogic mailLogic)
{
_logger = logger;
_mailLogic = mailLogic;
_logic = logic;
}
@ -63,4 +68,20 @@ public class ClientController : Controller
}
}
[HttpGet]
public List<MessageInfoViewModel>? GetMessages(int clientId)
{
try
{
return _mailLogic.ReadList(new MessageInfoSearchModel
{
ClientId = clientId
});
}
catch (Exception ex)
{
_logger.LogError(ex, "Error");
throw;
}
}
}

View File

@ -3,6 +3,8 @@ using SushiBarContracts.BusinessLogicsContracts;
using SushiBarContracts.StoragesContracts;
using SushiBarDatabaseImplement.Implements;
using Microsoft.OpenApi.Models;
using SushiBarBusinessLogic.MailWorker;
using SushiBarContracts.BindingModels;
var builder = WebApplication.CreateBuilder(args);
@ -14,10 +16,14 @@ builder.Logging.AddLog4Net("log4net.config");
builder.Services.AddTransient<IClientStorage, ClientStorage>();
builder.Services.AddTransient<IOrderStorage, OrderStorage>();
builder.Services.AddTransient<ISushiStorage, SushiStorage>();
builder.Services.AddTransient<IImplementerStorage, ImplementerStorage>();
builder.Services.AddTransient<IMessageInfoStorage, MessageStorage>();
builder.Services.AddTransient<IOrderLogic, OrderLogic>();
builder.Services.AddTransient<IClientLogic, ClientLogic>();
builder.Services.AddTransient<ISushiLogic, SushiLogic>();
builder.Services.AddTransient<IImplementerLogic, ImplementerLogic>();
builder.Services.AddTransient<IMessageInfoLogic, MessageInfoLogic>();
builder.Services.AddTransient<AbstractMailWorker, MailKitWorker>();
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
@ -26,6 +32,21 @@ builder.Services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new OpenApiInfo { Title
var app = builder.Build();
var mailSender = app.Services.GetService<AbstractMailWorker>();
mailSender?.MailConfig(new MailConfigBindingModel
{
MailLogin = builder.Configuration?.GetSection("MailLogin")?.Value
?? string.Empty,
MailPassword = builder.Configuration?.GetSection("MailPassword")?.Value ??
string.Empty,
SmtpClientHost = builder.Configuration?.GetSection("SmtpClientHost")?.Value ??
string.Empty,
SmtpClientPort = Convert.ToInt32(builder.Configuration?.GetSection("SmtpClientPort")?.Value),
PopHost = builder.Configuration?.GetSection("PopHost")?.Value ??
string.Empty,
PopPort = Convert.ToInt32(builder.Configuration?.GetSection("PopPort")?.Value)
});
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())