чет лень стало. почти готово
This commit is contained in:
parent
fc115bd8d5
commit
acf1bbf960
@ -9,6 +9,8 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
|
||||
namespace FlowerShopBusinessLogic.BusinessLogic
|
||||
{
|
||||
@ -106,7 +108,15 @@ namespace FlowerShopBusinessLogic.BusinessLogic
|
||||
throw new ArgumentNullException("Нет пароля клиента",
|
||||
nameof(model.ClientFIO));
|
||||
}
|
||||
_logger.LogInformation("Client. ClientFIO:{ClientFIO}." +
|
||||
if (!Regex.IsMatch(model.Email, @"^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$"))
|
||||
{
|
||||
throw new ArgumentException("Некорретно введен email клиента", nameof(model.Email));
|
||||
}
|
||||
if (!Regex.IsMatch(model.Password, @"^(?=.*\d)(?=.*\W)(?=.*[^\d\s]).+$"))
|
||||
{
|
||||
throw new ArgumentException("Некорректно введен пароль клиента", nameof(model.Password));
|
||||
}
|
||||
_logger.LogInformation("Client. ClientFIO:{ClientFIO}." +
|
||||
"Email:{ Email}. Password:{ Password}. Id: { Id} ", model.ClientFIO, model.Email, model.Password, model.Id);
|
||||
var element = _clientStorage.GetElement(new ClientSearchModel
|
||||
{
|
||||
|
@ -8,6 +8,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="DocumentFormat.OpenXml" Version="3.0.2" />
|
||||
<PackageReference Include="MailKit" Version="4.5.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
|
||||
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.15" />
|
||||
</ItemGroup>
|
||||
|
81
FlowerShopBusinessLogic/MailWorker/AbstractMailWorker.cs
Normal file
81
FlowerShopBusinessLogic/MailWorker/AbstractMailWorker.cs
Normal file
@ -0,0 +1,81 @@
|
||||
using FlowerShopContracts.BindingModels;
|
||||
using FlowerShopContracts.BusinessLogicsContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FlowerShopBusinessLogic.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 ILogger _logger;
|
||||
public AbstractMailWorker(ILogger<AbstractMailWorker> logger, IMessageInfoLogic messageInfoLogic)
|
||||
{
|
||||
_logger = logger;
|
||||
_messageInfoLogic = messageInfoLogic;
|
||||
}
|
||||
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)
|
||||
{
|
||||
_messageInfoLogic.Create(mail);
|
||||
}
|
||||
}
|
||||
protected abstract Task SendMailAsync(MailSendInfoBindingModel info);
|
||||
protected abstract Task<List<MessageInfoBindingModel>>
|
||||
ReceiveMailAsync();
|
||||
}
|
||||
}
|
84
FlowerShopBusinessLogic/MailWorker/MailKitWorker.cs
Normal file
84
FlowerShopBusinessLogic/MailWorker/MailKitWorker.cs
Normal file
@ -0,0 +1,84 @@
|
||||
using FlowerShopContracts.BindingModels;
|
||||
using FlowerShopContracts.BusinessLogicsContracts;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Mail;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using MailKit.Net.Pop3;
|
||||
using MailKit.Security;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FlowerShopBusinessLogic.MailWorker
|
||||
{
|
||||
public class MailKitWorker : AbstractMailWorker
|
||||
{
|
||||
public MailKitWorker(ILogger<MailKitWorker> logger, IMessageInfoLogic
|
||||
messageInfoLogic) : base(logger, messageInfoLogic) { }
|
||||
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.TextBody
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (MailKit.Security.AuthenticationException)
|
||||
{ }
|
||||
finally
|
||||
{
|
||||
client.Disconnect(true);
|
||||
}
|
||||
});
|
||||
return list;
|
||||
}
|
||||
}
|
||||
}
|
48
FlowerShopBusinessLogic/MessageInfoLogic.cs
Normal file
48
FlowerShopBusinessLogic/MessageInfoLogic.cs
Normal file
@ -0,0 +1,48 @@
|
||||
using FlowerShopContracts.BindingModels;
|
||||
using FlowerShopContracts.BusinessLogicsContracts;
|
||||
using FlowerShopContracts.SearchModels;
|
||||
using FlowerShopContracts.StoragesContracts;
|
||||
using FlowerShopContracts.ViewModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FlowerShopBusinessLogic.BusinessLogic
|
||||
{
|
||||
public class MessageInfoLogic : IMessageInfoLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IMessageInfoStorage _messageInfoStorage;
|
||||
public MessageInfoLogic(ILogger<MessageInfoLogic> logger, IMessageInfoStorage MessageInfoStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_messageInfoStorage = MessageInfoStorage;
|
||||
}
|
||||
|
||||
public bool Create(MessageInfoBindingModel model)
|
||||
{
|
||||
if (_messageInfoStorage.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) ? _messageInfoStorage.GetFullList() : _messageInfoStorage.GetFilteredList(model);
|
||||
if (list == null)
|
||||
{
|
||||
_logger.LogWarning("ReadList return null list");
|
||||
return null;
|
||||
}
|
||||
_logger.LogInformation("ReadList. Count:{Count}", list.Count);
|
||||
return list;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
using FlowerShopContracts.BindingModels;
|
||||
using FlowerShopBusinessLogic.MailWorker;
|
||||
using FlowerShopContracts.BindingModels;
|
||||
using FlowerShopContracts.BusinessLogicsContracts;
|
||||
using FlowerShopContracts.SearchModels;
|
||||
using FlowerShopContracts.StoragesContracts;
|
||||
@ -17,13 +18,17 @@ namespace FlowerShopBusinessLogic.BusinessLogic
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IOrderStorage _orderStorage;
|
||||
private readonly AbstractMailWorker _mailWorker;
|
||||
private readonly IClientLogic _clientLogic;
|
||||
static readonly object locker = new object();
|
||||
|
||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
|
||||
{
|
||||
_logger = logger;
|
||||
_orderStorage = orderStorage;
|
||||
}
|
||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, AbstractMailWorker mailWorker, IClientLogic clientLogic)
|
||||
{
|
||||
_orderStorage = orderStorage;
|
||||
_logger = logger;
|
||||
_mailWorker = mailWorker;
|
||||
_clientLogic = clientLogic;
|
||||
}
|
||||
public OrderViewModel? ReadElement(OrderSearchModel model)
|
||||
{
|
||||
if (model == null)
|
||||
@ -59,13 +64,15 @@ namespace FlowerShopBusinessLogic.BusinessLogic
|
||||
CheckModel(model);
|
||||
if (model.Status != OrderStatus.Неизвестен) return false;
|
||||
model.Status = OrderStatus.Принят;
|
||||
if (_orderStorage.Insert(model) == null)
|
||||
{
|
||||
var res = _orderStorage.Insert(model);
|
||||
if (res == null)
|
||||
{
|
||||
_logger.LogWarning("Insert operation failed");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
SendOrderStatusMail(model.ClientId, $"Изменен статус заказа #{res.Id}", $"Заказ #{res.Id} изменен статус на {model.Status}");
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool ChangeStatus(OrderBindingModel model, OrderStatus status)
|
||||
{
|
||||
@ -85,9 +92,16 @@ namespace FlowerShopBusinessLogic.BusinessLogic
|
||||
if (model.Status == OrderStatus.Выдан) model.DateImplement = DateTime.Now;
|
||||
if (element.ImplementerId.HasValue)
|
||||
model.ImplementerId = element.ImplementerId;
|
||||
_orderStorage.Update(model);
|
||||
return true;
|
||||
}
|
||||
var result = _orderStorage.Update(model);
|
||||
if (result == null)
|
||||
{
|
||||
_logger.LogWarning("Update operation failed");
|
||||
return false;
|
||||
}
|
||||
SendOrderStatusMail(result.ClientId, $"Изменен статус заказа #{result.Id}", $"Заказ #{model.Id} изменен статус на {result.Status}");
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool TakeOrderInWork(OrderBindingModel model)
|
||||
{
|
||||
@ -127,5 +141,20 @@ namespace FlowerShopBusinessLogic.BusinessLogic
|
||||
}
|
||||
_logger.LogInformation("Order. Sum:{ Cost}. Id: { Id}", model.Sum, model.Id);
|
||||
}
|
||||
}
|
||||
private bool SendOrderStatusMail(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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,18 @@ namespace FlowerShopClientApp.Controllers
|
||||
View(APIClient.GetRequest<List<OrderViewModel>>($"api/main/getorders?clientId={APIClient.Client.Id}"));
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
[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}"));
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Privacy()
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
|
54
FlowerShopClientApp/Views/Home/Mails.cshtml
Normal file
54
FlowerShopClientApp/Views/Home/Mails.cshtml
Normal file
@ -0,0 +1,54 @@
|
||||
@using FlowerShopContracts.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>
|
@ -26,6 +26,9 @@
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="Privacy">Личные данные</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="Mails">Письма</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link text-dark" asparea="" asp-controller="Home" asp-action="Enter">Вход</a>
|
||||
</li>
|
||||
|
18
FlowerShopContracts/BindingModels/MailConfigBindingModel.cs
Normal file
18
FlowerShopContracts/BindingModels/MailConfigBindingModel.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FlowerShopContracts.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,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FlowerShopContracts.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;
|
||||
}
|
||||
}
|
24
FlowerShopContracts/BindingModels/MessageInfoBindingModel.cs
Normal file
24
FlowerShopContracts/BindingModels/MessageInfoBindingModel.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using FlowerShopDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FlowerShopContracts.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,18 @@
|
||||
using FlowerShopContracts.BindingModels;
|
||||
using FlowerShopContracts.SearchModels;
|
||||
using FlowerShopContracts.ViewModels;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FlowerShopContracts.BusinessLogicsContracts
|
||||
{
|
||||
public interface IMessageInfoLogic
|
||||
{
|
||||
List<MessageInfoViewModel>? ReadList(MessageInfoSearchModel? model);
|
||||
bool Create(MessageInfoBindingModel model);
|
||||
}
|
||||
}
|
14
FlowerShopContracts/SearchModels/MessageInfoSearchModel.cs
Normal file
14
FlowerShopContracts/SearchModels/MessageInfoSearchModel.cs
Normal file
@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FlowerShopContracts.SearchModels
|
||||
{
|
||||
public class MessageInfoSearchModel
|
||||
{
|
||||
public int? ClientId { get; set; }
|
||||
public string? MessageId { get; set; }
|
||||
}
|
||||
}
|
20
FlowerShopContracts/StoragesContracts/IMessageInfoStorage.cs
Normal file
20
FlowerShopContracts/StoragesContracts/IMessageInfoStorage.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using FlowerShopContracts.BindingModels;
|
||||
using FlowerShopContracts.SearchModels;
|
||||
using FlowerShopContracts.ViewModels;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FlowerShopContracts.StoragesContracts
|
||||
{
|
||||
public interface IMessageInfoStorage
|
||||
{
|
||||
List<MessageInfoViewModel> GetFullList();
|
||||
List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model);
|
||||
MessageInfoViewModel? GetElement(MessageInfoSearchModel model);
|
||||
MessageInfoViewModel? Insert(MessageInfoBindingModel model);
|
||||
}
|
||||
}
|
24
FlowerShopContracts/ViewModels/MessageInfoViewModel.cs
Normal file
24
FlowerShopContracts/ViewModels/MessageInfoViewModel.cs
Normal file
@ -0,0 +1,24 @@
|
||||
using FlowerShopDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FlowerShopContracts.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;
|
||||
}
|
||||
}
|
19
FlowerShopDataModels/IMessageInfoModel.cs
Normal file
19
FlowerShopDataModels/IMessageInfoModel.cs
Normal file
@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FlowerShopDataModels.Models
|
||||
{
|
||||
public interface IMessageInfoModel
|
||||
{
|
||||
string MessageId { get; }
|
||||
int? ClientId { get; }
|
||||
string SenderName { get; }
|
||||
DateTime DateDelivery { get; }
|
||||
string Subject { get; }
|
||||
string Body { get; }
|
||||
|
||||
}
|
||||
}
|
@ -24,6 +24,7 @@ namespace FlowerShopDatabaseImplement
|
||||
public virtual DbSet<Order> Orders { set; get; }
|
||||
public virtual DbSet<Client> Clients { set; get; }
|
||||
public virtual DbSet<Implementer> Implementers { set; get; }
|
||||
public virtual DbSet<MessageInfo> Messages { set; get; }
|
||||
|
||||
}
|
||||
}
|
||||
|
59
FlowerShopDatabaseImplement/MessageInfo.cs
Normal file
59
FlowerShopDatabaseImplement/MessageInfo.cs
Normal file
@ -0,0 +1,59 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using FlowerShopContracts.BindingModels;
|
||||
using FlowerShopContracts.ViewModels;
|
||||
using FlowerShopDataModels.Models;
|
||||
|
||||
|
||||
namespace FlowerShopDatabaseImplement.Models
|
||||
{
|
||||
public class MessageInfo : IMessageInfoModel
|
||||
{
|
||||
[Key]
|
||||
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 MessageInfo? Create(FlowerShopDataBase 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,
|
||||
};
|
||||
}
|
||||
}
|
57
FlowerShopDatabaseImplement/MessageInfoStorage.cs
Normal file
57
FlowerShopDatabaseImplement/MessageInfoStorage.cs
Normal file
@ -0,0 +1,57 @@
|
||||
using FlowerShopContracts.BindingModels;
|
||||
using FlowerShopContracts.SearchModels;
|
||||
using FlowerShopContracts.StoragesContracts;
|
||||
using FlowerShopContracts.ViewModels;
|
||||
using FlowerShopDatabaseImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FlowerShopDatabaseImplement.Implements
|
||||
{
|
||||
public class MessageInfoStorage : IMessageInfoStorage
|
||||
{
|
||||
|
||||
public MessageInfoViewModel? GetElement(MessageInfoSearchModel model)
|
||||
{
|
||||
using var context = new FlowerShopDataBase();
|
||||
if (model.MessageId != null)
|
||||
{
|
||||
return context.Messages.FirstOrDefault(x => x.MessageId == model.MessageId)?.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model)
|
||||
{
|
||||
using var context = new FlowerShopDataBase();
|
||||
return context.Messages
|
||||
.Where(x => x.ClientId == model.ClientId)
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<MessageInfoViewModel> GetFullList()
|
||||
{
|
||||
using var context = new FlowerShopDataBase();
|
||||
return context.Messages
|
||||
.Select(x => x.GetViewModel)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public MessageInfoViewModel? Insert(MessageInfoBindingModel model)
|
||||
{
|
||||
using var context = new FlowerShopDataBase();
|
||||
var newMessage = MessageInfo.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;
|
||||
}
|
||||
}
|
||||
}
|
292
FlowerShopDatabaseImplement/Migrations/20240430175003_InitialCreate.Designer.cs
generated
Normal file
292
FlowerShopDatabaseImplement/Migrations/20240430175003_InitialCreate.Designer.cs
generated
Normal file
@ -0,0 +1,292 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using FlowerShopDatabaseImplement;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace FlowerShopDatabaseImplement.Migrations
|
||||
{
|
||||
[DbContext(typeof(FlowerShopDataBase))]
|
||||
[Migration("20240430175003_InitialCreate")]
|
||||
partial class InitialCreate
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "6.0.0")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1);
|
||||
|
||||
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Client", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);
|
||||
|
||||
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("FlowerShopDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);
|
||||
|
||||
b.Property<string>("ComponentName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<double>("Cost")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Components");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Flower", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);
|
||||
|
||||
b.Property<string>("FlowerName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<double>("Price")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Flowers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.FlowerComponent", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);
|
||||
|
||||
b.Property<int>("ComponentId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("FlowerId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ComponentId");
|
||||
|
||||
b.HasIndex("FlowerId");
|
||||
|
||||
b.ToTable("FlowerComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);
|
||||
|
||||
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>("FlowerId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("Status")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<double>("Sum")
|
||||
.HasColumnType("float");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("ClientId");
|
||||
|
||||
b.HasIndex("FlowerId");
|
||||
|
||||
b.ToTable("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Shop", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);
|
||||
|
||||
b.Property<string>("Address")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<DateTime>("DateOpen")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<int>("MaxCapacity")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("ShopName")
|
||||
.IsRequired()
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Shops");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.ShopFlower", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"), 1L, 1);
|
||||
|
||||
b.Property<int>("Count")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("FlowerId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<int>("ShopId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("FlowerId");
|
||||
|
||||
b.HasIndex("ShopId");
|
||||
|
||||
b.ToTable("ShopFlowers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.FlowerComponent", b =>
|
||||
{
|
||||
b.HasOne("FlowerShopDatabaseImplement.Models.Component", "Component")
|
||||
.WithMany("FlowerComponents")
|
||||
.HasForeignKey("ComponentId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FlowerShopDatabaseImplement.Models.Flower", "Flower")
|
||||
.WithMany("Components")
|
||||
.HasForeignKey("FlowerId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Component");
|
||||
|
||||
b.Navigation("Flower");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Order", b =>
|
||||
{
|
||||
b.HasOne("FlowerShopDatabaseImplement.Models.Client", "Client")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("ClientId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FlowerShopDatabaseImplement.Models.Flower", "Flower")
|
||||
.WithMany("Orders")
|
||||
.HasForeignKey("FlowerId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Client");
|
||||
|
||||
b.Navigation("Flower");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.ShopFlower", b =>
|
||||
{
|
||||
b.HasOne("FlowerShopDatabaseImplement.Models.Flower", "Flower")
|
||||
.WithMany("ShopFlowers")
|
||||
.HasForeignKey("FlowerId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("FlowerShopDatabaseImplement.Models.Shop", "Shop")
|
||||
.WithMany("Flowers")
|
||||
.HasForeignKey("ShopId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("Flower");
|
||||
|
||||
b.Navigation("Shop");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Client", b =>
|
||||
{
|
||||
b.Navigation("Orders");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Component", b =>
|
||||
{
|
||||
b.Navigation("FlowerComponents");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Flower", b =>
|
||||
{
|
||||
b.Navigation("Components");
|
||||
|
||||
b.Navigation("Orders");
|
||||
|
||||
b.Navigation("ShopFlowers");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("FlowerShopDatabaseImplement.Models.Shop", b =>
|
||||
{
|
||||
b.Navigation("Flowers");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,211 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace FlowerShopDatabaseImplement.Migrations
|
||||
{
|
||||
public partial class InitialCreate : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Clients",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
ClientFIO = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Email = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Password = table.Column<string>(type: "nvarchar(max)", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Clients", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Components",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
ComponentName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Cost = table.Column<double>(type: "float", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Components", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Flowers",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
FlowerName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Price = table.Column<double>(type: "float", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Flowers", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Shops",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
ShopName = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
Address = table.Column<string>(type: "nvarchar(max)", nullable: false),
|
||||
DateOpen = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
MaxCapacity = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Shops", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "FlowerComponents",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
FlowerId = table.Column<int>(type: "int", nullable: false),
|
||||
ComponentId = table.Column<int>(type: "int", nullable: false),
|
||||
Count = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_FlowerComponents", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_FlowerComponents_Components_ComponentId",
|
||||
column: x => x.ComponentId,
|
||||
principalTable: "Components",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_FlowerComponents_Flowers_FlowerId",
|
||||
column: x => x.FlowerId,
|
||||
principalTable: "Flowers",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Orders",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
Count = table.Column<int>(type: "int", nullable: false),
|
||||
Sum = table.Column<double>(type: "float", nullable: false),
|
||||
Status = table.Column<int>(type: "int", nullable: false),
|
||||
DateCreate = table.Column<DateTime>(type: "datetime2", nullable: false),
|
||||
DateImplement = table.Column<DateTime>(type: "datetime2", nullable: true),
|
||||
FlowerId = table.Column<int>(type: "int", nullable: false),
|
||||
ClientId = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Orders", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_Orders_Clients_ClientId",
|
||||
column: x => x.ClientId,
|
||||
principalTable: "Clients",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_Orders_Flowers_FlowerId",
|
||||
column: x => x.FlowerId,
|
||||
principalTable: "Flowers",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "ShopFlowers",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("SqlServer:Identity", "1, 1"),
|
||||
FlowerId = table.Column<int>(type: "int", nullable: false),
|
||||
ShopId = table.Column<int>(type: "int", nullable: false),
|
||||
Count = table.Column<int>(type: "int", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_ShopFlowers", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_ShopFlowers_Flowers_FlowerId",
|
||||
column: x => x.FlowerId,
|
||||
principalTable: "Flowers",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_ShopFlowers_Shops_ShopId",
|
||||
column: x => x.ShopId,
|
||||
principalTable: "Shops",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_FlowerComponents_ComponentId",
|
||||
table: "FlowerComponents",
|
||||
column: "ComponentId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_FlowerComponents_FlowerId",
|
||||
table: "FlowerComponents",
|
||||
column: "FlowerId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Orders_ClientId",
|
||||
table: "Orders",
|
||||
column: "ClientId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_Orders_FlowerId",
|
||||
table: "Orders",
|
||||
column: "FlowerId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ShopFlowers_FlowerId",
|
||||
table: "ShopFlowers",
|
||||
column: "FlowerId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_ShopFlowers_ShopId",
|
||||
table: "ShopFlowers",
|
||||
column: "ShopId");
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "FlowerComponents");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Orders");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "ShopFlowers");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Components");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Clients");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Flowers");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Shops");
|
||||
}
|
||||
}
|
||||
}
|
@ -11,11 +11,13 @@ internal class DataFileSingleton
|
||||
private readonly string FlowerFileName = "Product.xml";
|
||||
private readonly string ClientFileName = "Client.xml";
|
||||
private readonly string ImplementerFileName = "Implementer.xml";
|
||||
private readonly string MessageInfoFileName = "MessageInfo.xml";
|
||||
public List<Component> Components { get; private set; }
|
||||
public List<Order> Orders { get; private set; }
|
||||
public List<Flower> Flowers { get; private set; }
|
||||
public List<Client> Clients { get; private set; }
|
||||
public List<Implementer> Implementers { get; private set; }
|
||||
public List<MessageInfo> Messages { get; private set; }
|
||||
|
||||
public static DataFileSingleton GetInstance()
|
||||
{
|
||||
@ -34,13 +36,15 @@ internal class DataFileSingleton
|
||||
public void SaveOrders() => SaveData(Orders, OrderFileName,
|
||||
"Orders", x => x.GetXElement);
|
||||
public void SaveClients() => SaveData(Clients, ClientFileName, "Clients", x => x.GetXElement);
|
||||
private DataFileSingleton()
|
||||
public void SaveMessages() => SaveData(Orders, ImplementerFileName, "Messages", x => x.GetXElement);
|
||||
private DataFileSingleton()
|
||||
{
|
||||
Components = LoadData(ComponentFileName, "Component", x => Component.Create(x)!)!;
|
||||
Flowers = LoadData(FlowerFileName, "Flower", x => Flower.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)!)!;
|
||||
Messages = LoadData(MessageInfoFileName, "MessageInfo", x => MessageInfo.Create(x)!)!;
|
||||
}
|
||||
private static List<T>? LoadData<T>(string filename, string xmlNodeName, Func<XElement, T> selectFunction)
|
||||
{
|
||||
|
80
FlowerShopFileImplement/MessageInfo.cs
Normal file
80
FlowerShopFileImplement/MessageInfo.cs
Normal file
@ -0,0 +1,80 @@
|
||||
using FlowerShopContracts.BindingModels;
|
||||
using FlowerShopContracts.ViewModels;
|
||||
using FlowerShopDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Linq;
|
||||
|
||||
namespace FlowerShopFileImplement.Models
|
||||
{
|
||||
public class MessageInfo : 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 MessageInfo? Create(MessageInfoBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new()
|
||||
{
|
||||
Body = model.Body,
|
||||
Subject = model.Subject,
|
||||
ClientId = model.ClientId,
|
||||
MessageId = model.MessageId,
|
||||
SenderName = model.SenderName,
|
||||
DateDelivery = model.DateDelivery,
|
||||
};
|
||||
}
|
||||
|
||||
public static MessageInfo? Create(XElement element)
|
||||
{
|
||||
if (element == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new()
|
||||
{
|
||||
Body = element.Attribute("Body")!.Value,
|
||||
Subject = element.Attribute("Subject")!.Value,
|
||||
ClientId = Convert.ToInt32(element.Attribute("ClientId")!.Value),
|
||||
MessageId = element.Attribute("MessageId")!.Value,
|
||||
SenderName = element.Attribute("SenderName")!.Value,
|
||||
DateDelivery = Convert.ToDateTime(element.Attribute("DateDelivery")!.Value),
|
||||
};
|
||||
}
|
||||
|
||||
public MessageInfoViewModel GetViewModel => new()
|
||||
{
|
||||
Body = Body,
|
||||
Subject = Subject,
|
||||
ClientId = ClientId,
|
||||
MessageId = MessageId,
|
||||
SenderName = SenderName,
|
||||
DateDelivery = DateDelivery,
|
||||
};
|
||||
|
||||
public XElement GetXElement => new("MessageInfo",
|
||||
new XAttribute("Body", Body),
|
||||
new XAttribute("Subject", Subject),
|
||||
new XAttribute("ClientId", ClientId),
|
||||
new XAttribute("MessageId", MessageId),
|
||||
new XAttribute("SenderName", SenderName),
|
||||
new XAttribute("DateDelivery", DateDelivery)
|
||||
);
|
||||
}
|
||||
}
|
58
FlowerShopFileImplement/MessageInfoStorage.cs
Normal file
58
FlowerShopFileImplement/MessageInfoStorage.cs
Normal file
@ -0,0 +1,58 @@
|
||||
using FlowerShopContracts.BindingModels;
|
||||
using FlowerShopContracts.SearchModels;
|
||||
using FlowerShopContracts.StoragesContracts;
|
||||
using FlowerShopContracts.ViewModels;
|
||||
using FlowerShopFileImplement.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FlowerShopFileImplement.Implements
|
||||
{
|
||||
public class MessageInfoStorage : IMessageInfoStorage
|
||||
{
|
||||
private readonly DataFileSingleton _source;
|
||||
public MessageInfoStorage()
|
||||
{
|
||||
_source = DataFileSingleton.GetInstance();
|
||||
}
|
||||
|
||||
public MessageInfoViewModel? GetElement(MessageInfoSearchModel model)
|
||||
{
|
||||
if (model.MessageId != null)
|
||||
{
|
||||
return _source.Messages.FirstOrDefault(x => x.MessageId == model.MessageId)?.GetViewModel;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<MessageInfoViewModel> GetFilteredList(MessageInfoSearchModel model)
|
||||
{
|
||||
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 = MessageInfo.Create(model);
|
||||
if (newMessage == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
_source.Messages.Add(newMessage);
|
||||
_source.SaveMessages();
|
||||
return newMessage.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -15,6 +15,8 @@ namespace FlowerShopListImplement
|
||||
public List<Flower> Flowers { get; set; }
|
||||
public List<Client> Clients { get; set; }
|
||||
public List<Implementer> Implementers { get; set; }
|
||||
public List<MessageInfo> Messages { get; set; }
|
||||
|
||||
|
||||
private DataListSingleton()
|
||||
{
|
||||
@ -22,7 +24,8 @@ namespace FlowerShopListImplement
|
||||
Orders = new List<Order>();
|
||||
Flowers = new List<Flower>();
|
||||
Clients = new List<Client>();
|
||||
}
|
||||
Messages = new List<MessageInfo>();
|
||||
}
|
||||
public static DataListSingleton GetInstance()
|
||||
{
|
||||
if (_instance == null)
|
||||
|
54
FlowerShopListImplement/MessageInfo.cs
Normal file
54
FlowerShopListImplement/MessageInfo.cs
Normal file
@ -0,0 +1,54 @@
|
||||
using FlowerShopContracts.BindingModels;
|
||||
using FlowerShopContracts.ViewModels;
|
||||
using FlowerShopDataModels.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FlowerShopListImplement.Models
|
||||
{
|
||||
public class MessageInfo : 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 MessageInfo? Create(MessageInfoBindingModel model)
|
||||
{
|
||||
if (model == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new()
|
||||
{
|
||||
Body = model.Body,
|
||||
Subject = model.Subject,
|
||||
ClientId = model.ClientId,
|
||||
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,
|
||||
};
|
||||
|
||||
}
|
||||
}
|
65
FlowerShopListImplement/MessageInfoStorage.cs
Normal file
65
FlowerShopListImplement/MessageInfoStorage.cs
Normal file
@ -0,0 +1,65 @@
|
||||
using FlowerShopContracts.BindingModels;
|
||||
using FlowerShopContracts.SearchModels;
|
||||
using FlowerShopContracts.StoragesContracts;
|
||||
using FlowerShopContracts.ViewModels;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace FlowerShopListImplement.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)
|
||||
{
|
||||
List<MessageInfoViewModel> result = new();
|
||||
foreach (var item in _source.Messages)
|
||||
{
|
||||
if (item.ClientId.HasValue && item.ClientId == model.ClientId)
|
||||
{
|
||||
result.Add(item.GetViewModel);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<MessageInfoViewModel> GetFullList()
|
||||
{
|
||||
List<MessageInfoViewModel> result = new();
|
||||
foreach (var item in _source.Messages)
|
||||
{
|
||||
result.Add(item.GetViewModel);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public MessageInfoViewModel? Insert(MessageInfoBindingModel model)
|
||||
{
|
||||
var newMessage = MessageInfo.Create(model);
|
||||
if (newMessage == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
_source.Messages.Add(newMessage);
|
||||
return newMessage.GetViewModel;
|
||||
}
|
||||
}
|
||||
}
|
@ -12,13 +12,30 @@ namespace FlowerShopRestApi.Controllers
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IClientLogic _logic;
|
||||
public ClientController(IClientLogic logic, ILogger<ClientController>
|
||||
logger)
|
||||
{
|
||||
private readonly IMessageInfoLogic _mailLogic;
|
||||
public ClientController(IClientLogic logic, IMessageInfoLogic mailLogic, ILogger<ClientController> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
_logic = logic;
|
||||
}
|
||||
[HttpGet]
|
||||
_mailLogic = mailLogic;
|
||||
}
|
||||
[HttpGet]
|
||||
public List<MessageInfoViewModel>? GetMessages(int clientId)
|
||||
{
|
||||
try
|
||||
{
|
||||
return _mailLogic.ReadList(new MessageInfoSearchModel
|
||||
{
|
||||
ClientId = clientId
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка получения писем клиента");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpGet]
|
||||
public ClientViewModel? Login(string login, string password)
|
||||
{
|
||||
try
|
||||
|
@ -1,4 +1,6 @@
|
||||
using FlowerShopBusinessLogic.BusinessLogic;
|
||||
using FlowerShopBusinessLogic.MailWorker;
|
||||
using FlowerShopContracts.BindingModels;
|
||||
using FlowerShopContracts.BusinessLogicsContracts;
|
||||
using FlowerShopContracts.StoragesContracts;
|
||||
using FlowerShopDatabaseImplement.Implements;
|
||||
@ -12,6 +14,11 @@ builder.Services.AddTransient<IFlowerStorage, FlowerStorage>();
|
||||
builder.Services.AddTransient<IOrderLogic, OrderLogic>();
|
||||
builder.Services.AddTransient<IClientLogic, ClientLogic>();
|
||||
builder.Services.AddTransient<IFlowerLogic, FlowerLogic>();
|
||||
builder.Services.AddTransient<IImplementerStorage, ImplementerStorage>();
|
||||
builder.Services.AddTransient<IMessageInfoStorage, MessageInfoStorage>();
|
||||
builder.Services.AddTransient<IImplementerLogic, ImplementerLogic>();
|
||||
builder.Services.AddTransient<IMessageInfoLogic, MessageInfoLogic>();
|
||||
builder.Services.AddSingleton<AbstractMailWorker, MailKitWorker>();
|
||||
builder.Services.AddControllers();
|
||||
// Learn more about configuring Swagger/OpenAPI at
|
||||
https://aka.ms/aspnetcore/swashbuckle
|
||||
@ -26,6 +33,24 @@ builder.Services.AddSwaggerGen(c =>
|
||||
});
|
||||
});
|
||||
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.
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
|
@ -5,5 +5,12 @@
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
"AllowedHosts": "*",
|
||||
"SmtpClientHost\": \"smtp.gmail.com\",": null,
|
||||
"SmtpClientPort": "587",
|
||||
"PopHost": "pop.gmail.com",
|
||||
"PopPort": "995",
|
||||
|
||||
"MailLogin": "sasda3183@gmail.com",
|
||||
"MailPassword": "ozxp vjof uinv fcmj"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user