не починилось :(

This commit is contained in:
Полина Чубыкина 2024-05-18 16:05:37 +04:00
parent b6f0aac54b
commit 4b880a78c7
5 changed files with 87 additions and 62 deletions

View File

@ -13,25 +13,36 @@ namespace ConfectioneryContracts.ViewModels
{ {
[DisplayName("Номер")] [DisplayName("Номер")]
public int Id { get; set; } public int Id { get; set; }
public int PastryId { get; set; } public int PastryId { get; set; }
[DisplayName("Выпечка")] [DisplayName("Выпечка")]
public string PastryName { get; set; } = string.Empty; public string PastryName { get; set; } = string.Empty;
public int ClientId { get; set; } public int ClientId { get; set; }
[DisplayName("ФИО клиента")] [DisplayName("ФИО клиента")]
public string ClientFIO { get; set; } = string.Empty; public string ClientFIO { get; set; } = string.Empty;
public string ClientEmail { get; set; } = string.Empty;
public int? ImplementerId { get; set; } public int? ImplementerId { get; set; }
[DisplayName("ФИО исполнителя")] [DisplayName("ФИО исполнителя")]
public string ImplementerFIO { get; set; } = string.Empty; public string ImplementerFIO { get; set; } = string.Empty;
[DisplayName("Количество")] [DisplayName("Количество")]
public int Count { get; set; } public int Count { get; set; }
[DisplayName("Сумма")] [DisplayName("Сумма")]
public double Sum { get; set; } public double Sum { get; set; }
[DisplayName("Статус")] [DisplayName("Статус")]
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен; public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
[DisplayName("Дата создания")] [DisplayName("Дата создания")]
public DateTime DateCreate { get; set; } = DateTime.Now; public DateTime DateCreate { get; set; } = DateTime.Now;
[DisplayName("Дата выполнения")] [DisplayName("Дата выполнения")]
public DateTime? DateImplement { get; set; } public DateTime? DateImplement { get; set; }
} }

View File

@ -15,39 +15,81 @@ namespace ConfectioneryBusinessLogic.BusinessLogics
public class MessageInfoLogic : IMessageInfoLogic public class MessageInfoLogic : IMessageInfoLogic
{ {
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IMessageInfoStorage _messageStorage;
public MessageInfoLogic(ILogger<MessageInfoLogic> logger, IMessageInfoStorage messageStorage) private readonly IMessageInfoStorage _messageInfoStorage;
private readonly IClientStorage _clientStorage;
public MessageInfoLogic(ILogger<MessageInfoLogic> logger, IMessageInfoStorage messageInfoStorage, IClientStorage clientStorage)
{ {
_logger = logger; _logger = logger;
_messageStorage = messageStorage; _messageInfoStorage = messageInfoStorage;
_clientStorage = clientStorage;
} }
public List<MessageInfoViewModel>? ReadList(MessageInfoSearchModel? model) public List<MessageInfoViewModel>? ReadList(MessageInfoSearchModel? model)
{ {
_logger.LogInformation("ReadList. MessageId: {MessageId}. ClientId: {ClientId}", model?.MessageId, model?.ClientId); _logger.LogInformation("ReadList. MessageId: {MessageId}. ClientId: {ClientId}", model?.MessageId, model?.ClientId);
var list = model == null ? _messageInfoStorage.GetFullList() : _messageInfoStorage.GetFilteredList(model);
var list = model == null ? _messageStorage.GetFullList() : _messageStorage.GetFilteredList(model);
if (list == null) if (list == null)
{ {
_logger.LogWarning("ReadList return null list"); _logger.LogWarning("ReadList return null list");
return null; return null;
} }
_logger.LogInformation("ReadList. Count: {Count}", list.Count); _logger.LogInformation("ReadList. Count: {Count}", list.Count);
return list; return list;
} }
public bool Create(MessageInfoBindingModel model) public bool Create(MessageInfoBindingModel model)
{ {
if (model == null) CheckModel(model);
{ if (_messageInfoStorage.Insert(model) == null)
return false;
}
if (_messageStorage.Insert(model) == null)
{ {
_logger.LogWarning("Insert operation failed"); _logger.LogWarning("Insert operation failed");
return false; return false;
} }
return true; return true;
} }
private void CheckModel(MessageInfoBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.MessageId))
{
throw new ArgumentNullException("Не указан id сообщения", nameof(model.MessageId));
}
if (string.IsNullOrEmpty(model.SenderName))
{
throw new ArgumentNullException("Не указана почта отправителя", nameof(model.SenderName));
}
if (string.IsNullOrEmpty(model.Subject))
{
throw new ArgumentNullException("Не указан заголовок", nameof(model.Subject));
}
if (string.IsNullOrEmpty(model.Body))
{
throw new ArgumentNullException("Не указан текст сообщения", nameof(model.Subject));
}
_logger.LogInformation("MessageInfo. MessageId: {MessageId}. SenderName: {SenderName}. DateDelivery: {DateDelivery} Subject: {Subject}. Body: {Body}", model.MessageId, model.SenderName, model.DateDelivery, model.Subject, model.Body);
var element = _clientStorage.GetElement(new ClientSearchModel
{
Email = model.SenderName
});
if (element == null)
{
_logger.LogWarning("Не удалось найти клиента, отправившего письмо с адреса Email: {Email}", model.SenderName);
}
else
{
model.ClientId = element.Id;
}
}
} }
} }

