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

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("Номер")]
public int Id { get; set; }
public int PastryId { get; set; }
[DisplayName("Выпечка")]
public string PastryName { get; set; } = string.Empty;
public int ClientId { get; set; }
[DisplayName("ФИО клиента")]
public string ClientFIO { get; set; } = string.Empty;
public string ClientEmail { get; set; } = string.Empty;
public int? ImplementerId { get; set; }
[DisplayName("ФИО исполнителя")]
public string ImplementerFIO { get; set; } = string.Empty;
[DisplayName("Количество")]
public int Count { get; set; }
[DisplayName("Сумма")]
public double Sum { get; set; }
[DisplayName("Статус")]
public OrderStatus Status { get; set; } = OrderStatus.Неизвестен;
[DisplayName("Дата создания")]
public DateTime DateCreate { get; set; } = DateTime.Now;
[DisplayName("Дата выполнения")]
public DateTime? DateImplement { get; set; }
}

View File

@ -15,39 +15,81 @@ namespace ConfectioneryBusinessLogic.BusinessLogics
public class MessageInfoLogic : IMessageInfoLogic
{
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;
_messageStorage = messageStorage;
_messageInfoStorage = messageInfoStorage;
_clientStorage = clientStorage;
}
public List<MessageInfoViewModel>? ReadList(MessageInfoSearchModel? model)
{
_logger.LogInformation("ReadList. MessageId: {MessageId}. ClientId: {ClientId}", model?.MessageId, model?.ClientId);
var list = model == null ? _messageStorage.GetFullList() : _messageStorage.GetFilteredList(model);
var list = model == null ? _messageInfoStorage.GetFullList() : _messageInfoStorage.GetFilteredList(model);
if (list == null)
{
_logger.LogWarning("ReadList return null list");
return null;
}
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
return list;
}
public bool Create(MessageInfoBindingModel model)
{
if (model == null)
{
return false;
}
if (_messageStorage.Insert(model) == null)
CheckModel(model);
if (_messageInfoStorage.Insert(model) == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
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 IClientStorage _clientStorage;
private readonly AbstractMailWorker _mailLogic;
private readonly AbstractMailWorker _mailWorker;
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;
_orderStorage = orderStorage;
_clientStorage = clientStorage;
_mailLogic = mailLogic;
_mailWorker = mailWorker;
}
public bool CreateOrder(OrderBindingModel model)
@ -43,15 +40,18 @@ namespace ConfectioneryBusinessLogic.BusinessLogics
return false;
}
model.Status = OrderStatus.Принят;
var order = _orderStorage.Insert(model);
if (order == null)
var element = _orderStorage.Insert(model);
if (element == null)
{
_logger.LogWarning("Insert operation failed");
return false;
}
SendEmail(order);
Task.Run(() => _mailWorker.MailSendAsync(new MailSendInfoBindingModel
{
MailAddress = element.ClientEmail,
Subject = $"Новый заказ создан. Номер заказа - {element.Id}",
Text = $"Заказ №{element.Id} от {element.DateCreate} на сумму {element.Sum} принят."
}));
return true;
}
@ -67,6 +67,7 @@ namespace ConfectioneryBusinessLogic.BusinessLogics
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
return list;
}
public OrderViewModel? ReadElement(OrderSearchModel model)
{
if (model == null)
@ -160,50 +161,19 @@ namespace ConfectioneryBusinessLogic.BusinessLogics
{
model.DateImplement = order.DateImplement;
}
order = _orderStorage.Update(model);
if (order == null)
if (_orderStorage.Update(model) == null)
{
_logger.LogWarning("Change status operation failed");
return false;
}
SendEmail(order);
string DateInfo = model.DateImplement.HasValue ? $"Дата выполнения {model.DateImplement}" : "";
Task.Run(() => _mailWorker.MailSendAsync(new MailSendInfoBindingModel
{
MailAddress = order.ClientEmail,
Subject = $"Заказ №{order.Id}",
Text = $"Заказ №{order.Id} изменен статус на {model.Status}. {DateInfo}"
}));
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,
PastryName = Pastry.PastryName,
ClientFIO = Client.ClientFIO,
ClientEmail = Client.Email ?? string.Empty,
ImplementerFIO = Implementer?.ImplementerFIO ?? string.Empty
};
}

View File

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