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

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" ?>
<configuration>
<appSettings>
<add key="SmtpClientHost" value="smtp.mail.com" />
<add key="SmtpClientPort" value="587" />
<add key="PopHost" value="pop.gmail.com" />
<add key="SmtpClientHost" value="smtp.beget.com" />
<add key="SmtpClientPort" value="2525" />
<add key="PopHost" value="pop3.beget.com" />
<add key="PopPort" value="995" />
<add key="MailLogin" value="qwertyelenatimakova@gmail.com" />
<add key="MailPassword" value="616Lena!" />
<add key="MailLogin" value="sushishop@ekallin.ru" />
<add key="MailPassword" value="8j#HWiCBiI*I" />
</appSettings>
</configuration>

View File

@ -43,12 +43,12 @@ namespace SushiBar
MailLogin = System.Configuration.ConfigurationManager.AppSettings["MailLogin"] ?? string.Empty,
MailPassword = System.Configuration.ConfigurationManager.AppSettings["MailPassword"] ?? 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,
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)
{
@ -80,8 +80,8 @@ namespace SushiBar
services.AddTransient<IWorkProcess, WorkModeling>();
services.AddTransient<IImplementerLogic, ImplementerLogic>();
services.AddTransient<IMessageInfoLogic, MessageInfoLogic>();
services.AddTransient<AbstractMailWorker, MailKitWorker>();
services.AddSingleton<AbstractMailWorker, MailKitWorker>();
services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
services.AddTransient<AbstractSaveToWord, SaveToWord>();
services.AddTransient<AbstractSaveToPdf, SaveToPdf>();

View File

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

View File

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

View File

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

View File

@ -51,10 +51,21 @@ namespace SushiBarDatabaseImplement.Implements
{
using var context = new SushiBarDatabase();
var newMessage = MessageInfo.Create(model);
if(newMessage == null) return null;
if (newMessage == null) return null;
context.Messages.Add(newMessage);
context.SaveChanges();
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"
}
},
"AllowedHosts": "*",
"SmtpClientHost": "smtp.mail.com",
"SmtpClientPort": "587",
"PopHost": "pop.gmail.com",
"SmtpClientHost": "smtp.beget.com",
"SmtpClientPort": "2525",
"PopHost": "pop.beget.com",
"PopPort": "995",
"MailLogin": "qwertyelenatimakova@gmail.com",
"MailPassword": "616Lena!"
"MailLogin": "sushishop@ekallin.ru",
"MailPassword": "8j#HWiCBiI*I!"
}