ЧЕРТОВ ПРОБЕЛ ААААААААААРРРРРРРРРРР И ГМЕЙЛОВСКАЯ ПОЧТА!!!

This commit is contained in:
Елена Бакальская 2024-05-06 00:26:46 +04:00
parent 8c874279fe
commit 54a95ee87f
7 changed files with 47 additions and 28 deletions

View File

@ -1,11 +1,12 @@
<?xml version="1.0" encoding="utf-8" ?> <?xml version="1.0" encoding="utf-8" ?>
<configuration> <configuration>
<appSettings> <appSettings>
<add key="SmtpClientHost" value="smtp.mail.com" /> <add key="SmtpClientHost" value="smtp.beget.com" />
<add key="SmtpClientPort" value="587" /> <add key="SmtpClientPort" value="2525" />
<add key="PopHost" value="pop.gmail.com" /> <add key="PopHost" value="pop3.beget.com" />
<add key="PopPort" value="995" /> <add key="PopPort" value="995" />
<add key="MailLogin" value="qwertyelenatimakova@gmail.com" /> <add key="MailLogin" value="sushishop@ekallin.ru" />
<add key="MailPassword" value="616Lena!" /> <add key="MailPassword" value="8j#HWiCBiI*I" />
</appSettings> </appSettings>
</configuration> </configuration>

View File

@ -43,12 +43,12 @@ namespace SushiBar
MailLogin = System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ?? string.Empty, MailLogin = System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ?? string.Empty,
MailPassword = System.Configuration.ConfigurationManager.AppSettings["MailPassword"] ?? string.Empty, MailPassword = System.Configuration.ConfigurationManager.AppSettings["MailPassword"] ?? string.Empty,
SmtpClientHost = System.Configuration.ConfigurationManager.AppSettings["SmtpClientHost"] ?? string.Empty, SmtpClientHost = System.Configuration.ConfigurationManager.AppSettings["SmtpClientHost"] ?? string.Empty,
SmtpClientPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["SmtpClient Port"]), SmtpClientPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["SmtpClientPort"]),
PopHost = System.Configuration.ConfigurationManager.AppSettings["PopHost"] ?? string.Empty, PopHost = System.Configuration.ConfigurationManager.AppSettings["PopHost"] ?? string.Empty,
PopPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["PopPort"]) PopPort = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["PopPort"])
}); });
// ñîçäàåì òàéìåð // ñîçäàåì òàéìåð
var timer = new System.Threading.Timer(new TimerCallback(MailCheck!), null, 0, 100000); var timer = new System.Threading.Timer(new TimerCallback(MailCheck!), null, 0, 5000);
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -80,8 +80,8 @@ namespace SushiBar
services.AddTransient<IWorkProcess, WorkModeling>(); services.AddTransient<IWorkProcess, WorkModeling>();
services.AddTransient<IImplementerLogic, ImplementerLogic>(); services.AddTransient<IImplementerLogic, ImplementerLogic>();
services.AddTransient<IMessageInfoLogic, MessageInfoLogic>(); services.AddTransient<IMessageInfoLogic, MessageInfoLogic>();
services.AddTransient<AbstractMailWorker, MailKitWorker>();
services.AddSingleton<AbstractMailWorker, MailKitWorker>();
services.AddTransient<AbstractSaveToExcel, SaveToExcel>(); services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
services.AddTransient<AbstractSaveToWord, SaveToWord>(); services.AddTransient<AbstractSaveToWord, SaveToWord>();
services.AddTransient<AbstractSaveToPdf, SaveToPdf>(); services.AddTransient<AbstractSaveToPdf, SaveToPdf>();

View File

@ -23,6 +23,7 @@ namespace SushiBarBusinessLogic
if(messageStorage.Insert(model) == null) if(messageStorage.Insert(model) == null)
{ {
logger.LogWarning("Insert message operation failed"); logger.LogWarning("Insert message operation failed");
return false;
} }
return true; return true;
} }

View File