View File

@ -20,18 +20,15 @@ namespace ConfectioneryBusinessLogic.BusinessLogics
private readonly IOrderStorage _orderStorage; private readonly IOrderStorage _orderStorage;
private readonly IClientStorage _clientStorage; private readonly AbstractMailWorker _mailWorker;
private readonly AbstractMailWorker _mailLogic;
static readonly object locker = new(); static readonly object locker = new();
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, IClientStorage clientStorage, AbstractMailWorker mailLogic) public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, AbstractMailWorker mailWorker)
{ {
_logger = logger; _logger = logger;
_orderStorage = orderStorage; _orderStorage = orderStorage;
_clientStorage = clientStorage; _mailWorker = mailWorker;
_mailLogic = mailLogic;
} }
public bool CreateOrder(OrderBindingModel model) public bool CreateOrder(OrderBindingModel model)
@ -43,15 +40,18 @@ namespace ConfectioneryBusinessLogic.BusinessLogics
return false; return false;
} }
model.Status = OrderStatus.Принят; model.Status = OrderStatus.Принят;
var element = _orderStorage.Insert(model);
var order = _orderStorage.Insert(model); if (element == null)
if (order == null)
{ {
_logger.LogWarning("Insert operation failed"); _logger.LogWarning("Insert operation failed");
return false; return false;
} }
Task.Run(() => _mailWorker.MailSendAsync(new MailSendInfoBindingModel
SendEmail(order); {
MailAddress = element.ClientEmail,
Subject = $"Новый заказ создан. Номер заказа - {element.Id}",
Text = $"Заказ №{element.Id} от {element.DateCreate} на сумму {element.Sum} принят."
}));
return true; return true;
} }
@ -67,6 +67,7 @@ namespace ConfectioneryBusinessLogic.BusinessLogics
_logger.LogInformation("ReadList. Count: {Count}", list.Count); _logger.LogInformation("ReadList. Count: {Count}", list.Count);
return list; return list;
} }
public OrderViewModel? ReadElement(OrderSearchModel model) public OrderViewModel? ReadElement(OrderSearchModel model)
{ {
if (model == null) if (model == null)
@ -160,50 +161,19 @@ namespace ConfectioneryBusinessLogic.BusinessLogics
{ {
model.DateImplement = order.DateImplement; model.DateImplement = order.DateImplement;
} }
if (_orderStorage.Update(model) == null)
order = _orderStorage.Update(model);
if (order == null)
{ {
_logger.LogWarning("Change status operation failed"); _logger.LogWarning("Change status operation failed");
return false; return false;
} }
string DateInfo = model.DateImplement.HasValue ? $"Дата выполнения {model.DateImplement}" : "";
SendEmail(order); Task.Run(() => _mailWorker.MailSendAsync(new MailSendInfoBindingModel
{
MailAddress = order.ClientEmail,
Subject = $"Заказ №{order.Id}",
Text = $"Заказ №{order.Id} изменен статус на {model.Status}. {DateInfo}"
}));
return true; return true;
} }
public void SendEmail(OrderViewModel order)
{
if (order == null)
{
return;
}
var client = _clientStorage.GetElement(new ClientSearchModel { Id = order.ClientId });
if (client == null)
{
return;
}
MailSendInfoBindingModel mailModel;
if (order.Status == OrderStatus.Выполняется)
{
mailModel = new MailSendInfoBindingModel
{
MailAddress = client.Email,
Subject = $"Order №{order.Id}",
Text = $"Your order №{order.Id} by {order.DateCreate} on {order.Sum} was accepted!"
};
}
else
{
mailModel = new MailSendInfoBindingModel
{
MailAddress = client.Email,
Subject = $"Order №{order.Id}",
Text = $"Order №{order.Id} status was changed to {order.Status}"
};
}
_mailLogic.MailSendAsync(mailModel);
}
} }
} }

View File

@ -70,6 +70,7 @@ namespace ConfectioneryDatabaseImplement.Models
DateImplement = DateImplement, DateImplement = DateImplement,
PastryName = Pastry.PastryName, PastryName = Pastry.PastryName,
ClientFIO = Client.ClientFIO, ClientFIO = Client.ClientFIO,
ClientEmail = Client.Email ?? string.Empty,
ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty
}; };
} }

View File

@ -44,6 +44,7 @@ namespace ConfectioneryView
dataGridView.Columns["PastryId"].Visible = false; dataGridView.Columns["PastryId"].Visible = false;
dataGridView.Columns["PastryName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridView.Columns["PastryName"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["ClientId"].Visible = false; dataGridView.Columns["ClientId"].Visible = false;
dataGridView.Columns["ClientEmail"].Visible = false;
dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridView.Columns["ClientFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView.Columns["ImplementerId"].Visible = false; dataGridView.Columns["ImplementerId"].Visible = false;
dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill; dataGridView.Columns["ImplementerFIO"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;