PIbd-23. Radaev A.V. Lab work 07 base #11
@ -4,124 +4,122 @@ using GiftShopContracts.SearchModels;
|
|||||||
using GiftShopContracts.StoragesContracts;
|
using GiftShopContracts.StoragesContracts;
|
||||||
using GiftShopContracts.ViewModels;
|
using GiftShopContracts.ViewModels;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
|
|
||||||
namespace GiftShopBusinessLogic.BusinessLogics
|
namespace GiftShopBusinessLogic.BusinessLogics
|
||||||
{
|
{
|
||||||
public class ClientLogic : IClientLogic
|
public class ClientLogic : IClientLogic
|
||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
|
private readonly IClientStorage _clientStorage;
|
||||||
|
public ClientLogic(ILogger<ClientLogic> logger, IClientStorage clientStorage)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_clientStorage = clientStorage;
|
||||||
|
}
|
||||||
|
public bool Create(ClientBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (_clientStorage.Insert(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Insert operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private readonly IClientStorage _clientStorage;
|
public bool Delete(ClientBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model, false);
|
||||||
|
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||||
|
if (_clientStorage.Delete(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Delete operation failed");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
public ClientLogic(ILogger<ClientLogic> logger, IClientStorage clientStorage)
|
public ClientViewModel? ReadElement(ClientSearchModel model)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
if (model == null)
|
||||||
_clientStorage = clientStorage;
|
{
|
||||||
}
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadElement. ClientFIO:{ClientFIO}. Email: {Email}. Id:{ Id}", model.ClientFIO, model.Email, model.Id);
|
||||||
|
var element = _clientStorage.GetElement(model);
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("ReadElement element not found");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
|
||||||
public bool Create(ClientBindingModel model)
|
public List<ClientViewModel>? ReadList(ClientSearchModel? model)
|
||||||
{
|
{
|
||||||
CheckModel(model);
|
_logger.LogInformation("ReadList. ClientFIO: {ClientName}. Email: {Email}. Id: {Id}.", model?.ClientFIO, model?.Email, model?.Id);
|
||||||
if (_clientStorage.Insert(model) == null)
|
var list = model == null ? _clientStorage.GetFullList() : _clientStorage.GetFilteredList(model);
|
||||||
{
|
if (list == null)
|
||||||
_logger.LogWarning("Insert operation failed");
|
{
|
||||||
return false;
|
_logger.LogWarning("ReadList return null list");
|
||||||
}
|
return null;
|
||||||
return true;
|
}
|
||||||
}
|
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
public bool Delete(ClientBindingModel model)
|
public bool Update(ClientBindingModel model)
|
||||||
{
|
{
|
||||||
CheckModel(model, false);
|
CheckModel(model);
|
||||||
_logger.LogInformation("Delete. Id: {Id}", model.Id);
|
if (_clientStorage.Update(model) == null)
|
||||||
if (_clientStorage.Delete(model) == null)
|
{
|
||||||
{
|
_logger.LogWarning("Update operation failed");
|
||||||
_logger.LogWarning("Delete operation failed");
|
return false;
|
||||||
return false;
|
}
|
||||||
}
|
return true;
|
||||||
return true;
|
}
|
||||||
}
|
private void CheckModel(ClientBindingModel model, bool withParams = true)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
if (!withParams)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(model.ClientFIO))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Нет ФИО клиента", nameof(model.ClientFIO));
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(model.Email))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("У клиента отсутствует почта", nameof(model.Email));
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(model.Password))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("У клиента отсутствует пароль", nameof(model.Password));
|
||||||
|
}
|
||||||
|
if (!Regex.IsMatch(model.Email, @"^[^@\s]+@[^@\s]+\.[^@\s]+$", RegexOptions.IgnoreCase))
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Неправильно введенный email", nameof(model.Email));
|
||||||
|
}
|
||||||
|
if (!Regex.IsMatch(model.Password, @"^((\w+\d+\W+)|(\w+\W+\d+)|(\d+\w+\W+)|(\d+\W+\w+)|(\W+\w+\d+)|(\W+\d+\w+))[\w\d\W]*$") || model.Password.Length < 10 || model.Password.Length > 50)
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Неправильно введенный пароль", nameof(model.Password));
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Client. ClientID:{Id}. ClientFIO: {ClientFIO}. Email:{ Email}. Password: { Password}", model.Id, model.ClientFIO, model.Email, model.Password);
|
||||||
|
var element = _clientStorage.GetElement(new ClientSearchModel
|
||||||
|
{
|
||||||
|
Email = model.Email
|
||||||
|
});
|
||||||
|
if (element != null && element.Id != model.Id)
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("Такой клиент уже существует");
|
||||||
|
}
|
||||||
|
|
||||||
public ClientViewModel? ReadElement(ClientSearchModel model)
|
}
|
||||||
{
|
}
|
||||||
if (model == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(model));
|
|
||||||
}
|
|
||||||
_logger.LogInformation("ReadElement. ClientFIO: {ClientFIO}. Email: {Email}. Id: {Id}.", model.ClientFIO, model.Email, model.Id);
|
|
||||||
|
|
||||||
var element = _clientStorage.GetElement(model);
|
|
||||||
if (element == null)
|
|
||||||
{
|
|
||||||
_logger.LogWarning("ReadElement element not found");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
_logger.LogInformation("ReadElement find. Id: {Id}", element.Id);
|
|
||||||
return element;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<ClientViewModel>? ReadList(ClientSearchModel? model)
|
|
||||||
{
|
|
||||||
_logger.LogInformation("ReadList. ClientFIO: {ClientName}. Email: {Email}. Id: {Id}.", model?.ClientFIO, model?.Email, model?.Id);
|
|
||||||
|
|
||||||
var list = model == null ? _clientStorage.GetFullList() : _clientStorage.GetFilteredList(model);
|
|
||||||
if (list == null)
|
|
||||||
{
|
|
||||||
_logger.LogWarning("ReadList return null list");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool Update(ClientBindingModel model)
|
|
||||||
{
|
|
||||||
CheckModel(model);
|
|
||||||
if (_clientStorage.Update(model) == null)
|
|
||||||
{
|
|
||||||
_logger.LogWarning("Update operation failed");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void CheckModel(ClientBindingModel model, bool withParams = true)
|
|
||||||
{
|
|
||||||
if (model == null)
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException(nameof(model));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!withParams)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(model.ClientFIO))
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException("Нет ФИО клиента", nameof(model.ClientFIO));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(model.Email))
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException("Нет почты клиента", nameof(model.Email));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (string.IsNullOrEmpty(model.Password))
|
|
||||||
{
|
|
||||||
throw new ArgumentNullException("Нет пароля клиента", nameof(model.Password));
|
|
||||||
}
|
|
||||||
_logger.LogInformation("Client. ClientFIO: {ClientFIO}. Email: {Email}. Id: {Id}", model.ClientFIO, model.Email, model.Id);
|
|
||||||
|
|
||||||
var element = _clientStorage.GetElement(new ClientSearchModel
|
|
||||||
{
|
|
||||||
Email = model.Email
|
|
||||||
});
|
|
||||||
|
|
||||||
if (element != null && element.Id != model.Id)
|
|
||||||
{
|
|
||||||
throw new InvalidOperationException("Клиент с такой почтой уже есть");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,94 @@
|
|||||||
|
using GiftShopContracts.BindingModels;
|
||||||
|
using GiftShopContracts.BusinessLogicsContracts;
|
||||||
|
using GiftShopContracts.SearchModels;
|
||||||
|
using GiftShopContracts.StoragesContracts;
|
||||||
|
using GiftShopContracts.ViewModels;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace GiftShopBusinessLogic.BusinessLogics
|
||||||
|
{
|
||||||
|
public class MessageInfoLogic : IMessageInfoLogic
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IClientStorage _clientStorage;
|
||||||
|
private readonly IMessageInfoStorage _messageStorage;
|
||||||
|
|
||||||
|
public MessageInfoLogic(ILogger<MessageInfoLogic> logger, IMessageInfoStorage messageStorage, IClientStorage clientStorage)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_messageStorage = messageStorage;
|
||||||
|
_clientStorage = clientStorage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Create(MessageInfoBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (_messageStorage.Insert(model) == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("Insert operation failed");
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
if (list == null)
|
||||||
|
{
|
||||||
|
_logger.LogWarning("ReadList return null list");
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogInformation("ReadList. Count: {Count}", list.Count);
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
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}.Subject:{Subject}.Body:{Body}", model.MessageId, model.SenderName, 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,10 +1,12 @@
|
|||||||
using GiftShopContracts.BindingModels;
|
using GiftShopBusinessLogic.MailWorker;
|
||||||
|
using GiftShopContracts.BindingModels;
|
||||||
using GiftShopContracts.BusinessLogicsContracts;
|
using GiftShopContracts.BusinessLogicsContracts;
|
||||||
using GiftShopContracts.SearchModels;
|
using GiftShopContracts.SearchModels;
|
||||||
using GiftShopContracts.StoragesContracts;
|
using GiftShopContracts.StoragesContracts;
|
||||||
using GiftShopContracts.ViewModels;
|
using GiftShopContracts.ViewModels;
|
||||||
using GiftShopDataModels.Enums;
|
using GiftShopDataModels.Enums;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
|
using MigraDoc.Rendering;
|
||||||
|
|
||||||
namespace GiftShopBusinessLogic.BusinessLogics
|
namespace GiftShopBusinessLogic.BusinessLogics
|
||||||
{
|
{
|
||||||
@ -14,15 +16,20 @@ namespace GiftShopBusinessLogic.BusinessLogics
|
|||||||
|
|
||||||
private readonly IOrderStorage _orderStorage;
|
private readonly IOrderStorage _orderStorage;
|
||||||
|
|
||||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
|
private readonly AbstractMailWorker _mailWorker;
|
||||||
|
|
||||||
|
private readonly IClientLogic _clientLogic;
|
||||||
|
|
||||||
|
static readonly object locker = new object();
|
||||||
|
|
||||||
|
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, AbstractMailWorker mailWorker, IClientLogic clientLogic)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_orderStorage = orderStorage;
|
_orderStorage = orderStorage;
|
||||||
}
|
_mailWorker = mailWorker;
|
||||||
public bool TakeOrderInWork(OrderBindingModel model)
|
_clientLogic = clientLogic;
|
||||||
{
|
}
|
||||||
return StatusUpdate(model, OrderStatus.Выполняется);
|
|
||||||
}
|
|
||||||
public bool CreateOrder(OrderBindingModel model)
|
public bool CreateOrder(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
CheckModel(model);
|
CheckModel(model);
|
||||||
@ -34,63 +41,73 @@ namespace GiftShopBusinessLogic.BusinessLogics
|
|||||||
}
|
}
|
||||||
|
|
||||||
model.Status = OrderStatus.Принят;
|
model.Status = OrderStatus.Принят;
|
||||||
|
var result = _orderStorage.Insert(model);
|
||||||
if (_orderStorage.Insert(model) == null)
|
if (result == null)
|
||||||
{
|
{
|
||||||
model.Status = OrderStatus.Неизвестен;
|
model.Status = OrderStatus.Неизвестен;
|
||||||
_logger.LogWarning("Insert operation failed");
|
_logger.LogWarning("Insert operation failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
SendOrderMessage(result.ClientId, $"Магазин подарков, Заказ №{result.Id}", $"Заказ №{result.Id} от {result.DateCreate} на сумму {result.Sum:0.00} принят");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus)
|
public bool StatusUpdate(OrderBindingModel model, OrderStatus newStatus)
|
||||||
{
|
{
|
||||||
var vmodel = _orderStorage.GetElement(new() { Id = model.Id });
|
CheckModel(model,false);
|
||||||
|
var element = _orderStorage.GetElement(new OrderSearchModel { Id = model.Id });
|
||||||
|
|
||||||
if (vmodel==null)
|
if (element == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(model));
|
_logger.LogWarning("Read operation failed");
|
||||||
}
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
|
||||||
if ((int)vmodel.Status + 1 != (int)newStatus)
|
if (element.Status != newStatus - 1)
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException($"Попытка перевести заказ не в следующий статус: " +
|
throw new InvalidOperationException($"Попытка перевести заказ не в следующий статус: " +
|
||||||
$"Текущий статус: {vmodel.Status} \n" +
|
$"Текущий статус: {element.Status} \n" +
|
||||||
$"Планируемый статус: {newStatus} \n" +
|
$"Планируемый статус: {newStatus} \n" +
|
||||||
$"Доступный статус: {(OrderStatus)((int)vmodel.Status + 1)}");
|
$"Доступный статус: {(OrderStatus)((int)element.Status + 1)}");
|
||||||
}
|
}
|
||||||
|
|
||||||
model.Status = newStatus;
|
model.Status = newStatus;
|
||||||
|
if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now;
|
||||||
|
model.DateCreate = element.DateCreate;
|
||||||
|
|
||||||
model.DateCreate = vmodel.DateCreate;
|
if (model.DateImplement == null)
|
||||||
|
model.DateImplement = element.DateImplement;
|
||||||
|
|
||||||
if (model.DateImplement == null)
|
if (element.ImplementerId.HasValue)
|
||||||
model.DateImplement = vmodel.DateImplement;
|
model.ImplementerId = element.ImplementerId;
|
||||||
|
|
||||||
if (vmodel.ImplementerId.HasValue)
|
model.GiftId = element.GiftId;
|
||||||
model.ImplementerId = vmodel.ImplementerId;
|
model.Sum = element.Sum;
|
||||||
|
model.Count = element.Count;
|
||||||
|
|
||||||
model.GiftId = vmodel.GiftId;
|
var result = _orderStorage.Update(model);
|
||||||
model.Sum = vmodel.Sum;
|
if (result == null)
|
||||||
model.Count = vmodel.Count;
|
|
||||||
|
|
||||||
|
|
||||||
if (_orderStorage.Update(model) == null)
|
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Update operation failed");
|
_logger.LogWarning("Update operation failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
SendOrderMessage(result.ClientId, $"Магазин подарков, Заказ №{result.Id}", $"Заказ №{model.Id} изменен статус на {result.Status}");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool TakeOrderInWork(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
lock (locker)
|
||||||
|
{
|
||||||
|
return StatusUpdate(model, OrderStatus.Выполняется);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public bool DeliveryOrder(OrderBindingModel model)
|
public bool DeliveryOrder(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
model.DateImplement = DateTime.Now;
|
model.DateImplement = DateTime.Now;
|
||||||
return StatusUpdate(model, OrderStatus.Готов);
|
return StatusUpdate(model, OrderStatus.Готов);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool FinishOrder(OrderBindingModel model)
|
public bool FinishOrder(OrderBindingModel model)
|
||||||
@ -120,52 +137,62 @@ namespace GiftShopBusinessLogic.BusinessLogics
|
|||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(model));
|
throw new ArgumentNullException(nameof(model));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!withParams)
|
if (!withParams)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (model.GiftId < 0)
|
if (model.GiftId < 0)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("Некорректный идентификатор изделия", nameof(model.GiftId));
|
throw new ArgumentNullException("Некорректный идентификатор изделия", nameof(model.GiftId));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (model.Count <= 0)
|
if (model.Count <= 0)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("Количество изделий в заказе должно быть больше 0", nameof(model.Count));
|
throw new ArgumentNullException("Количество изделий в заказе должно быть больше 0", nameof(model.Count));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (model.Sum <= 0)
|
if (model.Sum <= 0)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum));
|
throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum));
|
||||||
}
|
}
|
||||||
|
|
||||||
_logger.LogInformation("Order. OrderId:{Id}.Sum:{ Sum}. EngineId: { EngineId}", model.Id, model.Sum, model.GiftId);
|
_logger.LogInformation("Order. OrderId:{Id}.Sum:{ Sum}. EngineId: { EngineId}", model.Id, model.Sum, model.GiftId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public OrderViewModel? ReadElement(OrderSearchModel model)
|
public OrderViewModel? ReadElement(OrderSearchModel model)
|
||||||
{
|
{
|
||||||
if (model == null)
|
if (model == null)
|
||||||
{
|
{
|
||||||
throw new ArgumentNullException(nameof(model));
|
throw new ArgumentNullException(nameof(model));
|
||||||
}
|
}
|
||||||
|
|
||||||
_logger.LogInformation("ReadElement. Id:{ Id}", model.Id);
|
_logger.LogInformation("ReadElement. Id:{ Id}", model.Id);
|
||||||
|
|
||||||
var element = _orderStorage.GetElement(model);
|
var element = _orderStorage.GetElement(model);
|
||||||
|
|
||||||
if (element == null)
|
if (element == null)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("ReadElement element not found");
|
_logger.LogWarning("ReadElement element not found");
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
_logger.LogInformation("ReadElement find. Id:{Id}", element.Id);
|
||||||
|
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
private bool SendOrderMessage(int clientId, string subject, string text)
|
||||||
|
{
|
||||||
|
var client = _clientLogic.ReadElement(new() { Id = clientId });
|
||||||
|
if (client == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
_mailWorker.MailSendAsync(new()
|
||||||
|
{
|
||||||
|
MailAddress = client.Email,
|
||||||
|
Subject = subject,
|
||||||
|
Text = text
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="DocumentFormat.OpenXml" Version="2.20.0" />
|
<PackageReference Include="DocumentFormat.OpenXml" Version="2.20.0" />
|
||||||
|
<PackageReference Include="MailKit" Version="4.5.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
|
||||||
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.15" />
|
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.15" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
100
GiftShop/GiftShopBusinessLogic/MailWorker/AbstractMailWorker.cs
Normal file
100
GiftShop/GiftShopBusinessLogic/MailWorker/AbstractMailWorker.cs
Normal file
@ -0,0 +1,100 @@
|
|||||||
|
using GiftShopContracts.BindingModels;
|
||||||
|
using GiftShopContracts.BusinessLogicsContracts;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
|
namespace GiftShopBusinessLogic.MailWorker
|
||||||
|
{
|
||||||
|
public abstract class AbstractMailWorker
|
||||||
|
{
|
||||||
|
protected string _mailLogin = string.Empty;
|
||||||
|
|
||||||
|
protected string _mailPassword = string.Empty;
|
||||||
|
|
||||||
|
protected string _smtpClientHost = string.Empty;
|
||||||
|
|
||||||
|
protected int _smtpClientPort;
|
||||||
|
|
||||||
|
protected string _popHost = string.Empty;
|
||||||
|
|
||||||
|
protected int _popPort;
|
||||||
|
|
||||||
|
private readonly IMessageInfoLogic _messageInfoLogic;
|
||||||
|
|
||||||
|
private readonly IClientLogic _clientLogic;
|
||||||
|
|
||||||
|
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
|
public AbstractMailWorker(ILogger<AbstractMailWorker> logger, IMessageInfoLogic messageInfoLogic, IClientLogic clientLogic)
|
||||||
|
{
|
||||||
|
_logger = logger;
|
||||||
|
_messageInfoLogic = messageInfoLogic;
|
||||||
|
_clientLogic = clientLogic;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void MailConfig(MailConfigBindingModel config)
|
||||||
|
{
|
||||||
|
_mailLogin = config.MailLogin;
|
||||||
|
_mailPassword = config.MailPassword;
|
||||||
|
_smtpClientHost = config.SmtpClientHost;
|
||||||
|
_smtpClientPort = config.SmtpClientPort;
|
||||||
|
_popHost = config.PopHost;
|
||||||
|
_popPort = config.PopPort;
|
||||||
|
_logger.LogDebug("Config: {login}, {password}, {clientHost}, {clientPOrt}, {popHost}, {popPort}", _mailLogin, _mailPassword, _smtpClientHost, _smtpClientPort, _popHost, _popPort);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async void MailSendAsync(MailSendInfoBindingModel info)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(_mailLogin) || string.IsNullOrEmpty(_mailPassword))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(_smtpClientHost) || _smtpClientPort == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(info.MailAddress) || string.IsNullOrEmpty(info.Subject) || string.IsNullOrEmpty(info.Text))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_logger.LogDebug("Send Mail: {To}, {Subject}", info.MailAddress, info.Subject);
|
||||||
|
await SendMailAsync(info);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async void MailCheck()
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(_mailLogin) || string.IsNullOrEmpty(_mailPassword))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (string.IsNullOrEmpty(_popHost) || _popPort == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_messageInfoLogic == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var list = await ReceiveMailAsync();
|
||||||
|
_logger.LogDebug("Check Mail: {Count} new mails", list.Count);
|
||||||
|
foreach (var mail in list)
|
||||||
|
{
|
||||||
|
mail.ClientId = _clientLogic.ReadElement(new() { Email = mail.SenderName })?.Id;
|
||||||
|
_messageInfoLogic.Create(mail);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract Task SendMailAsync(MailSendInfoBindingModel info);
|
||||||
|
|
||||||
|
protected abstract Task<List<MessageInfoBindingModel>> ReceiveMailAsync();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
77
GiftShop/GiftShopBusinessLogic/MailWorker/MailKitWorker.cs
Normal file
77
GiftShop/GiftShopBusinessLogic/MailWorker/MailKitWorker.cs
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
using GiftShopContracts.BindingModels;
|
||||||
|
using GiftShopContracts.BusinessLogicsContracts;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using System.Net.Mail;
|
||||||
|
using System.Net;
|
||||||
|
using System.Text;
|
||||||
|
using MailKit.Net.Pop3;
|
||||||
|
using MailKit.Security;
|
||||||
|
|
||||||
|
namespace GiftShopBusinessLogic.MailWorker
|
||||||
|
{
|
||||||
|
public class MailKitWorker : AbstractMailWorker
|
||||||
|
{
|
||||||
|
public MailKitWorker(ILogger<MailKitWorker> logger, IMessageInfoLogic messageInfoLogic, IClientLogic clientLogic) : base(logger, messageInfoLogic, clientLogic) { }
|
||||||
|
|
||||||
|
protected override async Task SendMailAsync(MailSendInfoBindingModel info)
|
||||||
|
{
|
||||||
|
using var objMailMessage = new MailMessage();
|
||||||
|
using var objSmtpClient = new SmtpClient(_smtpClientHost, _smtpClientPort);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
objMailMessage.From = new MailAddress(_mailLogin);
|
||||||
|
objMailMessage.To.Add(new MailAddress(info.MailAddress));
|
||||||
|
objMailMessage.Subject = info.Subject;
|
||||||
|
objMailMessage.Body = info.Text;
|
||||||
|
objMailMessage.SubjectEncoding = Encoding.UTF8;
|
||||||
|
objMailMessage.BodyEncoding = Encoding.UTF8;
|
||||||
|
objSmtpClient.UseDefaultCredentials = false;
|
||||||
|
objSmtpClient.EnableSsl = true;
|
||||||
|
objSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
|
||||||
|
objSmtpClient.Credentials = new NetworkCredential(_mailLogin, _mailPassword);
|
||||||
|
|
||||||
|
await Task.Run(() => objSmtpClient.Send(objMailMessage));
|
||||||
|
}
|
||||||
|
catch (Exception)
|
||||||
|
{
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override async Task<List<MessageInfoBindingModel>> ReceiveMailAsync()
|
||||||
|
{
|
||||||
|
var list = new List<MessageInfoBindingModel>();
|
||||||
|
using var client = new Pop3Client();
|
||||||
|
await Task.Run(() =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
client.Connect(_popHost, _popPort, SecureSocketOptions.SslOnConnect);
|
||||||
|
client.Authenticate(_mailLogin, _mailPassword);
|
||||||
|
for (int i = 0; i < client.Count; i++)
|
||||||
|
{
|
||||||
|
var message = client.GetMessage(i);
|
||||||
|
foreach (var mail in message.From.Mailboxes)
|
||||||
|
{
|
||||||
|
list.Add(new MessageInfoBindingModel
|
||||||
|
{
|
||||||
|
DateDelivery = message.Date.DateTime,
|
||||||
|
MessageId = message.MessageId,
|
||||||
|
SenderName = mail.Address,
|
||||||
|
Subject = message.Subject,
|
||||||
|
Body = message.HtmlBody
|
||||||
|
}) ;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (AuthenticationException)
|
||||||
|
{ }
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
client.Disconnect(true);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -101,9 +101,9 @@ namespace GiftShopClientApp.Controllers
|
|||||||
}
|
}
|
||||||
APIClient.PostRequest("api/client/register", new ClientBindingModel
|
APIClient.PostRequest("api/client/register", new ClientBindingModel
|
||||||
{
|
{
|
||||||
ClientFIO = fio,
|
|
||||||
Email = login,
|
Email = login,
|
||||||
Password = password
|
Password = password,
|
||||||
|
ClientFIO = fio
|
||||||
});
|
});
|
||||||
Response.Redirect("Enter");
|
Response.Redirect("Enter");
|
||||||
return;
|
return;
|
||||||
@ -143,5 +143,15 @@ namespace GiftShopClientApp.Controllers
|
|||||||
var gif = APIClient.GetRequest<GiftViewModel>($"api/main/getgift?giftId={gift}");
|
var gif = APIClient.GetRequest<GiftViewModel>($"api/main/getgift?giftId={gift}");
|
||||||
return count * (gif?.Price ?? 1);
|
return count * (gif?.Price ?? 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public IActionResult Mails()
|
||||||
|
{
|
||||||
|
if (APIClient.Client == null)
|
||||||
|
{
|
||||||
|
return Redirect("~/Home/Enter");
|
||||||
|
}
|
||||||
|
return View(APIClient.GetRequest<List<MessageInfoViewModel>>($"api/client/getmessages?clientId={APIClient.Client.Id}"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -7,6 +7,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="MailKit" Version="4.5.0" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
},
|
},
|
||||||
"dotnetRunMessages": true,
|
"dotnetRunMessages": true,
|
||||||
"applicationUrl": "http://localhost:7105;http://localhost:5092"
|
"applicationUrl": "https://localhost:7098;http://localhost:8080"
|
||||||
},
|
},
|
||||||
"IIS Express": {
|
"IIS Express": {
|
||||||
"commandName": "IISExpress",
|
"commandName": "IISExpress",
|
||||||
@ -21,8 +21,8 @@
|
|||||||
"windowsAuthentication": false,
|
"windowsAuthentication": false,
|
||||||
"anonymousAuthentication": false,
|
"anonymousAuthentication": false,
|
||||||
"iisExpress": {
|
"iisExpress": {
|
||||||
"applicationUrl": "http://localhost:34342",
|
"applicationUrl": "http://localhost:36192",
|
||||||
"sslPort": 0
|
"sslPort": 44375
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
53
GiftShop/GiftShopClientApp/Views/Home/Mails.cshtml
Normal file
53
GiftShop/GiftShopClientApp/Views/Home/Mails.cshtml
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
@using GiftShopContracts.ViewModels
|
||||||
|
@model List<MessageInfoViewModel>
|
||||||
|
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "Mails";
|
||||||
|
}
|
||||||
|
|
||||||
|
<div class="text-center">
|
||||||
|
<h1 class="display-4">Письма</h1>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<div class="text-center">
|
||||||
|
@{
|
||||||
|
if (Model == null)
|
||||||
|
{
|
||||||
|
<h3 class="display-4">Авторизируйтесь</h3>
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
<table class="table">
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>
|
||||||
|
Дата письма
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
Заголовок
|
||||||
|
</th>
|
||||||
|
<th>
|
||||||
|
Текст
|
||||||
|
</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
@foreach (var item in Model)
|
||||||
|
{
|
||||||
|
<tr>
|
||||||
|
<td>
|
||||||
|
@Html.DisplayFor(modelItem => item.DateDelivery)
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@Html.DisplayFor(modelItem => item.Subject)
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
@Html.DisplayFor(modelItem => item.Body)
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
}
|
||||||
|
</div>
|
@ -25,6 +25,9 @@
|
|||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Личные данные</a>
|
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Privacy">Личные данные</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Mails">Письма</a>
|
||||||
|
</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Enter">Вход</a>
|
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="Enter">Вход</a>
|
||||||
</li>
|
</li>
|
||||||
|
@ -7,5 +7,5 @@
|
|||||||
},
|
},
|
||||||
"AllowedHosts": "*",
|
"AllowedHosts": "*",
|
||||||
|
|
||||||
"IPAddress": "http://localhost:5062/"
|
"IPAddress": "http://localhost:5175/"
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,17 @@
|
|||||||
|
namespace GiftShopContracts.BindingModels
|
||||||
|
{
|
||||||
|
public class MailConfigBindingModel
|
||||||
|
{
|
||||||
|
public string MailLogin { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public string MailPassword { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public string SmtpClientHost { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public int SmtpClientPort { get; set; }
|
||||||
|
|
||||||
|
public string PopHost { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public int PopPort { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,11 @@
|
|||||||
|
namespace GiftShopContracts.BindingModels
|
||||||
|
{
|
||||||
|
public class MailSendInfoBindingModel
|
||||||
|
{
|
||||||
|
public string MailAddress { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public string Subject { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public string Text { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
using GiftShopDataModels.Models;
|
||||||
|
|
||||||
|
namespace GiftShopContracts.BindingModels
|
||||||
|
{
|
||||||
|
public class MessageInfoBindingModel : IMessageInfoModel
|
||||||
|
{
|
||||||
|
public string MessageId { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public int? ClientId { get; set; }
|
||||||
|
|
||||||
|
public string SenderName { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public string Subject { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public string Body { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public DateTime DateDelivery { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
using GiftShopContracts.BindingModels;
|
||||||
|
using GiftShopContracts.SearchModels;
|
||||||
|
using GiftShopContracts.ViewModels;
|
||||||
|
|
||||||
|
namespace GiftShopContracts.BusinessLogicsContracts
|
||||||
|
{
|
||||||
|
public interface IMessageInfoLogic
|
||||||
|
{
|
||||||
|
List<MessageInfoViewModel>? ReadList(MessageInfoSearchModel? model);
|
||||||
|
|
||||||
|
bool Create(MessageInfoBindingModel model);
|
||||||
|
}
|
||||||
|
}
|
@ -6,6 +6,10 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="MailKit" Version="4.5.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\GiftShopDataModels\GiftShopDataModels.csproj" />
|
<ProjectReference Include="..\GiftShopDataModels\GiftShopDataModels.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -0,0 +1,9 @@
|
|||||||
|
namespace GiftShopContracts.SearchModels
|
||||||
|
{
|
||||||
|
public class MessageInfoSearchModel
|
||||||
|
{
|
||||||
|
public int? ClientId { get; set; }
|
||||||
|
|
||||||
|
public string? MessageId { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
using GiftShopContracts.BindingModels;
|
||||||
|
using GiftShopContracts.SearchModels;
|
||||||
|
using GiftShopContracts.ViewModels;
|
||||||
|
|
||||||
|
namespace GiftShopContracts.StoragesContracts
|
||||||
|
{
|
||||||
|
public interface IMessageInfoStorage
|
||||||
|
{
|
||||||
|
List<MessageInfoViewModel> GetFullList();
|
||||||
|
|
||||||
|
List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model);
|
||||||
|
|
||||||
|
MessageInfoViewModel? GetElement(MessageInfoSearchModel model);
|
||||||
|
|
||||||
|
MessageInfoViewModel? Insert(MessageInfoBindingModel model);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
using GiftShopDataModels.Models;
|
||||||
|
using System.ComponentModel;
|
||||||
|
|
||||||
|
namespace GiftShopContracts.ViewModels
|
||||||
|
{
|
||||||
|
public class MessageInfoViewModel : IMessageInfoModel
|
||||||
|
{
|
||||||
|
public string MessageId { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
public int? ClientId { get; set; }
|
||||||
|
|
||||||
|
[DisplayName("Имя отправителя")]
|
||||||
|
public string SenderName { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
[DisplayName("Дата отправления")]
|
||||||
|
public DateTime DateDelivery { get; set; }
|
||||||
|
|
||||||
|
[DisplayName("Тема")]
|
||||||
|
public string Subject { get; set; } = string.Empty;
|
||||||
|
|
||||||
|
[DisplayName("Содержание")]
|
||||||
|
public string Body { get; set; } = string.Empty;
|
||||||
|
}
|
||||||
|
}
|
@ -6,4 +6,8 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="MailKit" Version="4.5.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
17
GiftShop/GiftShopDataModels/Models/IMessageInfoModel.cs
Normal file
17
GiftShop/GiftShopDataModels/Models/IMessageInfoModel.cs
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
namespace GiftShopDataModels.Models
|
||||||
|
{
|
||||||
|
public interface IMessageInfoModel
|
||||||
|
{
|
||||||
|
string MessageId { get; }
|
||||||
|
|
||||||
|
int? ClientId { get; }
|
||||||
|
|
||||||
|
string SenderName { get; }
|
||||||
|
|
||||||
|
DateTime DateDelivery { get; }
|
||||||
|
|
||||||
|
string Subject { get; }
|
||||||
|
|
||||||
|
string Body { get; }
|
||||||
|
}
|
||||||
|
}
|
@ -25,5 +25,7 @@ namespace GiftShopDatabaseImplement
|
|||||||
public virtual DbSet<Client> Clients { set; get; }
|
public virtual DbSet<Client> Clients { set; get; }
|
||||||
|
|
||||||
public virtual DbSet<Implementer> Implementers { set; get; }
|
public virtual DbSet<Implementer> Implementers { set; get; }
|
||||||
|
|
||||||
|
public virtual DbSet<Message> Messages { set; get; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="MailKit" Version="4.5.0" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.4" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.4" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.4" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.4" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.4">
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="7.0.4">
|
||||||
|
@ -0,0 +1,52 @@
|
|||||||
|
using GiftShopContracts.BindingModels;
|
||||||
|
using GiftShopContracts.SearchModels;
|
||||||
|
using GiftShopContracts.StoragesContracts;
|
||||||
|
using GiftShopContracts.ViewModels;
|
||||||
|
using GiftShopDatabaseImplement.Models;
|
||||||
|
|
||||||
|
namespace GiftShopDatabaseImplement.Implements
|
||||||
|
{
|
||||||
|
public class MessageInfoStorage : IMessageInfoStorage
|
||||||
|
{
|
||||||
|
public MessageInfoViewModel? GetElement(MessageInfoSearchModel model)
|
||||||
|
{
|
||||||
|
using var context = new GiftShopDatabase();
|
||||||
|
if (string.IsNullOrEmpty(model.MessageId))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return context.Messages.FirstOrDefault(x => x.MessageId == model.MessageId)?.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model)
|
||||||
|
{
|
||||||
|
//if (!model.ClientId.HasValue) return new();
|
||||||
|
using var context = new GiftShopDatabase();
|
||||||
|
return context.Messages
|
||||||
|
.Where(x => x.ClientId == model.ClientId)
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<MessageInfoViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
using var context = new GiftShopDatabase();
|
||||||
|
return context.Messages
|
||||||
|
.Select(x => x.GetViewModel)
|
||||||
|
.ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public MessageInfoViewModel? Insert(MessageInfoBindingModel model)
|
||||||
|
{
|
||||||
|
using var context = new GiftShopDatabase();
|
||||||
|
var newMessage = Message.Create(context, model);
|
||||||
|
if (newMessage == null || context.Messages.Any(x => x.MessageId.Equals(model.MessageId)))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
context.Messages.Add(newMessage);
|
||||||
|
context.SaveChanges();
|
||||||
|
return newMessage.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -7,23 +7,23 @@ using Microsoft.EntityFrameworkCore;
|
|||||||
|
|
||||||
namespace GiftShopDatabaseImplement.Implements
|
namespace GiftShopDatabaseImplement.Implements
|
||||||
{
|
{
|
||||||
public class OrderStorage : IOrderStorage
|
public class OrderStorage : IOrderStorage
|
||||||
{
|
{
|
||||||
public OrderViewModel? Delete(OrderBindingModel model)
|
public OrderViewModel? Delete(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
using var context = new GiftShopDatabase();
|
using var context = new GiftShopDatabase();
|
||||||
var element = context.Orders.FirstOrDefault(rec => rec.Id == model.Id);
|
var element = context.Orders.FirstOrDefault(rec => rec.Id == model.Id);
|
||||||
if (element != null)
|
if (element != null)
|
||||||
{
|
{
|
||||||
context.Orders.Remove(element);
|
context.Orders.Remove(element);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
return element.GetViewModel;
|
return element.GetViewModel;
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||||
{
|
{
|
||||||
using var context = new GiftShopDatabase();
|
using var context = new GiftShopDatabase();
|
||||||
return context.Orders.Include(x => x.Gift).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(
|
return context.Orders.Include(x => x.Gift).Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(
|
||||||
x => ((model.Id.HasValue && x.Id == model.Id) ||
|
x => ((model.Id.HasValue && x.Id == model.Id) ||
|
||||||
@ -52,43 +52,43 @@ namespace GiftShopDatabaseImplement.Implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<OrderViewModel> GetFullList()
|
public List<OrderViewModel> GetFullList()
|
||||||
{
|
{
|
||||||
using var context = new GiftShopDatabase();
|
using var context = new GiftShopDatabase();
|
||||||
return context.Orders.Include(x => x.Gift)
|
return context.Orders.Include(x => x.Gift)
|
||||||
.Include(x => x.Client).Include(x => x.Implementer).Select(x => x.GetViewModel).ToList();
|
.Include(x => x.Client).Include(x => x.Implementer).Select(x => x.GetViewModel).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public OrderViewModel? Insert(OrderBindingModel model)
|
public OrderViewModel? Insert(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
using var context = new GiftShopDatabase();
|
using var context = new GiftShopDatabase();
|
||||||
var newOrder = Order.Create(model, context);
|
var newOrder = Order.Create(model, context);
|
||||||
if (newOrder == null)
|
if (newOrder == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
context.Orders.Add(newOrder);
|
context.Orders.Add(newOrder);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
|
|
||||||
return context.Orders
|
return context.Orders
|
||||||
.Include(x => x.Gift)
|
.Include(x => x.Gift)
|
||||||
.Include(x => x.Client)
|
.Include(x => x.Client)
|
||||||
.Include(x => x.Implementer)
|
.Include(x => x.Implementer)
|
||||||
.FirstOrDefault(x => x.Id == newOrder.Id)
|
.FirstOrDefault(x => x.Id == newOrder.Id)
|
||||||
?.GetViewModel;
|
?.GetViewModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public OrderViewModel? Update(OrderBindingModel model)
|
public OrderViewModel? Update(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
using var context = new GiftShopDatabase();
|
using var context = new GiftShopDatabase();
|
||||||
var order = context.Orders.Include(x => x.Gift)
|
var order = context.Orders.Include(x => x.Gift)
|
||||||
.Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => x.Id == model.Id);
|
.Include(x => x.Client).Include(x => x.Implementer).FirstOrDefault(x => x.Id == model.Id);
|
||||||
if (order == null)
|
if (order == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
order.Update(model);
|
order.Update(model);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
return order.GetViewModel;
|
return order.GetViewModel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
300
GiftShop/GiftShopDatabaseImplement/Migrations/20240516061313_lab7.Designer.cs
generated
Normal file
300
GiftShop/GiftShopDatabaseImplement/Migrations/20240516061313_lab7.Designer.cs
generated
Normal file
@ -0,0 +1,300 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using GiftShopDatabaseImplement;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace GiftShopDatabaseImplement.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(GiftShopDatabase))]
|
||||||
|
[Migration("20240516061313_lab7")]
|
||||||
|
partial class lab7
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "7.0.4")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||||
|
|
||||||
|
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("GiftShopDatabaseImplement.Models.Client", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("ClientFIO")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("Email")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("Password")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Clients");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("GiftShopDatabaseImplement.Models.Component", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("ComponentName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<double>("Cost")
|
||||||
|
.HasColumnType("float");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Components");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("GiftShopDatabaseImplement.Models.Gift", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("GiftName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<double>("Price")
|
||||||
|
.HasColumnType("float");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Gifts");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("GiftShopDatabaseImplement.Models.GiftComponent", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("ComponentId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("Count")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("GiftId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("ComponentId");
|
||||||
|
|
||||||
|
b.HasIndex("GiftId");
|
||||||
|
|
||||||
|
b.ToTable("GiftComponents");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("GiftShopDatabaseImplement.Models.Implementer", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("ImplementerFIO")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("Password")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<int>("Qualification")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("WorkExperience")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.ToTable("Implementers");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("GiftShopDatabaseImplement.Models.Message", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("MessageId")
|
||||||
|
.HasColumnType("nvarchar(450)");
|
||||||
|
|
||||||
|
b.Property<string>("Body")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<int?>("ClientId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateDelivery")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<string>("SenderName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("Subject")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.HasKey("MessageId");
|
||||||
|
|
||||||
|
b.HasIndex("ClientId");
|
||||||
|
|
||||||
|
b.ToTable("Messages");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("GiftShopDatabaseImplement.Models.Order", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<int>("ClientId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("Count")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateCreate")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<DateTime?>("DateImplement")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<int>("GiftId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<string>("GiftName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<int?>("ImplementerId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<int>("Status")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<double>("Sum")
|
||||||
|
.HasColumnType("float");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("ClientId");
|
||||||
|
|
||||||
|
b.HasIndex("GiftId");
|
||||||
|
|
||||||
|
b.HasIndex("ImplementerId");
|
||||||
|
|
||||||
|
b.ToTable("Orders");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("GiftShopDatabaseImplement.Models.GiftComponent", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("GiftShopDatabaseImplement.Models.Component", "Component")
|
||||||
|
.WithMany("GiftComponents")
|
||||||
|
.HasForeignKey("ComponentId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("GiftShopDatabaseImplement.Models.Gift", "Gift")
|
||||||
|
.WithMany("Components")
|
||||||
|
.HasForeignKey("GiftId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Component");
|
||||||
|
|
||||||
|
b.Navigation("Gift");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("GiftShopDatabaseImplement.Models.Message", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("GiftShopDatabaseImplement.Models.Client", "Client")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("ClientId");
|
||||||
|
|
||||||
|
b.Navigation("Client");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("GiftShopDatabaseImplement.Models.Order", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("GiftShopDatabaseImplement.Models.Client", "Client")
|
||||||
|
.WithMany("Orders")
|
||||||
|
.HasForeignKey("ClientId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("GiftShopDatabaseImplement.Models.Gift", "Gift")
|
||||||
|
.WithMany("Orders")
|
||||||
|
.HasForeignKey("GiftId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("GiftShopDatabaseImplement.Models.Implementer", "Implementer")
|
||||||
|
.WithMany("Orders")
|
||||||
|
.HasForeignKey("ImplementerId");
|
||||||
|
|
||||||
|
b.Navigation("Client");
|
||||||
|
|
||||||
|
b.Navigation("Gift");
|
||||||
|
|
||||||
|
b.Navigation("Implementer");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("GiftShopDatabaseImplement.Models.Client", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Orders");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("GiftShopDatabaseImplement.Models.Component", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("GiftComponents");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("GiftShopDatabaseImplement.Models.Gift", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Components");
|
||||||
|
|
||||||
|
b.Navigation("Orders");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("GiftShopDatabaseImplement.Models.Implementer", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Orders");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,48 @@
|
|||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace GiftShopDatabaseImplement.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class lab7 : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.CreateTable(
|
||||||
|
name: "Messages",
|
||||||
|
columns: table => new
|
||||||
|
{
|
||||||
|
MessageId = table.Column<string>(type: "nvarchar(450)", nullable: false),
|
||||||
|
ClientId = table.Column<int>(type: "int", nullable: true),
|
||||||
|
SenderName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||||
|
DateDelivery = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||||
|
Subject = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||||
|
Body = table.Column<string>(type: "nvarchar(max)", nullable: false)
|
||||||
|
},
|
||||||
|
constraints: table =>
|
||||||
|
{
|
||||||
|
table.PrimaryKey("PK_Messages", x => x.MessageId);
|
||||||
|
table.ForeignKey(
|
||||||
|
name: "FK_Messages_Clients_ClientId",
|
||||||
|
column: x => x.ClientId,
|
||||||
|
principalTable: "Clients",
|
||||||
|
principalColumn: "Id");
|
||||||
|
});
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_Messages_ClientId",
|
||||||
|
table: "Messages",
|
||||||
|
column: "ClientId");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropTable(
|
||||||
|
name: "Messages");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -140,6 +140,36 @@ namespace GiftShopDatabaseImplement.Migrations
|
|||||||
b.ToTable("Implementers");
|
b.ToTable("Implementers");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("GiftShopDatabaseImplement.Models.Message", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("MessageId")
|
||||||
|
.HasColumnType("nvarchar(450)");
|
||||||
|
|
||||||
|
b.Property<string>("Body")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<int?>("ClientId")
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
b.Property<DateTime>("DateDelivery")
|
||||||
|
.HasColumnType("datetime2");
|
||||||
|
|
||||||
|
b.Property<string>("SenderName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("Subject")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.HasKey("MessageId");
|
||||||
|
|
||||||
|
b.HasIndex("ClientId");
|
||||||
|
|
||||||
|
b.ToTable("Messages");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("GiftShopDatabaseImplement.Models.Order", b =>
|
modelBuilder.Entity("GiftShopDatabaseImplement.Models.Order", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("Id")
|
b.Property<int>("Id")
|
||||||
@ -206,6 +236,15 @@ namespace GiftShopDatabaseImplement.Migrations
|
|||||||
b.Navigation("Gift");
|
b.Navigation("Gift");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("GiftShopDatabaseImplement.Models.Message", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("GiftShopDatabaseImplement.Models.Client", "Client")
|
||||||
|
.WithMany("ClientMessages")
|
||||||
|
.HasForeignKey("ClientId");
|
||||||
|
|
||||||
|
b.Navigation("Client");
|
||||||
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("GiftShopDatabaseImplement.Models.Order", b =>
|
modelBuilder.Entity("GiftShopDatabaseImplement.Models.Order", b =>
|
||||||
{
|
{
|
||||||
b.HasOne("GiftShopDatabaseImplement.Models.Client", "Client")
|
b.HasOne("GiftShopDatabaseImplement.Models.Client", "Client")
|
||||||
|
@ -18,6 +18,8 @@ namespace GiftShopDatabaseImplement.Models
|
|||||||
|
|
||||||
[ForeignKey("ClientId")]
|
[ForeignKey("ClientId")]
|
||||||
public virtual List<Order> Orders { get; set; } = new();
|
public virtual List<Order> Orders { get; set; } = new();
|
||||||
|
[ForeignKey("ClientId")]
|
||||||
|
public virtual List<Message> ClientMessages { get; set; } = new();
|
||||||
public static Client? Create(ClientBindingModel model)
|
public static Client? Create(ClientBindingModel model)
|
||||||
{
|
{
|
||||||
if (model == null)
|
if (model == null)
|
||||||
|
54
GiftShop/GiftShopDatabaseImplement/Models/Message.cs
Normal file
54
GiftShop/GiftShopDatabaseImplement/Models/Message.cs
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
using GiftShopContracts.BindingModels;
|
||||||
|
using GiftShopContracts.ViewModels;
|
||||||
|
using GiftShopDataModels.Models;
|
||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
|
namespace GiftShopDatabaseImplement.Models
|
||||||
|
{
|
||||||
|
public class Message : IMessageInfoModel
|
||||||
|
{
|
||||||
|
[Key]
|
||||||
|
[DatabaseGenerated(DatabaseGeneratedOption.None)]
|
||||||
|
public string MessageId { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
public int? ClientId { get; private set; }
|
||||||
|
|
||||||
|
public string SenderName { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
public DateTime DateDelivery { get; private set; } = DateTime.Now;
|
||||||
|
|
||||||
|
public string Subject { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
public string Body { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
public Client? Client { get; private set; }
|
||||||
|
public static Message? Create(GiftShopDatabase context, MessageInfoBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new()
|
||||||
|
{
|
||||||
|
Body = model.Body,
|
||||||
|
Subject = model.Subject,
|
||||||
|
ClientId = context.Clients.FirstOrDefault(x => x.Email == model.SenderName).Id,
|
||||||
|
Client = context.Clients.FirstOrDefault(x => x.Email == model.SenderName),
|
||||||
|
MessageId = model.MessageId,
|
||||||
|
SenderName = model.SenderName,
|
||||||
|
DateDelivery = model.DateDelivery,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public MessageInfoViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Body = Body,
|
||||||
|
Subject = Subject,
|
||||||
|
ClientId = ClientId,
|
||||||
|
MessageId = MessageId,
|
||||||
|
SenderName = SenderName,
|
||||||
|
DateDelivery = DateDelivery,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -6,55 +6,55 @@ using System.ComponentModel.DataAnnotations;
|
|||||||
|
|
||||||
namespace GiftShopDatabaseImplement.Models
|
namespace GiftShopDatabaseImplement.Models
|
||||||
{
|
{
|
||||||
public class Order : IOrderModel
|
public class Order : IOrderModel
|
||||||
{
|
{
|
||||||
public int Id { get; private set; }
|
public int Id { get; private set; }
|
||||||
|
|
||||||
public int GiftId { get; private set; }
|
public int GiftId { get; private set; }
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
public int ClientId { get; set; }
|
public int ClientId { get; set; }
|
||||||
|
|
||||||
public int? ImplementerId { get; private set; }
|
public int? ImplementerId { get; private set; }
|
||||||
|
|
||||||
public string GiftName { get; private set; } = string.Empty;
|
public string GiftName { get; private set; } = string.Empty;
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
public int Count { get; private set; }
|
public int Count { get; private set; }
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
public double Sum { get; private set; }
|
public double Sum { get; private set; }
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
|
public OrderStatus Status { get; private set; } = OrderStatus.Неизвестен;
|
||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
public DateTime DateCreate { get; private set; } = DateTime.Now;
|
||||||
|
|
||||||
public DateTime? DateImplement { get; private set; }
|
public DateTime? DateImplement { get; private set; }
|
||||||
|
|
||||||
public virtual Gift Gift { get; set; }
|
public virtual Gift Gift { get; set; }
|
||||||
|
|
||||||
public Client Client { get; set; }
|
public Client Client { get; set; }
|
||||||
public Implementer? Implementer { get; set; }
|
public Implementer? Implementer { get; set; }
|
||||||
|
|
||||||
public static Order? Create(OrderBindingModel? model, GiftShopDatabase context)
|
public static Order? Create(OrderBindingModel? model, GiftShopDatabase context)
|
||||||
{
|
{
|
||||||
if (model == null)
|
if (model == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Order()
|
return new Order()
|
||||||
{
|
{
|
||||||
Id = model.Id,
|
Id = model.Id,
|
||||||
GiftId = model.GiftId,
|
GiftId = model.GiftId,
|
||||||
GiftName = model.GiftName,
|
GiftName = model.GiftName,
|
||||||
Count = model.Count,
|
Count = model.Count,
|
||||||
Sum = model.Sum,
|
Sum = model.Sum,
|
||||||
Status = model.Status,
|
Status = model.Status,
|
||||||
DateCreate = model.DateCreate,
|
DateCreate = model.DateCreate,
|
||||||
DateImplement = model.DateImplement,
|
DateImplement = model.DateImplement,
|
||||||
Gift = context.Gifts.FirstOrDefault(x => x.Id == model.GiftId),
|
Gift = context.Gifts.FirstOrDefault(x => x.Id == model.GiftId),
|
||||||
ClientId = model.ClientId,
|
ClientId = model.ClientId,
|
||||||
Client = context.Clients.FirstOrDefault(x => x.Id == model.ClientId),
|
Client = context.Clients.FirstOrDefault(x => x.Id == model.ClientId),
|
||||||
@ -62,19 +62,19 @@ namespace GiftShopDatabaseImplement.Models
|
|||||||
Implementer = (model.ImplementerId.HasValue ? context.Implementers.FirstOrDefault(x => x.Id == model.ImplementerId)
|
Implementer = (model.ImplementerId.HasValue ? context.Implementers.FirstOrDefault(x => x.Id == model.ImplementerId)
|
||||||
: null),
|
: null),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Update(OrderBindingModel? model)
|
public void Update(OrderBindingModel? model)
|
||||||
{
|
{
|
||||||
if (model == null)
|
if (model == null)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Status = model.Status;
|
Status = model.Status;
|
||||||
DateImplement = model.DateImplement;
|
DateImplement = model.DateImplement;
|
||||||
ImplementerId = model.ImplementerId;
|
ImplementerId = model.ImplementerId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public OrderViewModel GetViewModel
|
public OrderViewModel GetViewModel
|
||||||
{
|
{
|
||||||
@ -86,8 +86,8 @@ namespace GiftShopDatabaseImplement.Models
|
|||||||
Id = Id,
|
Id = Id,
|
||||||
GiftId = GiftId,
|
GiftId = GiftId,
|
||||||
ClientId = ClientId,
|
ClientId = ClientId,
|
||||||
ImplementerId = ImplementerId,
|
ImplementerId = ImplementerId,
|
||||||
ClientFIO = Client.ClientFIO,
|
ClientFIO = Client.ClientFIO,
|
||||||
GiftName = Gift.GiftName,
|
GiftName = Gift.GiftName,
|
||||||
Count = Count,
|
Count = Count,
|
||||||
Sum = Sum,
|
Sum = Sum,
|
||||||
@ -99,4 +99,4 @@ namespace GiftShopDatabaseImplement.Models
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -17,7 +17,9 @@ namespace GiftShopFileImplement
|
|||||||
|
|
||||||
private readonly string ClientFileName = "Client.xml";
|
private readonly string ClientFileName = "Client.xml";
|
||||||
|
|
||||||
public List<Component> Components { get; private set; }
|
private readonly string MessageFileName = "Message.xml";
|
||||||
|
|
||||||
|
public List<Component> Components { get; private set; }
|
||||||
|
|
||||||
public List<Order> Orders { get; private set; }
|
public List<Order> Orders { get; private set; }
|
||||||
|
|
||||||
@ -27,6 +29,8 @@ namespace GiftShopFileImplement
|
|||||||
|
|
||||||
public List<Implementer> Implementers { get; private set; }
|
public List<Implementer> Implementers { get; private set; }
|
||||||
|
|
||||||
|
public List<Message> Messages { get; private set; }
|
||||||
|
|
||||||
public static DataFileSingleton GetInstance()
|
public static DataFileSingleton GetInstance()
|
||||||
{
|
{
|
||||||
if (instance == null)
|
if (instance == null)
|
||||||
@ -45,12 +49,16 @@ namespace GiftShopFileImplement
|
|||||||
public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement);
|
public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement);
|
||||||
|
|
||||||
public void SaveImplementers() => SaveData(Implementers, OrderFileName, "Implementers", x => x.GetXElement);
|
public void SaveImplementers() => SaveData(Implementers, OrderFileName, "Implementers", x => x.GetXElement);
|
||||||
|
|
||||||
|
public void SaveMessages() => SaveData(Messages, MessageFileName, "Messages", x => x.GetXElement);
|
||||||
private DataFileSingleton()
|
private DataFileSingleton()
|
||||||
{
|
{
|
||||||
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
|
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
|
||||||
Gifts = LoadData(GiftFileName, "Gift", x => Gift.Create(x)!)!;
|
Gifts = LoadData(GiftFileName, "Gift", x => Gift.Create(x)!)!;
|
||||||
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
|
Orders = LoadData(OrderFileName, "Order", x => Order.Create(x)!)!;
|
||||||
|
Clients = LoadData(ClientFileName, "Client", x => Client.Create(x)!)!;
|
||||||
Implementers = LoadData(ImplementerFileName, "Implementer", x => Implementer.Create(x)!)!;
|
Implementers = LoadData(ImplementerFileName, "Implementer", x => Implementer.Create(x)!)!;
|
||||||
|
Messages = LoadData(MessageFileName, "Message", x => Message.Create(x)!)!;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
|
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
|
||||||
|
@ -6,6 +6,10 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="MailKit" Version="4.5.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\GiftShopContracts\GiftShopContracts.csproj" />
|
<ProjectReference Include="..\GiftShopContracts\GiftShopContracts.csproj" />
|
||||||
<ProjectReference Include="..\GiftShopDataModels\GiftShopDataModels.csproj" />
|
<ProjectReference Include="..\GiftShopDataModels\GiftShopDataModels.csproj" />
|
||||||
|
@ -0,0 +1,52 @@
|
|||||||
|
using GiftShopContracts.BindingModels;
|
||||||
|
using GiftShopContracts.SearchModels;
|
||||||
|
using GiftShopContracts.StoragesContracts;
|
||||||
|
using GiftShopContracts.ViewModels;
|
||||||
|
using GiftShopFileImplement.Models;
|
||||||
|
|
||||||
|
namespace GiftShopFileImplement.Implements
|
||||||
|
{
|
||||||
|
public class MessageInfoStorage : IMessageInfoStorage
|
||||||
|
{
|
||||||
|
private readonly DataFileSingleton source;
|
||||||
|
public MessageInfoStorage()
|
||||||
|
{
|
||||||
|
source = DataFileSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
public MessageInfoViewModel? GetElement(MessageInfoSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.MessageId))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return source.Messages.FirstOrDefault(x => x.MessageId == model.MessageId)?.GetViewModel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(model.MessageId))
|
||||||
|
{
|
||||||
|
return new();
|
||||||
|
}
|
||||||
|
return source.Messages.Where(x =>
|
||||||
|
x.ClientId == model.ClientId).Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<MessageInfoViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
return source.Messages.Select(x => x.GetViewModel).ToList();
|
||||||
|
}
|
||||||
|
|
||||||
|
public MessageInfoViewModel? Insert(MessageInfoBindingModel model)
|
||||||
|
{
|
||||||
|
var newMessage = Message.Create(model);
|
||||||
|
if (newMessage == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
source.Messages.Add(newMessage);
|
||||||
|
source.SaveMessages();
|
||||||
|
return newMessage.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -6,36 +6,36 @@ using GiftShopFileImplement.Models;
|
|||||||
|
|
||||||
namespace GiftShopFileImplement.Implements
|
namespace GiftShopFileImplement.Implements
|
||||||
{
|
{
|
||||||
public class OrderStorage : IOrderStorage
|
public class OrderStorage : IOrderStorage
|
||||||
{
|
{
|
||||||
private readonly DataFileSingleton source;
|
private readonly DataFileSingleton source;
|
||||||
|
|
||||||
public OrderStorage()
|
public OrderStorage()
|
||||||
{
|
{
|
||||||
source = DataFileSingleton.GetInstance();
|
source = DataFileSingleton.GetInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
public OrderViewModel? Delete(OrderBindingModel model)
|
public OrderViewModel? Delete(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
var element = source.Orders.FirstOrDefault(x => x.Id == model.Id);
|
var element = source.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
|
||||||
if (element != null)
|
if (element != null)
|
||||||
{
|
{
|
||||||
source.Orders.Remove(element);
|
source.Orders.Remove(element);
|
||||||
source.SaveOrders();
|
source.SaveOrders();
|
||||||
|
|
||||||
return AccessStorage(element.GetViewModel);
|
return AccessStorage(element.GetViewModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||||
{
|
{
|
||||||
if (!model.Id.HasValue)
|
if (!model.Id.HasValue)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return AccessStorage(source.Orders
|
return AccessStorage(source.Orders
|
||||||
.FirstOrDefault(x => ((model.Id.HasValue && x.Id == model.Id) ||
|
.FirstOrDefault(x => ((model.Id.HasValue && x.Id == model.Id) ||
|
||||||
@ -43,8 +43,8 @@ namespace GiftShopFileImplement.Implements
|
|||||||
x.ImplementerId == model.ImplementerId && x.Status == model.Status)))?.GetViewModel);
|
x.ImplementerId == model.ImplementerId && x.Status == model.Status)))?.GetViewModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||||
{
|
{
|
||||||
return source.Orders
|
return source.Orders
|
||||||
.Where(x => (
|
.Where(x => (
|
||||||
(!model.Id.HasValue || x.Id == model.Id) &&
|
(!model.Id.HasValue || x.Id == model.Id) &&
|
||||||
@ -58,41 +58,41 @@ namespace GiftShopFileImplement.Implements
|
|||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<OrderViewModel> GetFullList()
|
public List<OrderViewModel> GetFullList()
|
||||||
{
|
{
|
||||||
return source.Orders.Select(x => AccessStorage(x.GetViewModel)).ToList();
|
return source.Orders.Select(x => AccessStorage(x.GetViewModel)).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public OrderViewModel? Insert(OrderBindingModel model)
|
public OrderViewModel? Insert(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1;
|
model.Id = source.Orders.Count > 0 ? source.Orders.Max(x => x.Id) + 1 : 1;
|
||||||
var newOrder = Order.Create(model);
|
var newOrder = Order.Create(model);
|
||||||
|
|
||||||
if (newOrder == null)
|
if (newOrder == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
source.Orders.Add(newOrder);
|
source.Orders.Add(newOrder);
|
||||||
source.SaveOrders();
|
source.SaveOrders();
|
||||||
|
|
||||||
return AccessStorage(newOrder.GetViewModel);
|
return AccessStorage(newOrder.GetViewModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
public OrderViewModel? Update(OrderBindingModel model)
|
public OrderViewModel? Update(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
var order = source.Orders.FirstOrDefault(x => x.Id == model.Id);
|
var order = source.Orders.FirstOrDefault(x => x.Id == model.Id);
|
||||||
|
|
||||||
if (order == null)
|
if (order == null)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
order.Update(model);
|
order.Update(model);
|
||||||
source.SaveOrders();
|
source.SaveOrders();
|
||||||
|
|
||||||
return AccessStorage(order.GetViewModel);
|
return AccessStorage(order.GetViewModel);
|
||||||
}
|
}
|
||||||
public OrderViewModel AccessStorage(OrderViewModel model)
|
public OrderViewModel AccessStorage(OrderViewModel model)
|
||||||
{
|
{
|
||||||
if (model == null)
|
if (model == null)
|
||||||
@ -109,4 +109,4 @@ namespace GiftShopFileImplement.Implements
|
|||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
74
GiftShop/GiftShopFileImplement/Models/Message.cs
Normal file
74
GiftShop/GiftShopFileImplement/Models/Message.cs
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
using GiftShopContracts.BindingModels;
|
||||||
|
using GiftShopContracts.ViewModels;
|
||||||
|
using GiftShopDataModels.Models;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
|
namespace GiftShopFileImplement.Models
|
||||||
|
{
|
||||||
|
public class Message : IMessageInfoModel
|
||||||
|
{
|
||||||
|
public string MessageId { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
public int? ClientId { get; private set; }
|
||||||
|
|
||||||
|
public string SenderName { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
public DateTime DateDelivery { get; private set; } = DateTime.Now;
|
||||||
|
|
||||||
|
public string Subject { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
public string Body { get; private set; } = string.Empty;
|
||||||
|
public static Message? Create(MessageInfoBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new()
|
||||||
|
{
|
||||||
|
Body = model.Body,
|
||||||
|
Subject = model.Subject,
|
||||||
|
DateDelivery = model.DateDelivery,
|
||||||
|
SenderName = model.SenderName,
|
||||||
|
ClientId = model.ClientId,
|
||||||
|
MessageId = model.MessageId
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Message? Create(XElement element)
|
||||||
|
{
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new()
|
||||||
|
{
|
||||||
|
Body = element.Attribute("Body")!.Value,
|
||||||
|
Subject = element.Attribute("Subject")!.Value,
|
||||||
|
DateDelivery = Convert.ToDateTime(element.Attribute("DateDelivery")!.Value),
|
||||||
|
SenderName = element.Attribute("SenderName")!.Value,
|
||||||
|
ClientId = Convert.ToInt32(element.Attribute("ClientId")!.Value),
|
||||||
|
MessageId = element.Attribute("MessageId")!.Value,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public MessageInfoViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Body = Body,
|
||||||
|
Subject = Subject,
|
||||||
|
DateDelivery = DateDelivery,
|
||||||
|
SenderName = SenderName,
|
||||||
|
ClientId = ClientId,
|
||||||
|
MessageId = MessageId
|
||||||
|
};
|
||||||
|
|
||||||
|
public XElement GetXElement => new("MessageInfo",
|
||||||
|
new XAttribute("Subject", Subject),
|
||||||
|
new XAttribute("Body", Body),
|
||||||
|
new XAttribute("ClientId", ClientId),
|
||||||
|
new XAttribute("MessageId", MessageId),
|
||||||
|
new XAttribute("SenderName", SenderName),
|
||||||
|
new XAttribute("DateDelivery", DateDelivery)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -10,6 +10,7 @@ namespace GiftShopListImplement
|
|||||||
public List<Gift> Gifts { get; set; }
|
public List<Gift> Gifts { get; set; }
|
||||||
public List<Client> Clients { get; set; }
|
public List<Client> Clients { get; set; }
|
||||||
public List<Implementer> Implementers { get; set; }
|
public List<Implementer> Implementers { get; set; }
|
||||||
|
public List<Message> Messages { get; set; }
|
||||||
private DataListSingleton()
|
private DataListSingleton()
|
||||||
{
|
{
|
||||||
Components = new List<Component>();
|
Components = new List<Component>();
|
||||||
@ -17,6 +18,7 @@ namespace GiftShopListImplement
|
|||||||
Gifts = new List<Gift>();
|
Gifts = new List<Gift>();
|
||||||
Clients = new List<Client>();
|
Clients = new List<Client>();
|
||||||
Implementers = new List<Implementer>();
|
Implementers = new List<Implementer>();
|
||||||
|
Messages = new List<Message>();
|
||||||
}
|
}
|
||||||
public static DataListSingleton GetInstance()
|
public static DataListSingleton GetInstance()
|
||||||
{
|
{
|
||||||
|
@ -6,6 +6,10 @@
|
|||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="MailKit" Version="4.5.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\GiftShopContracts\GiftShopContracts.csproj" />
|
<ProjectReference Include="..\GiftShopContracts\GiftShopContracts.csproj" />
|
||||||
<ProjectReference Include="..\GiftShopDataModels\GiftShopDataModels.csproj" />
|
<ProjectReference Include="..\GiftShopDataModels\GiftShopDataModels.csproj" />
|
||||||
|
@ -0,0 +1,60 @@
|
|||||||
|
using GiftShopContracts.BindingModels;
|
||||||
|
using GiftShopContracts.SearchModels;
|
||||||
|
using GiftShopContracts.StoragesContracts;
|
||||||
|
using GiftShopContracts.ViewModels;
|
||||||
|
using GiftShopListImplement.Models;
|
||||||
|
|
||||||
|
namespace GiftShopListImplement.Implements
|
||||||
|
{
|
||||||
|
public class MessageInfoStorage : IMessageInfoStorage
|
||||||
|
{
|
||||||
|
private readonly DataListSingleton _source;
|
||||||
|
public MessageInfoStorage()
|
||||||
|
{
|
||||||
|
_source = DataListSingleton.GetInstance();
|
||||||
|
}
|
||||||
|
public MessageInfoViewModel? GetElement(MessageInfoSearchModel model)
|
||||||
|
{
|
||||||
|
foreach (var message in _source.Messages)
|
||||||
|
{
|
||||||
|
if (model.MessageId != null && model.MessageId.Equals(message.MessageId))
|
||||||
|
return message.GetViewModel;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model)
|
||||||
|
{
|
||||||
|
var result = new List<MessageInfoViewModel>();
|
||||||
|
foreach (var message in _source.Messages)
|
||||||
|
{
|
||||||
|
if (message.ClientId.HasValue && message.ClientId == model.ClientId)
|
||||||
|
{
|
||||||
|
result.Add(message.GetViewModel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<MessageInfoViewModel> GetFullList()
|
||||||
|
{
|
||||||
|
var result = new List<MessageInfoViewModel>();
|
||||||
|
foreach (var message in _source.Messages)
|
||||||
|
{
|
||||||
|
result.Add(message.GetViewModel);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MessageInfoViewModel? Insert(MessageInfoBindingModel model)
|
||||||
|
{
|
||||||
|
var newMessage = Message.Create(model);
|
||||||
|
if (newMessage == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
_source.Messages.Add(newMessage);
|
||||||
|
return newMessage.GetViewModel;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -6,30 +6,30 @@ using GiftShopListImplement.Models;
|
|||||||
|
|
||||||
namespace GiftShopListImplement.Implements
|
namespace GiftShopListImplement.Implements
|
||||||
{
|
{
|
||||||
public class OrderStorage : IOrderStorage
|
public class OrderStorage : IOrderStorage
|
||||||
{
|
{
|
||||||
private readonly DataListSingleton _source;
|
private readonly DataListSingleton _source;
|
||||||
public OrderStorage()
|
public OrderStorage()
|
||||||
{
|
{
|
||||||
_source = DataListSingleton.GetInstance();
|
_source = DataListSingleton.GetInstance();
|
||||||
}
|
}
|
||||||
public OrderViewModel? Delete(OrderBindingModel model)
|
public OrderViewModel? Delete(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < _source.Orders.Count; ++i)
|
for (int i = 0; i < _source.Orders.Count; ++i)
|
||||||
{
|
{
|
||||||
if (_source.Orders[i].Id == model.Id)
|
if (_source.Orders[i].Id == model.Id)
|
||||||
{
|
{
|
||||||
var element = _source.Orders[i];
|
var element = _source.Orders[i];
|
||||||
_source.Orders.RemoveAt(i);
|
_source.Orders.RemoveAt(i);
|
||||||
return element.GetViewModel;
|
return element.GetViewModel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public OrderViewModel? GetElement(OrderSearchModel model)
|
public OrderViewModel? GetElement(OrderSearchModel model)
|
||||||
{
|
{
|
||||||
if (!model.Id.HasValue)
|
if (!model.Id.HasValue)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
@ -46,8 +46,8 @@ namespace GiftShopListImplement.Implements
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
public List<OrderViewModel> GetFilteredList(OrderSearchModel model)
|
||||||
{
|
{
|
||||||
var result = new List<OrderViewModel>();
|
var result = new List<OrderViewModel>();
|
||||||
foreach (var order in _source.Orders)
|
foreach (var order in _source.Orders)
|
||||||
{
|
{
|
||||||
@ -63,8 +63,8 @@ namespace GiftShopListImplement.Implements
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<OrderViewModel> GetFullList()
|
public List<OrderViewModel> GetFullList()
|
||||||
{
|
{
|
||||||
List<OrderViewModel> list = new();
|
List<OrderViewModel> list = new();
|
||||||
foreach (Order order in _source.Orders)
|
foreach (Order order in _source.Orders)
|
||||||
{
|
{
|
||||||
@ -73,8 +73,8 @@ namespace GiftShopListImplement.Implements
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
public OrderViewModel? Insert(OrderBindingModel model)
|
public OrderViewModel? Insert(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
model.Id = 1;
|
model.Id = 1;
|
||||||
foreach (Order order in _source.Orders)
|
foreach (Order order in _source.Orders)
|
||||||
{
|
{
|
||||||
@ -92,8 +92,8 @@ namespace GiftShopListImplement.Implements
|
|||||||
return newOrder.GetViewModel;
|
return newOrder.GetViewModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
public OrderViewModel? Update(OrderBindingModel model)
|
public OrderViewModel? Update(OrderBindingModel model)
|
||||||
{
|
{
|
||||||
foreach (Order order in _source.Orders)
|
foreach (Order order in _source.Orders)
|
||||||
{
|
{
|
||||||
if (order.Id == model.Id)
|
if (order.Id == model.Id)
|
||||||
@ -103,7 +103,7 @@ namespace GiftShopListImplement.Implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
public OrderViewModel AccessStorage(OrderViewModel model)
|
public OrderViewModel AccessStorage(OrderViewModel model)
|
||||||
{
|
{
|
||||||
if (model == null)
|
if (model == null)
|
||||||
@ -120,4 +120,4 @@ namespace GiftShopListImplement.Implements
|
|||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
48
GiftShop/GiftShopListImplement/Models/Message.cs
Normal file
48
GiftShop/GiftShopListImplement/Models/Message.cs
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
using GiftShopContracts.BindingModels;
|
||||||
|
using GiftShopContracts.ViewModels;
|
||||||
|
using GiftShopDataModels.Models;
|
||||||
|
|
||||||
|
namespace GiftShopListImplement.Models
|
||||||
|
{
|
||||||
|
public class Message : IMessageInfoModel
|
||||||
|
{
|
||||||
|
public string MessageId { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
public int? ClientId { get; private set; }
|
||||||
|
|
||||||
|
public string SenderName { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
public DateTime DateDelivery { get; private set; } = DateTime.Now;
|
||||||
|
|
||||||
|
public string Subject { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
public string Body { get; private set; } = string.Empty;
|
||||||
|
|
||||||
|
public static Message? Create(MessageInfoBindingModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return new()
|
||||||
|
{
|
||||||
|
Body = model.Body,
|
||||||
|
Subject = model.Subject,
|
||||||
|
DateDelivery = model.DateDelivery,
|
||||||
|
SenderName = model.SenderName,
|
||||||
|
ClientId = model.ClientId,
|
||||||
|
MessageId = model.MessageId
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public MessageInfoViewModel GetViewModel => new()
|
||||||
|
{
|
||||||
|
Body = Body,
|
||||||
|
Subject = Subject,
|
||||||
|
DateDelivery = DateDelivery,
|
||||||
|
SenderName = SenderName,
|
||||||
|
ClientId = ClientId,
|
||||||
|
MessageId = MessageId
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@ -3,6 +3,7 @@ using GiftShopContracts.BusinessLogicsContracts;
|
|||||||
using GiftShopContracts.SearchModels;
|
using GiftShopContracts.SearchModels;
|
||||||
using GiftShopContracts.ViewModels;
|
using GiftShopContracts.ViewModels;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using System.Net;
|
||||||
|
|
||||||
namespace GiftShopRestApi.Controllers
|
namespace GiftShopRestApi.Controllers
|
||||||
{
|
{
|
||||||
@ -14,11 +15,14 @@ namespace GiftShopRestApi.Controllers
|
|||||||
|
|
||||||
private readonly IClientLogic _logic;
|
private readonly IClientLogic _logic;
|
||||||
|
|
||||||
public ClientController(IClientLogic logic, ILogger<ClientController> logger)
|
private readonly IMessageInfoLogic _mailLogic;
|
||||||
|
|
||||||
|
public ClientController(IClientLogic logic, ILogger<ClientController> logger, IMessageInfoLogic mailLogic)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_logic = logic;
|
_logic = logic;
|
||||||
}
|
_mailLogic = mailLogic;
|
||||||
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public ClientViewModel? Login(string login, string password)
|
public ClientViewModel? Login(string login, string password)
|
||||||
@ -48,8 +52,9 @@ namespace GiftShopRestApi.Controllers
|
|||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_logger.LogError(ex, "Ошибка регистрации");
|
_logger.LogError(ex, "Ошибка регистрации");
|
||||||
|
Response.StatusCode = (int)HttpStatusCode.NotAcceptable;
|
||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
@ -65,5 +70,22 @@ namespace GiftShopRestApi.Controllers
|
|||||||
throw;
|
throw;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
[HttpGet]
|
||||||
|
public List<MessageInfoViewModel>? GetMessages(int clientId)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return _mailLogic.ReadList(new MessageInfoSearchModel
|
||||||
|
{
|
||||||
|
ClientId = clientId
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка получения писем клиента");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="MailKit" Version="4.5.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging.Log4Net.AspNetCore" Version="6.1.0" />
|
<PackageReference Include="Microsoft.Extensions.Logging.Log4Net.AspNetCore" Version="6.1.0" />
|
||||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
using GiftShopBusinessLogic.BusinessLogics;
|
using GiftShopBusinessLogic.BusinessLogics;
|
||||||
|
using GiftShopBusinessLogic.MailWorker;
|
||||||
|
using GiftShopContracts.BindingModels;
|
||||||
using GiftShopContracts.BusinessLogicsContracts;
|
using GiftShopContracts.BusinessLogicsContracts;
|
||||||
using GiftShopContracts.StoragesContracts;
|
using GiftShopContracts.StoragesContracts;
|
||||||
using GiftShopDatabaseImplement.Implements;
|
using GiftShopDatabaseImplement.Implements;
|
||||||
@ -15,11 +17,15 @@ builder.Services.AddTransient<IClientStorage, ClientStorage>();
|
|||||||
builder.Services.AddTransient<IImplementerStorage, ImplementerStorage>();
|
builder.Services.AddTransient<IImplementerStorage, ImplementerStorage>();
|
||||||
builder.Services.AddTransient<IOrderStorage, OrderStorage>();
|
builder.Services.AddTransient<IOrderStorage, OrderStorage>();
|
||||||
builder.Services.AddTransient<IGiftStorage, GiftStorage>();
|
builder.Services.AddTransient<IGiftStorage, GiftStorage>();
|
||||||
|
builder.Services.AddTransient<IMessageInfoStorage, MessageInfoStorage>();
|
||||||
|
|
||||||
builder.Services.AddTransient<IOrderLogic, OrderLogic>();
|
builder.Services.AddTransient<IOrderLogic, OrderLogic>();
|
||||||
builder.Services.AddTransient<IClientLogic, ClientLogic>();
|
builder.Services.AddTransient<IClientLogic, ClientLogic>();
|
||||||
builder.Services.AddTransient<IImplementerLogic, ImplementerLogic>();
|
builder.Services.AddTransient<IImplementerLogic, ImplementerLogic>();
|
||||||
builder.Services.AddTransient<IGiftLogic, GiftLogic>();
|
builder.Services.AddTransient<IGiftLogic, GiftLogic>();
|
||||||
|
builder.Services.AddTransient<IMessageInfoLogic, MessageInfoLogic>();
|
||||||
|
|
||||||
|
builder.Services.AddSingleton<AbstractMailWorker, MailKitWorker>();
|
||||||
|
|
||||||
builder.Services.AddControllers();
|
builder.Services.AddControllers();
|
||||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||||
@ -31,6 +37,17 @@ builder.Services.AddSwaggerGen(c =>
|
|||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
|
var mailSender = app.Services.GetService<AbstractMailWorker>();
|
||||||
|
mailSender?.MailConfig(new MailConfigBindingModel
|
||||||
|
{
|
||||||
|
MailLogin = builder.Configuration?.GetSection("MailLogin")?.Value?.ToString() ?? string.Empty,
|
||||||
|
MailPassword = builder.Configuration?.GetSection("MailPassword")?.Value?.ToString() ?? string.Empty,
|
||||||
|
SmtpClientHost = builder.Configuration?.GetSection("SmtpClientHost")?.Value?.ToString() ?? string.Empty,
|
||||||
|
SmtpClientPort = Convert.ToInt32(builder.Configuration?.GetSection("SmtpClientPort")?.Value?.ToString()),
|
||||||
|
PopHost = builder.Configuration?.GetSection("PopHost")?.Value?.ToString() ?? string.Empty,
|
||||||
|
PopPort = Convert.ToInt32(builder.Configuration?.GetSection("PopPort")?.Value?.ToString())
|
||||||
|
});
|
||||||
|
|
||||||
// Configure the HTTP request pipeline.
|
// Configure the HTTP request pipeline.
|
||||||
if (app.Environment.IsDevelopment())
|
if (app.Environment.IsDevelopment())
|
||||||
{
|
{
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||||
},
|
},
|
||||||
"dotnetRunMessages": true,
|
"dotnetRunMessages": true,
|
||||||
"applicationUrl": "http://localhost:7100;http://localhost:5062"
|
"applicationUrl": "https://localhost:7175;http://localhost:5175"
|
||||||
},
|
},
|
||||||
"IIS Express": {
|
"IIS Express": {
|
||||||
"commandName": "IISExpress",
|
"commandName": "IISExpress",
|
||||||
@ -24,8 +24,8 @@
|
|||||||
"windowsAuthentication": false,
|
"windowsAuthentication": false,
|
||||||
"anonymousAuthentication": false,
|
"anonymousAuthentication": false,
|
||||||
"iisExpress": {
|
"iisExpress": {
|
||||||
"applicationUrl": "http://localhost:39704",
|
"applicationUrl": "http://localhost:38846",
|
||||||
"sslPort": 0
|
"sslPort": 44369
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -5,5 +5,11 @@
|
|||||||
"Microsoft.AspNetCore": "Warning"
|
"Microsoft.AspNetCore": "Warning"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"AllowedHosts": "*"
|
"AllowedHosts": "*",
|
||||||
|
"SmtpClientHost": "smtp.gmail.com",
|
||||||
|
"SmtpClientPort": "587",
|
||||||
|
"PopHost": "pop.gmail.com",
|
||||||
|
"PopPort": "995",
|
||||||
|
"MailLogin": "tempfortrip22@gmail.com",
|
||||||
|
"MailPassword": "gbyb vdkr qeux xrol"
|
||||||
}
|
}
|
||||||
|
11
GiftShop/GiftShopView/App.config
Normal file
11
GiftShop/GiftShopView/App.config
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8" ?>
|
||||||
|
<configuration>
|
||||||
|
<appSettings>
|
||||||
|
<add key="SmtpClientHost" value="smtp.gmail.com" />
|
||||||
|
<add key="SmtpClientPort" value="587" />
|
||||||
|
<add key="PopHost" value="pop.gmail.com" />
|
||||||
|
<add key="PopPort" value="995" />
|
||||||
|
<add key="MailLogin" value="tempfortrip22@gmail.com" />
|
||||||
|
<add key="MailPassword" value="gbyb vdkr qeux xrol" />
|
||||||
|
</appSettings>
|
||||||
|
</configuration>
|
298
GiftShop/GiftShopView/FormCreateOrder.Designer.cs
generated
298
GiftShop/GiftShopView/FormCreateOrder.Designer.cs
generated
@ -1,145 +1,169 @@
|
|||||||
namespace GiftShopView
|
namespace GiftShopView
|
||||||
{
|
{
|
||||||
partial class FormCreateOrder
|
partial class FormCreateOrder
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Required designer variable.
|
/// Required designer variable.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private System.ComponentModel.IContainer components = null;
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Clean up any resources being used.
|
/// Clean up any resources being used.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
protected override void Dispose(bool disposing)
|
protected override void Dispose(bool disposing)
|
||||||
{
|
{
|
||||||
if (disposing && (components != null))
|
if (disposing && (components != null))
|
||||||
{
|
{
|
||||||
components.Dispose();
|
components.Dispose();
|
||||||
}
|
}
|
||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Windows Form Designer generated code
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Required method for Designer support - do not modify
|
/// Required method for Designer support - do not modify
|
||||||
/// the contents of this method with the code editor.
|
/// the contents of this method with the code editor.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
labelGift = new Label();
|
labelGift = new Label();
|
||||||
labelCount = new Label();
|
labelCount = new Label();
|
||||||
labelSum = new Label();
|
labelSum = new Label();
|
||||||
comboBoxGift = new ComboBox();
|
comboBoxGift = new ComboBox();
|
||||||
textBoxCount = new TextBox();
|
textBoxCount = new TextBox();
|
||||||
textBoxSum = new TextBox();
|
textBoxSum = new TextBox();
|
||||||
buttonSave = new Button();
|
buttonSave = new Button();
|
||||||
buttonCancel = new Button();
|
buttonCancel = new Button();
|
||||||
SuspendLayout();
|
labelClient = new Label();
|
||||||
//
|
comboBoxClient = new ComboBox();
|
||||||
// labelGift
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
labelGift.AutoSize = true;
|
// labelGift
|
||||||
labelGift.Location = new Point(34, 44);
|
//
|
||||||
labelGift.Name = "labelGift";
|
labelGift.AutoSize = true;
|
||||||
labelGift.Size = new Size(71, 20);
|
labelGift.Location = new Point(34, 44);
|
||||||
labelGift.TabIndex = 0;
|
labelGift.Name = "labelGift";
|
||||||
labelGift.Text = "Изделие:";
|
labelGift.Size = new Size(71, 20);
|
||||||
//
|
labelGift.TabIndex = 0;
|
||||||
// labelCount
|
labelGift.Text = "Изделие:";
|
||||||
//
|
//
|
||||||
labelCount.AutoSize = true;
|
// labelCount
|
||||||
labelCount.Location = new Point(34, 112);
|
//
|
||||||
labelCount.Name = "labelCount";
|
labelCount.AutoSize = true;
|
||||||
labelCount.Size = new Size(93, 20);
|
labelCount.Location = new Point(34, 138);
|
||||||
labelCount.TabIndex = 1;
|
labelCount.Name = "labelCount";
|
||||||
labelCount.Text = "Количество:";
|
labelCount.Size = new Size(93, 20);
|
||||||
//
|
labelCount.TabIndex = 1;
|
||||||
// labelSum
|
labelCount.Text = "Количество:";
|
||||||
//
|
//
|
||||||
labelSum.AutoSize = true;
|
// labelSum
|
||||||
labelSum.Location = new Point(34, 171);
|
//
|
||||||
labelSum.Name = "labelSum";
|
labelSum.AutoSize = true;
|
||||||
labelSum.Size = new Size(58, 20);
|
labelSum.Location = new Point(34, 187);
|
||||||
labelSum.TabIndex = 2;
|
labelSum.Name = "labelSum";
|
||||||
labelSum.Text = "Сумма:";
|
labelSum.Size = new Size(58, 20);
|
||||||
//
|
labelSum.TabIndex = 2;
|
||||||
// comboBoxGift
|
labelSum.Text = "Сумма:";
|
||||||
//
|
//
|
||||||
comboBoxGift.DropDownStyle = ComboBoxStyle.DropDownList;
|
// comboBoxGift
|
||||||
comboBoxGift.FormattingEnabled = true;
|
//
|
||||||
comboBoxGift.Location = new Point(141, 41);
|
comboBoxGift.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||||
comboBoxGift.Name = "comboBoxGift";
|
comboBoxGift.FormattingEnabled = true;
|
||||||
comboBoxGift.Size = new Size(369, 28);
|
comboBoxGift.Location = new Point(141, 41);
|
||||||
comboBoxGift.TabIndex = 3;
|
comboBoxGift.Name = "comboBoxGift";
|
||||||
comboBoxGift.SelectedIndexChanged += ComboBoxGift_SelectedIndexChanged;
|
comboBoxGift.Size = new Size(369, 28);
|
||||||
//
|
comboBoxGift.TabIndex = 3;
|
||||||
// textBoxCount
|
comboBoxGift.SelectedIndexChanged += ComboBoxGift_SelectedIndexChanged;
|
||||||
//
|
//
|
||||||
textBoxCount.Location = new Point(141, 109);
|
// textBoxCount
|
||||||
textBoxCount.Name = "textBoxCount";
|
//
|
||||||
textBoxCount.Size = new Size(369, 27);
|
textBoxCount.Location = new Point(141, 135);
|
||||||
textBoxCount.TabIndex = 4;
|
textBoxCount.Name = "textBoxCount";
|
||||||
textBoxCount.TextChanged += TextBoxCount_TextChanged;
|
textBoxCount.Size = new Size(369, 27);
|
||||||
//
|
textBoxCount.TabIndex = 4;
|
||||||
// textBoxSum
|
textBoxCount.TextChanged += TextBoxCount_TextChanged;
|
||||||
//
|
//
|
||||||
textBoxSum.Location = new Point(141, 171);
|
// textBoxSum
|
||||||
textBoxSum.Name = "textBoxSum";
|
//
|
||||||
textBoxSum.ReadOnly = true;
|
textBoxSum.Location = new Point(141, 187);
|
||||||
textBoxSum.Size = new Size(369, 27);
|
textBoxSum.Name = "textBoxSum";
|
||||||
textBoxSum.TabIndex = 5;
|
textBoxSum.ReadOnly = true;
|
||||||
//
|
textBoxSum.Size = new Size(369, 27);
|
||||||
// buttonSave
|
textBoxSum.TabIndex = 5;
|
||||||
//
|
//
|
||||||
buttonSave.Location = new Point(197, 245);
|
// buttonSave
|
||||||
buttonSave.Name = "buttonSave";
|
//
|
||||||
buttonSave.Size = new Size(144, 45);
|
buttonSave.Location = new Point(197, 245);
|
||||||
buttonSave.TabIndex = 6;
|
buttonSave.Name = "buttonSave";
|
||||||
buttonSave.Text = "Сохранить";
|
buttonSave.Size = new Size(144, 45);
|
||||||
buttonSave.UseVisualStyleBackColor = true;
|
buttonSave.TabIndex = 6;
|
||||||
buttonSave.Click += ButtonSave_Click;
|
buttonSave.Text = "Сохранить";
|
||||||
//
|
buttonSave.UseVisualStyleBackColor = true;
|
||||||
// buttonCancel
|
buttonSave.Click += ButtonSave_Click;
|
||||||
//
|
//
|
||||||
buttonCancel.Location = new Point(384, 245);
|
// buttonCancel
|
||||||
buttonCancel.Name = "buttonCancel";
|
//
|
||||||
buttonCancel.Size = new Size(126, 45);
|
buttonCancel.Location = new Point(384, 245);
|
||||||
buttonCancel.TabIndex = 7;
|
buttonCancel.Name = "buttonCancel";
|
||||||
buttonCancel.Text = "Отмена";
|
buttonCancel.Size = new Size(126, 45);
|
||||||
buttonCancel.UseVisualStyleBackColor = true;
|
buttonCancel.TabIndex = 7;
|
||||||
buttonCancel.Click += ButtonCancel_Click;
|
buttonCancel.Text = "Отмена";
|
||||||
//
|
buttonCancel.UseVisualStyleBackColor = true;
|
||||||
// FormCreateOrder
|
buttonCancel.Click += ButtonCancel_Click;
|
||||||
//
|
//
|
||||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
// labelClient
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
//
|
||||||
ClientSize = new Size(539, 308);
|
labelClient.AutoSize = true;
|
||||||
Controls.Add(buttonCancel);
|
labelClient.Location = new Point(34, 92);
|
||||||
Controls.Add(buttonSave);
|
labelClient.Name = "labelClient";
|
||||||
Controls.Add(textBoxSum);
|
labelClient.Size = new Size(61, 20);
|
||||||
Controls.Add(textBoxCount);
|
labelClient.TabIndex = 8;
|
||||||
Controls.Add(comboBoxGift);
|
labelClient.Text = "Клиент:";
|
||||||
Controls.Add(labelSum);
|
//
|
||||||
Controls.Add(labelCount);
|
// comboBoxClient
|
||||||
Controls.Add(labelGift);
|
//
|
||||||
Name = "FormCreateOrder";
|
comboBoxClient.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||||
Text = "Заказ";
|
comboBoxClient.FormattingEnabled = true;
|
||||||
Load += FormCreateOrder_Load;
|
comboBoxClient.Location = new Point(141, 89);
|
||||||
ResumeLayout(false);
|
comboBoxClient.Name = "comboBoxClient";
|
||||||
PerformLayout();
|
comboBoxClient.Size = new Size(369, 28);
|
||||||
}
|
comboBoxClient.TabIndex = 9;
|
||||||
|
//
|
||||||
|
// FormCreateOrder
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(539, 308);
|
||||||
|
Controls.Add(comboBoxClient);
|
||||||
|
Controls.Add(labelClient);
|
||||||
|
Controls.Add(buttonCancel);
|
||||||
|
Controls.Add(buttonSave);
|
||||||
|
Controls.Add(textBoxSum);
|
||||||
|
Controls.Add(textBoxCount);
|
||||||
|
Controls.Add(comboBoxGift);
|
||||||
|
Controls.Add(labelSum);
|
||||||
|
Controls.Add(labelCount);
|
||||||
|
Controls.Add(labelGift);
|
||||||
|
Name = "FormCreateOrder";
|
||||||
|
Text = "Заказ";
|
||||||
|
Load += FormCreateOrder_Load;
|
||||||
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private Label labelGift;
|
private Label labelGift;
|
||||||
private Label labelCount;
|
private Label labelCount;
|
||||||
private Label labelSum;
|
private Label labelSum;
|
||||||
private ComboBox comboBoxGift;
|
private ComboBox comboBoxGift;
|
||||||
private TextBox textBoxCount;
|
private TextBox textBoxCount;
|
||||||
private TextBox textBoxSum;
|
private TextBox textBoxSum;
|
||||||
private Button buttonSave;
|
private Button buttonSave;
|
||||||
private Button buttonCancel;
|
private Button buttonCancel;
|
||||||
}
|
private Label labelClient;
|
||||||
|
private ComboBox comboBoxClient;
|
||||||
|
}
|
||||||
}
|
}
|
@ -5,123 +5,145 @@ using Microsoft.Extensions.Logging;
|
|||||||
|
|
||||||
namespace GiftShopView
|
namespace GiftShopView
|
||||||
{
|
{
|
||||||
public partial class FormCreateOrder : Form
|
public partial class FormCreateOrder : Form
|
||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
private readonly IGiftLogic _logicP;
|
private readonly IGiftLogic _logicP;
|
||||||
|
|
||||||
private readonly IOrderLogic _logicO;
|
private readonly IOrderLogic _logicO;
|
||||||
|
|
||||||
public FormCreateOrder(ILogger<FormCreateOrder> logger, IGiftLogic logicP, IOrderLogic logicO)
|
private readonly IClientLogic _logicC;
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
_logger = logger;
|
|
||||||
_logicP = logicP;
|
|
||||||
_logicO = logicO;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void FormCreateOrder_Load(object sender, EventArgs e)
|
public FormCreateOrder(ILogger<FormCreateOrder> logger, IGiftLogic logicP, IOrderLogic logicO, IClientLogic logicC)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Загрузка изделий для заказа");
|
InitializeComponent();
|
||||||
LoadData();
|
_logger = logger;
|
||||||
}
|
_logicP = logicP;
|
||||||
|
_logicO = logicO;
|
||||||
|
_logicC = logicC;
|
||||||
|
}
|
||||||
|
|
||||||
private void LoadData()
|
private void FormCreateOrder_Load(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Загрузка изделий для заказа");
|
_logger.LogInformation("Загрузка изделий для заказа");
|
||||||
try
|
LoadData();
|
||||||
{
|
}
|
||||||
var list = _logicP.ReadList(null);
|
|
||||||
if (list != null)
|
|
||||||
{
|
|
||||||
comboBoxGift.DisplayMember = "GiftName";
|
|
||||||
comboBoxGift.ValueMember = "ID";
|
|
||||||
comboBoxGift.DataSource = list;
|
|
||||||
comboBoxGift.SelectedItem = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError(ex, "Ошибка загрузки списка изделий");
|
|
||||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void CalcSum()
|
private void LoadData()
|
||||||
{
|
{
|
||||||
if (comboBoxGift.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text))
|
_logger.LogInformation("Загрузка изделий для заказа");
|
||||||
{
|
try
|
||||||
try
|
{
|
||||||
{
|
var list = _logicP.ReadList(null);
|
||||||
int id = Convert.ToInt32(comboBoxGift.SelectedValue);
|
if (list != null)
|
||||||
var product = _logicP.ReadElement(new GiftSearchModel
|
{
|
||||||
{
|
comboBoxGift.DisplayMember = "GiftName";
|
||||||
Id = id
|
comboBoxGift.ValueMember = "ID";
|
||||||
});
|
comboBoxGift.DataSource = list;
|
||||||
int count = Convert.ToInt32(textBoxCount.Text);
|
comboBoxGift.SelectedItem = null;
|
||||||
textBoxSum.Text = Math.Round(count * (product?.Price ?? 0), 2).ToString();
|
}
|
||||||
_logger.LogInformation("Расчет суммы заказа");
|
}
|
||||||
}
|
catch (Exception ex)
|
||||||
catch (Exception ex)
|
{
|
||||||
{
|
_logger.LogError(ex, "Ошибка загрузки списка изделий");
|
||||||
_logger.LogError(ex, "Ошибка расчета суммы заказа");
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
}
|
||||||
}
|
_logger.LogInformation("Загрузка клиентов для заказа");
|
||||||
}
|
try
|
||||||
}
|
{
|
||||||
|
var list = _logicC.ReadList(null);
|
||||||
|
if (list != null)
|
||||||
|
{
|
||||||
|
comboBoxClient.DisplayMember = "Клиент";
|
||||||
|
comboBoxClient.ValueMember = "Id";
|
||||||
|
comboBoxClient.DataSource = list.Select(c => c.ClientFIO).ToList();
|
||||||
|
comboBoxClient.SelectedItem = null;
|
||||||
|
}
|
||||||
|
|
||||||
private void TextBoxCount_TextChanged(object sender, EventArgs e)
|
}
|
||||||
{
|
catch (Exception ex)
|
||||||
CalcSum();
|
{
|
||||||
}
|
_logger.LogError(ex, "Ошибка загрузки списка клиентов");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void ComboBoxGift_SelectedIndexChanged(object sender, EventArgs e)
|
private void CalcSum()
|
||||||
{
|
{
|
||||||
CalcSum();
|
if (comboBoxGift.SelectedValue != null && !string.IsNullOrEmpty(textBoxCount.Text))
|
||||||
}
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
int id = Convert.ToInt32(comboBoxGift.SelectedValue);
|
||||||
|
var product = _logicP.ReadElement(new GiftSearchModel
|
||||||
|
{
|
||||||
|
Id = id
|
||||||
|
});
|
||||||
|
int count = Convert.ToInt32(textBoxCount.Text);
|
||||||
|
textBoxSum.Text = Math.Round(count * (product?.Price ?? 0), 2).ToString();
|
||||||
|
_logger.LogInformation("Расчет суммы заказа");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка расчета суммы заказа");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void ButtonSave_Click(object sender, EventArgs e)
|
private void TextBoxCount_TextChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(textBoxCount.Text))
|
CalcSum();
|
||||||
{
|
}
|
||||||
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (comboBoxGift.SelectedValue == null)
|
|
||||||
{
|
|
||||||
MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
_logger.LogInformation("Создание заказа");
|
|
||||||
try
|
|
||||||
{
|
|
||||||
var operationResult = _logicO.CreateOrder(new OrderBindingModel
|
|
||||||
{
|
|
||||||
GiftId = Convert.ToInt32(comboBoxGift.SelectedValue),
|
|
||||||
GiftName = comboBoxGift.Text,
|
|
||||||
Count = Convert.ToInt32(textBoxCount.Text),
|
|
||||||
Sum = Convert.ToDouble(textBoxSum.Text)
|
|
||||||
});
|
|
||||||
if (!operationResult)
|
|
||||||
{
|
|
||||||
throw new Exception("Ошибка при создании заказа. Дополнительная информация в логах.");
|
|
||||||
}
|
|
||||||
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
|
||||||
DialogResult = DialogResult.OK;
|
|
||||||
Close();
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_logger.LogError(ex, "Ошибка создания заказа");
|
|
||||||
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ButtonCancel_Click(object sender, EventArgs e)
|
private void ComboBoxGift_SelectedIndexChanged(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
DialogResult = DialogResult.Cancel;
|
CalcSum();
|
||||||
Close();
|
}
|
||||||
}
|
|
||||||
}
|
private void ButtonSave_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(textBoxCount.Text))
|
||||||
|
{
|
||||||
|
MessageBox.Show("Заполните поле Количество", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (comboBoxGift.SelectedValue == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Выберите изделие", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Создание заказа");
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var operationResult = _logicO.CreateOrder(new OrderBindingModel
|
||||||
|
{
|
||||||
|
GiftId = Convert.ToInt32(comboBoxGift.SelectedValue),
|
||||||
|
GiftName = comboBoxGift.Text,
|
||||||
|
ClientId = Convert.ToInt32(comboBoxClient.SelectedIndex),
|
||||||
|
Count = Convert.ToInt32(textBoxCount.Text),
|
||||||
|
Sum = Convert.ToDouble(textBoxSum.Text)
|
||||||
|
});
|
||||||
|
if (!operationResult)
|
||||||
|
{
|
||||||
|
throw new Exception("Ошибка при создании заказа. Дополнительная информация в логах.");
|
||||||
|
}
|
||||||
|
MessageBox.Show("Сохранение прошло успешно", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка создания заказа");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ButtonCancel_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
DialogResult = DialogResult.Cancel;
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
64
GiftShop/GiftShopView/FormMails.Designer.cs
generated
Normal file
64
GiftShop/GiftShopView/FormMails.Designer.cs
generated
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
namespace GiftShopView
|
||||||
|
{
|
||||||
|
partial class FormMails
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Required designer variable.
|
||||||
|
/// </summary>
|
||||||
|
private System.ComponentModel.IContainer components = null;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Clean up any resources being used.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||||
|
protected override void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (disposing && (components != null))
|
||||||
|
{
|
||||||
|
components.Dispose();
|
||||||
|
}
|
||||||
|
base.Dispose(disposing);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Required method for Designer support - do not modify
|
||||||
|
/// the contents of this method with the code editor.
|
||||||
|
/// </summary>
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
dataGridView = new DataGridView();
|
||||||
|
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||||
|
SuspendLayout();
|
||||||
|
//
|
||||||
|
// dataGridView
|
||||||
|
//
|
||||||
|
dataGridView.BackgroundColor = SystemColors.ControlLightLight;
|
||||||
|
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
|
dataGridView.Dock = DockStyle.Fill;
|
||||||
|
dataGridView.Location = new Point(0, 0);
|
||||||
|
dataGridView.Name = "dataGridView";
|
||||||
|
dataGridView.RowHeadersWidth = 51;
|
||||||
|
dataGridView.RowTemplate.Height = 29;
|
||||||
|
dataGridView.Size = new Size(800, 450);
|
||||||
|
dataGridView.TabIndex = 0;
|
||||||
|
//
|
||||||
|
// FormMails
|
||||||
|
//
|
||||||
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
|
ClientSize = new Size(800, 450);
|
||||||
|
Controls.Add(dataGridView);
|
||||||
|
Name = "FormMails";
|
||||||
|
Text = "Письма";
|
||||||
|
Load += FormMails_Load;
|
||||||
|
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||||
|
ResumeLayout(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
private DataGridView dataGridView;
|
||||||
|
}
|
||||||
|
}
|
46
GiftShop/GiftShopView/FormMails.cs
Normal file
46
GiftShop/GiftShopView/FormMails.cs
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
using GiftShopContracts.BusinessLogicsContracts;
|
||||||
|
|
||||||
|
namespace GiftShopView
|
||||||
|
{
|
||||||
|
public partial class FormMails : Form
|
||||||
|
{
|
||||||
|
private readonly ILogger _logger;
|
||||||
|
private readonly IMessageInfoLogic _logic;
|
||||||
|
|
||||||
|
public FormMails(ILogger<FormMails> logger, IMessageInfoLogic logic)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
_logger = logger;
|
||||||
|
_logic = logic;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadData()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var list = _logic.ReadList(null);
|
||||||
|
if (list != null)
|
||||||
|
{
|
||||||
|
dataGridView.DataSource = list;
|
||||||
|
dataGridView.Columns["ClientId"].Visible = false;
|
||||||
|
dataGridView.Columns["MessageId"].Visible = false;
|
||||||
|
dataGridView.Columns["Body"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
|
||||||
|
}
|
||||||
|
_logger.LogInformation("Загрузка писем");
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка загрузки писем");
|
||||||
|
MessageBox.Show(ex.Message, "Ошибка", MessageBoxButtons.OK,
|
||||||
|
MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void FormMails_Load(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
LoadData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
60
GiftShop/GiftShopView/FormMails.resx
Normal file
60
GiftShop/GiftShopView/FormMails.resx
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<root>
|
||||||
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:choice maxOccurs="unbounded">
|
||||||
|
<xsd:element name="metadata">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="assembly">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:attribute name="alias" type="xsd:string" />
|
||||||
|
<xsd:attribute name="name" type="xsd:string" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="data">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||||
|
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||||
|
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||||
|
<xsd:attribute ref="xml:space" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
<xsd:element name="resheader">
|
||||||
|
<xsd:complexType>
|
||||||
|
<xsd:sequence>
|
||||||
|
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||||
|
</xsd:sequence>
|
||||||
|
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:choice>
|
||||||
|
</xsd:complexType>
|
||||||
|
</xsd:element>
|
||||||
|
</xsd:schema>
|
||||||
|
<resheader name="resmimetype">
|
||||||
|
<value>text/microsoft-resx</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="version">
|
||||||
|
<value>2.0</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="reader">
|
||||||
|
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
<resheader name="writer">
|
||||||
|
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||||
|
</resheader>
|
||||||
|
</root>
|
353
GiftShop/GiftShopView/FormMain.Designer.cs
generated
353
GiftShop/GiftShopView/FormMain.Designer.cs
generated
@ -20,184 +20,186 @@
|
|||||||
base.Dispose(disposing);
|
base.Dispose(disposing);
|
||||||
}
|
}
|
||||||
|
|
||||||
#region Windows Form Designer generated code
|
#region Windows Form Designer generated code
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Required method for Designer support - do not modify
|
/// Required method for Designer support - do not modify
|
||||||
/// the contents of this method with the code editor.
|
/// the contents of this method with the code editor.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
menuStrip = new MenuStrip();
|
menuStrip = new MenuStrip();
|
||||||
справочникиToolStripMenuItem = new ToolStripMenuItem();
|
справочникиToolStripMenuItem = new ToolStripMenuItem();
|
||||||
компонентыToolStripMenuItem = new ToolStripMenuItem();
|
компонентыToolStripMenuItem = new ToolStripMenuItem();
|
||||||
изделияToolStripMenuItem = new ToolStripMenuItem();
|
изделияToolStripMenuItem = new ToolStripMenuItem();
|
||||||
клиентыToolStripMenuItem = new ToolStripMenuItem();
|
клиентыToolStripMenuItem = new ToolStripMenuItem();
|
||||||
исполнителиToolStripMenuItem = new ToolStripMenuItem();
|
исполнителиToolStripMenuItem = new ToolStripMenuItem();
|
||||||
отчётыToolStripMenuItem = new ToolStripMenuItem();
|
отчётыToolStripMenuItem = new ToolStripMenuItem();
|
||||||
списокКомпонентовToolStripMenuItem = new ToolStripMenuItem();
|
списокКомпонентовToolStripMenuItem = new ToolStripMenuItem();
|
||||||
компонентыПоИзделиямToolStripMenuItem = new ToolStripMenuItem();
|
компонентыПоИзделиямToolStripMenuItem = new ToolStripMenuItem();
|
||||||
списокЗаказовToolStripMenuItem = new ToolStripMenuItem();
|
списокЗаказовToolStripMenuItem = new ToolStripMenuItem();
|
||||||
запускРаботToolStripMenuItem = new ToolStripMenuItem();
|
запускРаботToolStripMenuItem = new ToolStripMenuItem();
|
||||||
dataGridView = new DataGridView();
|
dataGridView = new DataGridView();
|
||||||
buttonCreateOrder = new Button();
|
buttonCreateOrder = new Button();
|
||||||
buttonIssuedOrder = new Button();
|
buttonIssuedOrder = new Button();
|
||||||
buttonRef = new Button();
|
buttonRef = new Button();
|
||||||
menuStrip.SuspendLayout();
|
письмаToolStripMenuItem = new ToolStripMenuItem();
|
||||||
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
menuStrip.SuspendLayout();
|
||||||
SuspendLayout();
|
((System.ComponentModel.ISupportInitialize)dataGridView).BeginInit();
|
||||||
//
|
SuspendLayout();
|
||||||
// menuStrip
|
//
|
||||||
//
|
// menuStrip
|
||||||
menuStrip.ImageScalingSize = new Size(20, 20);
|
//
|
||||||
menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчётыToolStripMenuItem, запускРаботToolStripMenuItem });
|
menuStrip.ImageScalingSize = new Size(20, 20);
|
||||||
menuStrip.Location = new Point(0, 0);
|
menuStrip.Items.AddRange(new ToolStripItem[] { справочникиToolStripMenuItem, отчётыToolStripMenuItem, запускРаботToolStripMenuItem, письмаToolStripMenuItem });
|
||||||
menuStrip.Name = "menuStrip";
|
menuStrip.Location = new Point(0, 0);
|
||||||
menuStrip.Padding = new Padding(8, 2, 0, 2);
|
menuStrip.Name = "menuStrip";
|
||||||
menuStrip.Size = new Size(1709, 33);
|
menuStrip.Size = new Size(1367, 28);
|
||||||
menuStrip.TabIndex = 0;
|
menuStrip.TabIndex = 0;
|
||||||
menuStrip.Text = "menuStrip1";
|
menuStrip.Text = "menuStrip1";
|
||||||
//
|
//
|
||||||
// справочникиToolStripMenuItem
|
// справочникиToolStripMenuItem
|
||||||
//
|
//
|
||||||
справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, изделияToolStripMenuItem, клиентыToolStripMenuItem, исполнителиToolStripMenuItem });
|
справочникиToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { компонентыToolStripMenuItem, изделияToolStripMenuItem, клиентыToolStripMenuItem, исполнителиToolStripMenuItem });
|
||||||
справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
|
справочникиToolStripMenuItem.Name = "справочникиToolStripMenuItem";
|
||||||
справочникиToolStripMenuItem.Size = new Size(139, 29);
|
справочникиToolStripMenuItem.Size = new Size(117, 24);
|
||||||
справочникиToolStripMenuItem.Text = "Справочники";
|
справочникиToolStripMenuItem.Text = "Справочники";
|
||||||
//
|
//
|
||||||
// компонентыToolStripMenuItem
|
// компонентыToolStripMenuItem
|
||||||
//
|
//
|
||||||
компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem";
|
компонентыToolStripMenuItem.Name = "компонентыToolStripMenuItem";
|
||||||
компонентыToolStripMenuItem.Size = new Size(220, 34);
|
компонентыToolStripMenuItem.Size = new Size(185, 26);
|
||||||
компонентыToolStripMenuItem.Text = "Компоненты";
|
компонентыToolStripMenuItem.Text = "Компоненты";
|
||||||
компонентыToolStripMenuItem.Click += КомпонентыToolStripMenuItem_Click;
|
компонентыToolStripMenuItem.Click += КомпонентыToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
// изделияToolStripMenuItem
|
// изделияToolStripMenuItem
|
||||||
//
|
//
|
||||||
изделияToolStripMenuItem.Name = "изделияToolStripMenuItem";
|
изделияToolStripMenuItem.Name = "изделияToolStripMenuItem";
|
||||||
изделияToolStripMenuItem.Size = new Size(220, 34);
|
изделияToolStripMenuItem.Size = new Size(185, 26);
|
||||||
изделияToolStripMenuItem.Text = "Изделия";
|
изделияToolStripMenuItem.Text = "Изделия";
|
||||||
изделияToolStripMenuItem.Click += ИзделияToolStripMenuItem_Click;
|
изделияToolStripMenuItem.Click += ИзделияToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
// клиентыToolStripMenuItem
|
// клиентыToolStripMenuItem
|
||||||
//
|
//
|
||||||
клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem";
|
клиентыToolStripMenuItem.Name = "клиентыToolStripMenuItem";
|
||||||
клиентыToolStripMenuItem.Size = new Size(220, 34);
|
клиентыToolStripMenuItem.Size = new Size(185, 26);
|
||||||
клиентыToolStripMenuItem.Text = "Клиенты";
|
клиентыToolStripMenuItem.Text = "Клиенты";
|
||||||
клиентыToolStripMenuItem.Click += ClientsToolStripMenuItem_Click;
|
клиентыToolStripMenuItem.Click += ClientsToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
// исполнителиToolStripMenuItem
|
// исполнителиToolStripMenuItem
|
||||||
//
|
//
|
||||||
исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem";
|
исполнителиToolStripMenuItem.Name = "исполнителиToolStripMenuItem";
|
||||||
исполнителиToolStripMenuItem.Size = new Size(220, 34);
|
исполнителиToolStripMenuItem.Size = new Size(185, 26);
|
||||||
исполнителиToolStripMenuItem.Text = "Исполнители";
|
исполнителиToolStripMenuItem.Text = "Исполнители";
|
||||||
исполнителиToolStripMenuItem.Click += исполнителиToolStripMenuItem_Click;
|
исполнителиToolStripMenuItem.Click += исполнителиToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
// отчётыToolStripMenuItem
|
// отчётыToolStripMenuItem
|
||||||
//
|
//
|
||||||
отчётыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { списокКомпонентовToolStripMenuItem, компонентыПоИзделиямToolStripMenuItem, списокЗаказовToolStripMenuItem });
|
отчётыToolStripMenuItem.DropDownItems.AddRange(new ToolStripItem[] { списокКомпонентовToolStripMenuItem, компонентыПоИзделиямToolStripMenuItem, списокЗаказовToolStripMenuItem });
|
||||||
отчётыToolStripMenuItem.Name = "отчётыToolStripMenuItem";
|
отчётыToolStripMenuItem.Name = "отчётыToolStripMenuItem";
|
||||||
отчётыToolStripMenuItem.Size = new Size(88, 29);
|
отчётыToolStripMenuItem.Size = new Size(73, 24);
|
||||||
отчётыToolStripMenuItem.Text = "Отчёты";
|
отчётыToolStripMenuItem.Text = "Отчёты";
|
||||||
//
|
//
|
||||||
// списокКомпонентовToolStripMenuItem
|
// списокКомпонентовToolStripMenuItem
|
||||||
//
|
//
|
||||||
списокКомпонентовToolStripMenuItem.Name = "списокКомпонентовToolStripMenuItem";
|
списокКомпонентовToolStripMenuItem.Name = "списокКомпонентовToolStripMenuItem";
|
||||||
списокКомпонентовToolStripMenuItem.Size = new Size(327, 34);
|
списокКомпонентовToolStripMenuItem.Size = new Size(276, 26);
|
||||||
списокКомпонентовToolStripMenuItem.Text = "Список компонентов";
|
списокКомпонентовToolStripMenuItem.Text = "Список компонентов";
|
||||||
списокКомпонентовToolStripMenuItem.Click += ComponentsToolStripMenuItem_Click;
|
списокКомпонентовToolStripMenuItem.Click += ComponentsToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
// компонентыПоИзделиямToolStripMenuItem
|
// компонентыПоИзделиямToolStripMenuItem
|
||||||
//
|
//
|
||||||
компонентыПоИзделиямToolStripMenuItem.Name = "компонентыПоИзделиямToolStripMenuItem";
|
компонентыПоИзделиямToolStripMenuItem.Name = "компонентыПоИзделиямToolStripMenuItem";
|
||||||
компонентыПоИзделиямToolStripMenuItem.Size = new Size(327, 34);
|
компонентыПоИзделиямToolStripMenuItem.Size = new Size(276, 26);
|
||||||
компонентыПоИзделиямToolStripMenuItem.Text = "Компоненты по изделиям";
|
компонентыПоИзделиямToolStripMenuItem.Text = "Компоненты по изделиям";
|
||||||
компонентыПоИзделиямToolStripMenuItem.Click += ComponentGiftsToolStripMenuItem_Click;
|
компонентыПоИзделиямToolStripMenuItem.Click += ComponentGiftsToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
// списокЗаказовToolStripMenuItem
|
// списокЗаказовToolStripMenuItem
|
||||||
//
|
//
|
||||||
списокЗаказовToolStripMenuItem.Name = "списокЗаказовToolStripMenuItem";
|
списокЗаказовToolStripMenuItem.Name = "списокЗаказовToolStripMenuItem";
|
||||||
списокЗаказовToolStripMenuItem.Size = new Size(327, 34);
|
списокЗаказовToolStripMenuItem.Size = new Size(276, 26);
|
||||||
списокЗаказовToolStripMenuItem.Text = "Список заказов";
|
списокЗаказовToolStripMenuItem.Text = "Список заказов";
|
||||||
списокЗаказовToolStripMenuItem.Click += OrdersToolStripMenuItem_Click;
|
списокЗаказовToolStripMenuItem.Click += OrdersToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
// запускРаботToolStripMenuItem
|
// запускРаботToolStripMenuItem
|
||||||
//
|
//
|
||||||
запускРаботToolStripMenuItem.Name = "запускРаботToolStripMenuItem";
|
запускРаботToolStripMenuItem.Name = "запускРаботToolStripMenuItem";
|
||||||
запускРаботToolStripMenuItem.Size = new Size(136, 29);
|
запускРаботToolStripMenuItem.Size = new Size(114, 24);
|
||||||
запускРаботToolStripMenuItem.Text = "Запуск работ";
|
запускРаботToolStripMenuItem.Text = "Запуск работ";
|
||||||
запускРаботToolStripMenuItem.Click += запускРаботToolStripMenuItem_Click;
|
запускРаботToolStripMenuItem.Click += запускРаботToolStripMenuItem_Click;
|
||||||
//
|
//
|
||||||
// dataGridView
|
// dataGridView
|
||||||
//
|
//
|
||||||
dataGridView.BackgroundColor = SystemColors.ControlLightLight;
|
dataGridView.BackgroundColor = SystemColors.ControlLightLight;
|
||||||
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
dataGridView.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
|
||||||
dataGridView.Location = new Point(15, 51);
|
dataGridView.Location = new Point(12, 41);
|
||||||
dataGridView.Margin = new Padding(4, 4, 4, 4);
|
dataGridView.Name = "dataGridView";
|
||||||
dataGridView.Name = "dataGridView";
|
dataGridView.RowHeadersWidth = 51;
|
||||||
dataGridView.RowHeadersWidth = 51;
|
dataGridView.RowTemplate.Height = 29;
|
||||||
dataGridView.RowTemplate.Height = 29;
|
dataGridView.Size = new Size(1123, 423);
|
||||||
dataGridView.Size = new Size(1404, 529);
|
dataGridView.TabIndex = 1;
|
||||||
dataGridView.TabIndex = 1;
|
//
|
||||||
//
|
// buttonCreateOrder
|
||||||
// buttonCreateOrder
|
//
|
||||||
//
|
buttonCreateOrder.Location = new Point(1155, 90);
|
||||||
buttonCreateOrder.Location = new Point(1444, 112);
|
buttonCreateOrder.Name = "buttonCreateOrder";
|
||||||
buttonCreateOrder.Margin = new Padding(4, 4, 4, 4);
|
buttonCreateOrder.Size = new Size(189, 57);
|
||||||
buttonCreateOrder.Name = "buttonCreateOrder";
|
buttonCreateOrder.TabIndex = 2;
|
||||||
buttonCreateOrder.Size = new Size(236, 71);
|
buttonCreateOrder.Text = "Создать заказ";
|
||||||
buttonCreateOrder.TabIndex = 2;
|
buttonCreateOrder.UseVisualStyleBackColor = true;
|
||||||
buttonCreateOrder.Text = "Создать заказ";
|
buttonCreateOrder.Click += ButtonCreateOrder_Click;
|
||||||
buttonCreateOrder.UseVisualStyleBackColor = true;
|
//
|
||||||
buttonCreateOrder.Click += ButtonCreateOrder_Click;
|
// buttonIssuedOrder
|
||||||
//
|
//
|
||||||
// buttonIssuedOrder
|
buttonIssuedOrder.Location = new Point(1155, 228);
|
||||||
//
|
buttonIssuedOrder.Name = "buttonIssuedOrder";
|
||||||
buttonIssuedOrder.Location = new Point(1444, 285);
|
buttonIssuedOrder.Size = new Size(189, 57);
|
||||||
buttonIssuedOrder.Margin = new Padding(4, 4, 4, 4);
|
buttonIssuedOrder.TabIndex = 5;
|
||||||
buttonIssuedOrder.Name = "buttonIssuedOrder";
|
buttonIssuedOrder.Text = "Заказ выдан";
|
||||||
buttonIssuedOrder.Size = new Size(236, 71);
|
buttonIssuedOrder.UseVisualStyleBackColor = true;
|
||||||
buttonIssuedOrder.TabIndex = 5;
|
buttonIssuedOrder.Click += ButtonIssuedOrder_Click;
|
||||||
buttonIssuedOrder.Text = "Заказ выдан";
|
//
|
||||||
buttonIssuedOrder.UseVisualStyleBackColor = true;
|
// buttonRef
|
||||||
buttonIssuedOrder.Click += ButtonIssuedOrder_Click;
|
//
|
||||||
//
|
buttonRef.Location = new Point(1155, 356);
|
||||||
// buttonRef
|
buttonRef.Name = "buttonRef";
|
||||||
//
|
buttonRef.Size = new Size(189, 57);
|
||||||
buttonRef.Location = new Point(1444, 445);
|
buttonRef.TabIndex = 6;
|
||||||
buttonRef.Margin = new Padding(4, 4, 4, 4);
|
buttonRef.Text = "Обновить список";
|
||||||
buttonRef.Name = "buttonRef";
|
buttonRef.UseVisualStyleBackColor = true;
|
||||||
buttonRef.Size = new Size(236, 71);
|
buttonRef.Click += ButtonRef_Click;
|
||||||
buttonRef.TabIndex = 6;
|
//
|
||||||
buttonRef.Text = "Обновить список";
|
// письмаToolStripMenuItem
|
||||||
buttonRef.UseVisualStyleBackColor = true;
|
//
|
||||||
buttonRef.Click += ButtonRef_Click;
|
письмаToolStripMenuItem.Name = "письмаToolStripMenuItem";
|
||||||
//
|
письмаToolStripMenuItem.Size = new Size(77, 24);
|
||||||
// FormMain
|
письмаToolStripMenuItem.Text = "Письма";
|
||||||
//
|
письмаToolStripMenuItem.Click += письмаToolStripMenuItem_Click;
|
||||||
AutoScaleDimensions = new SizeF(10F, 25F);
|
//
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
// FormMain
|
||||||
ClientSize = new Size(1709, 589);
|
//
|
||||||
Controls.Add(buttonRef);
|
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||||
Controls.Add(buttonIssuedOrder);
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
Controls.Add(buttonCreateOrder);
|
ClientSize = new Size(1367, 471);
|
||||||
Controls.Add(dataGridView);
|
Controls.Add(buttonRef);
|
||||||
Controls.Add(menuStrip);
|
Controls.Add(buttonIssuedOrder);
|
||||||
MainMenuStrip = menuStrip;
|
Controls.Add(buttonCreateOrder);
|
||||||
Margin = new Padding(4, 4, 4, 4);
|
Controls.Add(dataGridView);
|
||||||
Name = "FormMain";
|
Controls.Add(menuStrip);
|
||||||
Text = "Магазин подарков";
|
MainMenuStrip = menuStrip;
|
||||||
Load += FormMain_Load;
|
Name = "FormMain";
|
||||||
menuStrip.ResumeLayout(false);
|
Text = "Магазин подарков";
|
||||||
menuStrip.PerformLayout();
|
Load += FormMain_Load;
|
||||||
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
menuStrip.ResumeLayout(false);
|
||||||
ResumeLayout(false);
|
menuStrip.PerformLayout();
|
||||||
PerformLayout();
|
((System.ComponentModel.ISupportInitialize)dataGridView).EndInit();
|
||||||
}
|
ResumeLayout(false);
|
||||||
|
PerformLayout();
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
private MenuStrip menuStrip;
|
private MenuStrip menuStrip;
|
||||||
private ToolStripMenuItem справочникиToolStripMenuItem;
|
private ToolStripMenuItem справочникиToolStripMenuItem;
|
||||||
private ToolStripMenuItem компонентыToolStripMenuItem;
|
private ToolStripMenuItem компонентыToolStripMenuItem;
|
||||||
private ToolStripMenuItem изделияToolStripMenuItem;
|
private ToolStripMenuItem изделияToolStripMenuItem;
|
||||||
@ -212,5 +214,6 @@
|
|||||||
private ToolStripMenuItem клиентыToolStripMenuItem;
|
private ToolStripMenuItem клиентыToolStripMenuItem;
|
||||||
private ToolStripMenuItem исполнителиToolStripMenuItem;
|
private ToolStripMenuItem исполнителиToolStripMenuItem;
|
||||||
private ToolStripMenuItem запускРаботToolStripMenuItem;
|
private ToolStripMenuItem запускРаботToolStripMenuItem;
|
||||||
|
private ToolStripMenuItem письмаToolStripMenuItem;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -177,5 +177,14 @@ namespace GiftShopView
|
|||||||
.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic);
|
.GetService(typeof(IImplementerLogic)) as IImplementerLogic)!, _orderLogic);
|
||||||
MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
MessageBox.Show("Процесс обработки запущен", "Сообщение", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void письмаToolStripMenuItem_Click(object sender, EventArgs e)
|
||||||
|
{
|
||||||
|
var service = Program.ServiceProvider?.GetService(typeof(FormMails));
|
||||||
|
if (service is FormMails form)
|
||||||
|
{
|
||||||
|
form.ShowDialog();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,64 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<root>
|
||||||
<root>
|
|
||||||
<!--
|
|
||||||
Microsoft ResX Schema
|
|
||||||
|
|
||||||
Version 2.0
|
|
||||||
|
|
||||||
The primary goals of this format is to allow a simple XML format
|
|
||||||
that is mostly human readable. The generation and parsing of the
|
|
||||||
various data types are done through the TypeConverter classes
|
|
||||||
associated with the data types.
|
|
||||||
|
|
||||||
Example:
|
|
||||||
|
|
||||||
... ado.net/XML headers & schema ...
|
|
||||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
|
||||||
<resheader name="version">2.0</resheader>
|
|
||||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
|
||||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
|
||||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
|
||||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
|
||||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
|
||||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
|
||||||
</data>
|
|
||||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
|
||||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
|
||||||
<comment>This is a comment</comment>
|
|
||||||
</data>
|
|
||||||
|
|
||||||
There are any number of "resheader" rows that contain simple
|
|
||||||
name/value pairs.
|
|
||||||
|
|
||||||
Each data row contains a name, and value. The row also contains a
|
|
||||||
type or mimetype. Type corresponds to a .NET class that support
|
|
||||||
text/value conversion through the TypeConverter architecture.
|
|
||||||
Classes that don't support this are serialized and stored with the
|
|
||||||
mimetype set.
|
|
||||||
|
|
||||||
The mimetype is used for serialized objects, and tells the
|
|
||||||
ResXResourceReader how to depersist the object. This is currently not
|
|
||||||
extensible. For a given mimetype the value must be set accordingly:
|
|
||||||
|
|
||||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
|
||||||
that the ResXResourceWriter will generate, however the reader can
|
|
||||||
read any of the formats listed below.
|
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.binary.base64
|
|
||||||
value : The object must be serialized with
|
|
||||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
|
||||||
: and then encoded with base64 encoding.
|
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.soap.base64
|
|
||||||
value : The object must be serialized with
|
|
||||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
|
||||||
: and then encoded with base64 encoding.
|
|
||||||
|
|
||||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
|
||||||
value : The object must be serialized into a byte array
|
|
||||||
: using a System.ComponentModel.TypeConverter
|
|
||||||
: and then encoded with base64 encoding.
|
|
||||||
-->
|
|
||||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||||
<xsd:element name="root" msdata:IsDataSet="true">
|
<xsd:element name="root" msdata:IsDataSet="true">
|
||||||
@ -121,6 +61,6 @@
|
|||||||
<value>17, 17</value>
|
<value>17, 17</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
<metadata name="$this.TrayHeight" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||||
<value>137</value>
|
<value>26</value>
|
||||||
</metadata>
|
</metadata>
|
||||||
</root>
|
</root>
|
@ -19,6 +19,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="MailKit" Version="4.5.0" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.4">
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.4">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
@ -39,6 +40,9 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<None Update="App.config">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</None>
|
||||||
<None Update="ReportOrders.rdlc">
|
<None Update="ReportOrders.rdlc">
|
||||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
</None>
|
</None>
|
||||||
|
@ -7,6 +7,8 @@ using GiftShopDatabaseImplement.Implements;
|
|||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using NLog.Extensions.Logging;
|
using NLog.Extensions.Logging;
|
||||||
|
using GiftShopBusinessLogic.MailWorker;
|
||||||
|
using GiftShopContracts.BindingModels;
|
||||||
|
|
||||||
namespace GiftShopView
|
namespace GiftShopView
|
||||||
{
|
{
|
||||||
@ -21,7 +23,27 @@ namespace GiftShopView
|
|||||||
var services = new ServiceCollection();
|
var services = new ServiceCollection();
|
||||||
ConfigureServices(services);
|
ConfigureServices(services);
|
||||||
_serviceProvider = services.BuildServiceProvider();
|
_serviceProvider = services.BuildServiceProvider();
|
||||||
Application.Run(_serviceProvider.GetRequiredService<FormMain>());
|
try
|
||||||
|
{
|
||||||
|
var mailSender = _serviceProvider.GetService<AbstractMailWorker>();
|
||||||
|
mailSender?.MailConfig(new MailConfigBindingModel
|
||||||
|
{
|
||||||
|
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["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);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
var logger = _serviceProvider.GetService<ILogger>();
|
||||||
|
logger?.LogError(ex, "Îøèáêà ðàáîòû ñ ïî÷òîé");
|
||||||
|
}
|
||||||
|
Application.Run(_serviceProvider.GetRequiredService<FormMain>());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ConfigureServices(ServiceCollection services)
|
private static void ConfigureServices(ServiceCollection services)
|
||||||
@ -35,19 +57,24 @@ namespace GiftShopView
|
|||||||
services.AddTransient<IOrderStorage, OrderStorage>();
|
services.AddTransient<IOrderStorage, OrderStorage>();
|
||||||
services.AddTransient<IGiftStorage, GiftStorage>();
|
services.AddTransient<IGiftStorage, GiftStorage>();
|
||||||
services.AddTransient<IClientStorage, ClientStorage>();
|
services.AddTransient<IClientStorage, ClientStorage>();
|
||||||
services.AddTransient<IImplementerStorage, ImplementerStorage>();
|
services.AddTransient<IImplementerStorage, ImplementerStorage>();
|
||||||
services.AddTransient<IClientLogic, ClientLogic>();
|
services.AddTransient<IMessageInfoStorage, MessageInfoStorage>();
|
||||||
|
|
||||||
|
services.AddTransient<IClientLogic, ClientLogic>();
|
||||||
services.AddTransient<IComponentLogic, ComponentLogic>();
|
services.AddTransient<IComponentLogic, ComponentLogic>();
|
||||||
services.AddTransient<IOrderLogic, OrderLogic>();
|
services.AddTransient<IOrderLogic, OrderLogic>();
|
||||||
services.AddTransient<IGiftLogic, GiftLogic>();
|
services.AddTransient<IGiftLogic, GiftLogic>();
|
||||||
services.AddTransient<IReportLogic, ReportLogic>();
|
services.AddTransient<IReportLogic, ReportLogic>();
|
||||||
services.AddTransient<IImplementerLogic, ImplementerLogic>();
|
services.AddTransient<IImplementerLogic, ImplementerLogic>();
|
||||||
services.AddTransient<IWorkProcess, WorkModeling>();
|
services.AddTransient<IMessageInfoLogic, MessageInfoLogic>();
|
||||||
services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
|
services.AddTransient<IWorkProcess, WorkModeling>();
|
||||||
|
|
||||||
|
services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
|
||||||
services.AddTransient<AbstractSaveToWord, SaveToWord>();
|
services.AddTransient<AbstractSaveToWord, SaveToWord>();
|
||||||
services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
|
services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
|
||||||
|
services.AddSingleton<AbstractMailWorker, MailKitWorker>();
|
||||||
|
|
||||||
services.AddTransient<FormMain>();
|
services.AddTransient<FormMain>();
|
||||||
services.AddTransient<FormComponent>();
|
services.AddTransient<FormComponent>();
|
||||||
services.AddTransient<FormComponents>();
|
services.AddTransient<FormComponents>();
|
||||||
services.AddTransient<FormCreateOrder>();
|
services.AddTransient<FormCreateOrder>();
|
||||||
@ -57,8 +84,11 @@ namespace GiftShopView
|
|||||||
services.AddTransient<FormReportOrders>();
|
services.AddTransient<FormReportOrders>();
|
||||||
services.AddTransient<FormReportGiftComponents>();
|
services.AddTransient<FormReportGiftComponents>();
|
||||||
services.AddTransient<FormClients>();
|
services.AddTransient<FormClients>();
|
||||||
services.AddTransient<FormImplementer>();
|
services.AddTransient<FormImplementer>();
|
||||||
services.AddTransient<FormImplementers>();
|
services.AddTransient<FormImplementers>();
|
||||||
}
|
services.AddTransient<FormMails>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void MailCheck(object obj) => ServiceProvider?.GetService<AbstractMailWorker>()?.MailCheck();
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user