Добавлено все, осталось допилить
This commit is contained in:
parent
b1abff7997
commit
6d2dccd4df
@ -34,12 +34,13 @@ namespace ConfectioneryBusinessLogic.BusinessLogics
|
|||||||
}
|
}
|
||||||
model.Status = OrderStatus.Принят;
|
model.Status = OrderStatus.Принят;
|
||||||
model.DateCreate = DateTime.Now;
|
model.DateCreate = DateTime.Now;
|
||||||
if (_orderStorage.Insert(model) == null)
|
var result = _orderStorage.Insert(model);
|
||||||
|
if (result == null)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Insert operation failed");
|
_logger.LogWarning("Insert operation failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
SendOrderStatusMail(model, $"Новый заказ создан. Номер заказа #{model.Id}", $"Заказ #{model.Id} от {model.DateCreate} на сумму {model.Sum:.02f} принят");
|
SendOrderStatusMail(result.ClientId, $"Новый заказ создан. Номер заказа #{result.Id}", $"Заказ #{result.Id} от {result.DateCreate} на сумму {result.Sum:0.00} принят");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -110,12 +111,13 @@ namespace ConfectioneryBusinessLogic.BusinessLogics
|
|||||||
model.PastryId = vmodel.PastryId;
|
model.PastryId = vmodel.PastryId;
|
||||||
model.Sum = vmodel.Sum;
|
model.Sum = vmodel.Sum;
|
||||||
model.Count= vmodel.Count;
|
model.Count= vmodel.Count;
|
||||||
if (_orderStorage.Update(model) == null)
|
var result = _orderStorage.Update(model);
|
||||||
|
if (result == null)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Update operation failed");
|
_logger.LogWarning("Update operation failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
SendOrderStatusMail(model, $"Изменен статус заказа #{model.Id}", $"Заказ #{model.Id} изменен статус на {model.Status}");
|
SendOrderStatusMail(result.ClientId, $"Изменен статус заказа #{result.Id}", $"Заказ #{model.Id} изменен статус на {result.Status}");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,9 +138,9 @@ namespace ConfectioneryBusinessLogic.BusinessLogics
|
|||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool SendOrderStatusMail(OrderBindingModel model, string subject, string text)
|
private bool SendOrderStatusMail(int clientId, string subject, string text)
|
||||||
{
|
{
|
||||||
var client = _clientLogic.ReadElement(new() { Id = model.ClientId });
|
var client = _clientLogic.ReadElement(new() { Id = clientId });
|
||||||
if (client == null)
|
if (client == null)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
<?xml version="1.0" encoding="utf-8" ?>
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
<configuration>
|
<configuration>
|
||||||
<appSettings>
|
<appSettings>
|
||||||
<add key="SmtpClientHost" value="smtp.gmail.com" />
|
<add key="SmtpClientHost" value="smtp.mail.ru" />
|
||||||
<add key="SmtpClientPort" value="587" />
|
<add key="SmtpClientPort" value="587" />
|
||||||
<add key="PopHost" value="pop.gmail.com" />
|
<add key="PopHost" value="pop.mail.ru" />
|
||||||
<add key="PopPort" value="995" />
|
<add key="PopPort" value="995" />
|
||||||
<add key="MailLogin" value="ordersender228@mail.ru" />
|
<add key="MailLogin" value="ordersender228@mail.ru" />
|
||||||
<add key="MailPassword" value="ZyN372xh8xiiTmj" />
|
<add key="MailPassword" value="v8czsQ8zztJc5wEHxKPN" />
|
||||||
</appSettings>
|
</appSettings>
|
||||||
</configuration>
|
</configuration>
|
@ -144,5 +144,15 @@ namespace ConfectioneryClientApp.Controllers
|
|||||||
var prod = APIClient.GetRequest<PastryViewModel>($"api/main/getpastry?pastryId={pastry}");
|
var prod = APIClient.GetRequest<PastryViewModel>($"api/main/getpastry?pastryId={pastry}");
|
||||||
return count * (prod?.Price ?? 1);
|
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}"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
54
ConfectioneryClientApp/Views/Home/Mails.cshtml
Normal file
54
ConfectioneryClientApp/Views/Home/Mails.cshtml
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
@using ConfectioneryContracts.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>
|
@ -28,6 +28,9 @@
|
|||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Личные данные</a>
|
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Личные данные</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Mails">Письма</a>
|
||||||
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Enter">Вход</a>
|
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Enter">Вход</a>
|
||||||
</li>
|
</li>
|
||||||
|
@ -40,7 +40,7 @@ namespace ConfectioneryDatabaseImplement
|
|||||||
{
|
{
|
||||||
using var context = new ConfectioneryDatabase();
|
using var context = new ConfectioneryDatabase();
|
||||||
var newMessage = MessageInfo.Create(model);
|
var newMessage = MessageInfo.Create(model);
|
||||||
if (newMessage == null)
|
if (newMessage == null || context.Messages.Any(x => x.MessageId.Equals(model.MessageId)))
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -13,11 +13,13 @@ namespace ConfectioneryRestApi.Controllers
|
|||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
private readonly IClientLogic _logic;
|
private readonly IClientLogic _logic;
|
||||||
|
private readonly IMessageInfoLogic _mailLogic;
|
||||||
|
|
||||||
public ClientController(IClientLogic logic, ILogger<ClientController> logger)
|
public ClientController(IClientLogic logic, IMessageInfoLogic mailLogic, ILogger<ClientController> logger)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_logic = logic;
|
_logic = logic;
|
||||||
|
_mailLogic = mailLogic;
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
@ -66,5 +68,22 @@ namespace ConfectioneryRestApi.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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
using ConfectioneryBusinessLogic;
|
using ConfectioneryBusinessLogic;
|
||||||
using ConfectioneryBusinessLogic.BusinessLogics;
|
using ConfectioneryBusinessLogic.BusinessLogics;
|
||||||
|
using ConfectioneryBusinessLogic.MailWorker;
|
||||||
|
using ConfectioneryContracts.BindingModels;
|
||||||
using ConfectioneryContracts.BusinessLogicsContracts;
|
using ConfectioneryContracts.BusinessLogicsContracts;
|
||||||
using ConfectioneryContracts.StoragesContract;
|
using ConfectioneryContracts.StoragesContract;
|
||||||
|
using ConfectioneryDatabaseImplement;
|
||||||
using ConfectioneryDatabaseImplement.Implements;
|
using ConfectioneryDatabaseImplement.Implements;
|
||||||
using Microsoft.OpenApi.Models;
|
using Microsoft.OpenApi.Models;
|
||||||
|
|
||||||
@ -14,7 +17,10 @@ builder.Services.AddTransient<IClientStorage, ClientStorage>();
|
|||||||
builder.Services.AddTransient<IOrderStorage, OrderStorage>();
|
builder.Services.AddTransient<IOrderStorage, OrderStorage>();
|
||||||
builder.Services.AddTransient<IPastryStorage, PastryStorage>();
|
builder.Services.AddTransient<IPastryStorage, PastryStorage>();
|
||||||
builder.Services.AddTransient<IOrderLogic, OrderLogic>();
|
builder.Services.AddTransient<IOrderLogic, OrderLogic>();
|
||||||
|
builder.Services.AddTransient<IMessageInfoLogic, MessageInfoLogic>();
|
||||||
|
builder.Services.AddTransient<IMessageInfoStorage, MessageInfoStorage>();
|
||||||
|
|
||||||
|
builder.Services.AddSingleton<AbstractMailWorker, MailKitWorker>();
|
||||||
builder.Services.AddTransient<IClientLogic, ClientLogic>();
|
builder.Services.AddTransient<IClientLogic, ClientLogic>();
|
||||||
builder.Services.AddTransient<IPastryLogic, PastryLogic>();
|
builder.Services.AddTransient<IPastryLogic, PastryLogic>();
|
||||||
builder.Services.AddControllers();
|
builder.Services.AddControllers();
|
||||||
@ -31,6 +37,19 @@ builder.Services.AddSwaggerGen(c =>
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
|
var mailSender = app.Services.GetService<AbstractMailWorker>();
|
||||||
|
|
||||||
|
mailSender?.MailConfig(new MailConfigBindingModel
|
||||||
|
{
|
||||||
|
MailLogin = builder.Configuration?.GetSection("MailLogin")?.Value?.ToString() ?? string.Empty,
|
||||||
|
MailPassword = builder.Configuration?.GetSection("MailPassword")?.Value?.ToString() ?? string.Empty,
|
||||||
|
SmtpClientHost = builder.Configuration?.GetSection("SmtpClientHost")?.Value?.ToString() ?? string.Empty,
|
||||||
|
SmtpClientPort = Convert.ToInt32(builder.Configuration?.GetSection("SmtpClientPort")?.Value?.ToString()),
|
||||||
|
PopHost = builder.Configuration?.GetSection("PopHost")?.Value?.ToString() ?? string.Empty,
|
||||||
|
PopPort = Convert.ToInt32(builder.Configuration?.GetSection("PopPort")?.Value?.ToString())
|
||||||
|
});
|
||||||
|
|
||||||
// Configure the HTTP request pipeline.
|
// Configure the HTTP request pipeline.
|
||||||
if (app.Environment.IsDevelopment())
|
if (app.Environment.IsDevelopment())
|
||||||
{
|
{
|
||||||
|
@ -5,5 +5,12 @@
|
|||||||
"Microsoft.AspNetCore": "Warning"
|
"Microsoft.AspNetCore": "Warning"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"AllowedHosts": "*"
|
"AllowedHosts": "*",
|
||||||
|
|
||||||
|
"SmtpClientHost": "smtp.mail.ru",
|
||||||
|
"SmtpClientPort": "587",
|
||||||
|
"PopHost": "pop.mail.ru",
|
||||||
|
"PopPort": "995",
|
||||||
|
"MailLogin": "ordersender228@mail.ru",
|
||||||
|
"MailPassword": "v8czsQ8zztJc5wEHxKPN"
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user