добавила в ордер логику метод отправки сообщения на почту :)
This commit is contained in:
parent
7fd7890a53
commit
e80dc53d6f
@ -28,8 +28,8 @@ namespace SushiBarBusinessLogic.MailWorker
|
||||
_smtpClientPort = config.SmtpClientPort;
|
||||
_popHost = config.PopHost;
|
||||
_popPort = config.PopPort;
|
||||
_logger.LogDebug("Config: {login}, {password}, {clientHost}, {clientPOrt}, {popHost}, {popPort}",
|
||||
_mailLogin, _mailPassword, _smtpClientHost, _smtpClientPort, _popHost, _popPort);
|
||||
_logger.LogDebug($"Config: {_mailLogin}, {_mailPassword}, " +
|
||||
$"{_smtpClientHost}, {_smtpClientPort}, {_popHost}, {_popPort}");
|
||||
}
|
||||
public async void MailSendAsync(MailSendInfoBindingModel info)
|
||||
{
|
||||
|
@ -71,6 +71,5 @@ namespace SushiBarBusinessLogic.MailWorker
|
||||
});
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -6,6 +6,7 @@ using SushiBarContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using SushiBarDataModels.Enums;
|
||||
using System.Xml.Linq;
|
||||
using SushiBarBusinessLogic.MailWorker;
|
||||
|
||||
namespace SushiBarBusinessLogic.BusinessLogic
|
||||
{
|
||||
@ -13,12 +14,17 @@ namespace SushiBarBusinessLogic.BusinessLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IOrderStorage _orderStorage;
|
||||
private readonly IClientStorage clientStorage;
|
||||
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;
|
||||
_orderStorage = orderStorage;
|
||||
this.clientStorage = clientStorage;
|
||||
this.abstractMailWorker = abstractMailWorker;
|
||||
}
|
||||
|
||||
public OrderViewModel? ReadElement(OrderSearchModel model)
|
||||
@ -86,8 +92,7 @@ namespace SushiBarBusinessLogic.BusinessLogic
|
||||
{
|
||||
CheckModel(model, false);
|
||||
var order = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id });
|
||||
if (order.ImplementerId.HasValue)
|
||||
model.ImplementerId = order.ImplementerId;
|
||||
|
||||
if (order == null)
|
||||
{
|
||||
_logger.LogWarning("Change status operation failed. Order not found");
|
||||
@ -100,6 +105,9 @@ namespace SushiBarBusinessLogic.BusinessLogic
|
||||
return false;
|
||||
}
|
||||
|
||||
if (order.ImplementerId.HasValue)
|
||||
model.ImplementerId = order.ImplementerId;
|
||||
|
||||
model.Status = orderStatus;
|
||||
|
||||
if (model.Status == OrderStatus.Готов)
|
||||
@ -115,9 +123,44 @@ namespace SushiBarBusinessLogic.BusinessLogic
|
||||
_logger.LogWarning("Change status operation failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
var clientView = clientStorage.GetElement(new ClientSearchModel { Id = order.ClientId });
|
||||
if (clientView != null)
|
||||
SendMail(clientView, order);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void SendMail(ClientViewModel clientView, OrderViewModel orderView)
|
||||
{
|
||||
if(clientView == null || orderView == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
MailSendInfoBindingModel mailSendInfoBindingModel;
|
||||
|
||||
if(orderView.Status == OrderStatus.Принят)
|
||||
{
|
||||
mailSendInfoBindingModel = new MailSendInfoBindingModel
|
||||
{
|
||||
MailAddress = clientView.Email,
|
||||
Subject = $"Заказ под номером {orderView.Id}",
|
||||
Text = $"Ваш заказ под номером {orderView.Id} от {orderView.DateCreate} ценой в {orderView.Sum} " +
|
||||
$"был принят"
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
mailSendInfoBindingModel = new MailSendInfoBindingModel
|
||||
{
|
||||
MailAddress = clientView.Email,
|
||||
Subject = $"Заказ под номером {orderView.Id}",
|
||||
Text = $"Ваш заказ под номером {orderView.Id} от {orderView.DateCreate} ценой в {orderView.Sum} " +
|
||||
$"поменял статус на {orderView.Status}"
|
||||
};
|
||||
}
|
||||
abstractMailWorker.MailSendAsync(mailSendInfoBindingModel);
|
||||
}
|
||||
|
||||
private void CheckModel(OrderBindingModel model, bool withParams = true)
|
||||
{
|
||||
if (model == null)
|
||||
|
Loading…
Reference in New Issue
Block a user