@ -18,7 +18,7 @@ namespace SushiBarBusinessLogic.BusinessLogic
private readonly AbstractMailWorker abstractMailWorker; private readonly AbstractMailWorker abstractMailWorker;
static readonly object blocking = new object(); static readonly object blocking = new object();
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage,
IClientStorage clientStorage, AbstractMailWorker abstractMailWorker) IClientStorage clientStorage, AbstractMailWorker abstractMailWorker)
{ {
_logger = logger; _logger = logger;
@ -60,18 +60,21 @@ namespace SushiBarBusinessLogic.BusinessLogic
public bool CreateOrder(OrderBindingModel model) public bool CreateOrder(OrderBindingModel model)
{ {
CheckModel(model); CheckModel(model);
if (model.Status != OrderStatus.Неизвестен) return false; if (model.Status != OrderStatus.Неизвестен)
{
return false;
}
model.Status = OrderStatus.Принят; model.Status = OrderStatus.Принят;
var order = _orderStorage.Insert(model); var order = _orderStorage.Insert(model);
if (order == null) if (order == null)
{ {
_logger.LogWarning("Insert operation failed"); _logger.LogWarning("Insert operation failed");
return false; return false;
} }
var client = clientStorage.GetElement(new() { Id = order!.ClientId }); var clientView = clientStorage.GetElement(new() { Id = order.ClientId });
SendMail(client, order);
if (clientView != null)
SendMail(clientView, order);
return true; return true;
} }
@ -97,7 +100,7 @@ namespace SushiBarBusinessLogic.BusinessLogic
{ {
CheckModel(model, false); CheckModel(model, false);
var order = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id }); var order = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id });
if (order == null) if (order == null)
{ {
_logger.LogWarning("Change status operation failed. Order not found"); _logger.LogWarning("Change status operation failed. Order not found");
@ -137,18 +140,18 @@ namespace SushiBarBusinessLogic.BusinessLogic
public void SendMail(ClientViewModel clientView, OrderViewModel orderView) public void SendMail(ClientViewModel clientView, OrderViewModel orderView)
{ {
if(clientView == null && orderView == null) if (clientView == null && orderView == null)
{ {
return; return;
} }
MailSendInfoBindingModel mailSendInfoBindingModel; MailSendInfoBindingModel mailSendInfoBindingModel;
if(orderView.Status == OrderStatus.Принят) if (orderView.Status == OrderStatus.Принят)
{ {
mailSendInfoBindingModel = new MailSendInfoBindingModel mailSendInfoBindingModel = new MailSendInfoBindingModel
{ {
MailAddress = clientView.Email, MailAddress = clientView!.Email,
Subject = $"Заказ под номером {orderView.Id}", Subject = $"Заказ под номером {orderView.Id}",
Text = $"Ваш заказ под номером {orderView.Id} от {orderView.DateCreate} ценой в {orderView.Sum} " + Text = $"Ваш заказ под номером {orderView.Id} от {orderView.DateCreate} ценой в {orderView.Sum} " +
$"был принят" $"был принят"
@ -158,7 +161,7 @@ namespace SushiBarBusinessLogic.BusinessLogic
{ {
mailSendInfoBindingModel = new MailSendInfoBindingModel mailSendInfoBindingModel = new MailSendInfoBindingModel
{ {
MailAddress = clientView.Email, MailAddress = clientView!.Email,
Subject = $"Заказ под номером {orderView.Id}", Subject = $"Заказ под номером {orderView.Id}",
Text = $"Ваш заказ под номером {orderView.Id} от {orderView.DateCreate} ценой в {orderView.Sum} " + Text = $"Ваш заказ под номером {orderView.Id} от {orderView.DateCreate} ценой в {orderView.Sum} " +
$"поменял статус на {orderView.Status}" $"поменял статус на {orderView.Status}"
@ -186,8 +189,8 @@ namespace SushiBarBusinessLogic.BusinessLogic
if (model.DateImplement.HasValue && model.DateImplement < model.DateCreate) if (model.DateImplement.HasValue && model.DateImplement < model.DateCreate)
throw new ArithmeticException("Заказ должен быть выдан позже, чем был создан"); throw new ArithmeticException("Заказ должен быть выдан позже, чем был создан");
_logger.LogInformation("Sushi. SushiId:{SushiId}. Count:{ Count}. Sum:{ Sum}. Id: { Id}", _logger.LogInformation("Sushi. SushiId:{SushiId}. Count:{ Count}. Sum:{ Sum}. Id: { Id}",
model.SushiId, model.Count, model.Sum, model.Id); model.SushiId, model.Count, model.Sum, model.Id);
} }
} }
} }

View File

@ -4,7 +4,7 @@
ViewData["Title"] = "Mails"; ViewData["Title"] = "Mails";
} }
<div class="text-center"> <div class="text-center">
<h1 class="display-4">Заказы</h1> <h1 class="display-4">Письма</h1>
</div> </div>
<div class="text-center"> <div class="text-center">
@{ @{

View File

@ -51,10 +51,21 @@ namespace SushiBarDatabaseImplement.Implements
{ {
using var context = new SushiBarDatabase(); using var context = new SushiBarDatabase();
var newMessage = MessageInfo.Create(model); var newMessage = MessageInfo.Create(model);
if(newMessage == null) return null; if (newMessage == null) return null;
context.Messages.Add(newMessage); context.Messages.Add(newMessage);
context.SaveChanges(); context.SaveChanges();
return newMessage.GetViewModel; return newMessage.GetViewModel;
/* using var context = new SushiBarDatabase();
model.ClientId = context.Clients.FirstOrDefault(x => x.Email.Equals(model.SenderName))?.Id;
var message = MessageInfo.Create(model);
if (message == null || context.Messages.Any(x => x.MessageId.Equals(model.MessageId)))
{
return null;
}
context.Messages.Add(message);
context.SaveChanges();
return message.GetViewModel;*/
} }
} }
} }

View File

@ -5,11 +5,14 @@
"Microsoft.AspNetCore": "Warning" "Microsoft.AspNetCore": "Warning"
} }
}, },
"AllowedHosts": "*", "AllowedHosts": "*",
"SmtpClientHost": "smtp.mail.com",
"SmtpClientPort": "587", "SmtpClientHost": "smtp.beget.com",
"PopHost": "pop.gmail.com", "SmtpClientPort": "2525",
"PopHost": "pop.beget.com",
"PopPort": "995", "PopPort": "995",
"MailLogin": "qwertyelenatimakova@gmail.com", "MailLogin": "sushishop@ekallin.ru",
"MailPassword": "616Lena!" "MailPassword": "8j#HWiCBiI*I!"
} }