parent
baf4bfba6d
commit
de97e33645
@ -9,7 +9,6 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace ComputersShopBusinessLogic.BusinessLogic
|
namespace ComputersShopBusinessLogic.BusinessLogic
|
||||||
@ -108,11 +107,7 @@ namespace ComputersShopBusinessLogic.BusinessLogic
|
|||||||
{
|
{
|
||||||
throw new ArgumentNullException("У клиента отсутствует пароль", nameof(model.Email));
|
throw new ArgumentNullException("У клиента отсутствует пароль", nameof(model.Email));
|
||||||
}
|
}
|
||||||
if (!Regex.IsMatch(model.Email, @"^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$"))
|
_logger.LogInformation("Client. ClientID:{Id}. ClientFIO: {ClientFIO}. Email:{ Email}. Password: { Password}", model.Id, model.ClientFIO, model.Email, model.Password);
|
||||||
{
|
|
||||||
throw new ArgumentException("Некорретно введенный email", nameof(model.Email));
|
|
||||||
}
|
|
||||||
_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
|
var element = _clientStorage.GetElement(new ClientSearchModel
|
||||||
{
|
{
|
||||||
Email = model.Email
|
Email = model.Email
|
||||||
|
@ -1,9 +1,4 @@
|
|||||||
using ComputersShopContracts.BindingModels;
|
using Microsoft.Extensions.Logging;
|
||||||
using ComputersShopContracts.BusinessLogicsContracts;
|
|
||||||
using ComputersShopContracts.SearchModels;
|
|
||||||
using ComputersShopContracts.StoragesContracts;
|
|
||||||
using ComputersShopContracts.ViewModels;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
@ -10,7 +10,6 @@ using System.Collections.Generic;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using ComputersShopBusinessLogic.MailWorker;
|
|
||||||
|
|
||||||
namespace ComputersShopBusinessLogic.BusinessLogic
|
namespace ComputersShopBusinessLogic.BusinessLogic
|
||||||
{
|
{
|
||||||
@ -19,15 +18,11 @@ namespace ComputersShopBusinessLogic.BusinessLogic
|
|||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IOrderStorage _orderStorage;
|
private readonly IOrderStorage _orderStorage;
|
||||||
|
|
||||||
private readonly AbstractMailWorker _mailWorker;
|
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
|
||||||
private readonly IClientLogic _clientLogic;
|
{
|
||||||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage, AbstractMailWorker mailWorker, IClientLogic clientLogic)
|
|
||||||
{
|
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_orderStorage = orderStorage;
|
_orderStorage = orderStorage;
|
||||||
mailWorker = mailWorker;
|
}
|
||||||
_clientLogic = clientLogic;
|
|
||||||
}
|
|
||||||
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("ReadList. OrderId:{Id}", model?.Id);
|
_logger.LogInformation("ReadList. OrderId:{Id}", model?.Id);
|
||||||
@ -46,15 +41,12 @@ namespace ComputersShopBusinessLogic.BusinessLogic
|
|||||||
CheckModel(model);
|
CheckModel(model);
|
||||||
if (model.Status != OrderStatus.Неизвестен) return false;
|
if (model.Status != OrderStatus.Неизвестен) return false;
|
||||||
model.Status = OrderStatus.Принят;
|
model.Status = OrderStatus.Принят;
|
||||||
var result = _orderStorage.Insert(model);
|
if (_orderStorage.Insert(model) == null)
|
||||||
if (result == null)
|
{
|
||||||
{
|
|
||||||
_logger.LogWarning("Insert operation failed");
|
_logger.LogWarning("Insert operation failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
SendOrderStatusMail(result.ClientId, $"Новый заказ создан. Номер заказа #{result.Id}", $"Заказ #{result.Id} от {result.DateCreate} на сумму {result.Sum:0.00} принят");
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
public bool ChangeStatus(OrderBindingModel model, OrderStatus status)
|
public bool ChangeStatus(OrderBindingModel model, OrderStatus status)
|
||||||
{
|
{
|
||||||
@ -120,20 +112,5 @@ namespace ComputersShopBusinessLogic.BusinessLogic
|
|||||||
}
|
}
|
||||||
_logger.LogInformation("Order. Sum:{ Cost}. Id: { Id}", model.Sum, model.Id);
|
_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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,6 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="DocumentFormat.OpenXml" Version="3.0.2" />
|
<PackageReference Include="DocumentFormat.OpenXml" Version="3.0.2" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.0" />
|
||||||
<PackageReference Include="MailKit" Version="4.5.0" />
|
|
||||||
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.15" />
|
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.15" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
@ -1,101 +0,0 @@
|
|||||||
using ComputersShopContracts.BindingModels;
|
|
||||||
using ComputersShopContracts.BusinessLogicContracts;
|
|
||||||
using ComputersShopContracts.BusinessLogicsContracts;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ComputersShopBusinessLogic.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();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,82 +0,0 @@
|
|||||||
using ComputersShopContracts.BindingModels;
|
|
||||||
using ComputersShopContracts.BusinessLogicContracts;
|
|
||||||
using ComputersShopContracts.BusinessLogicsContracts;
|
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Net.Mail;
|
|
||||||
using System.Net;
|
|
||||||
using System.Security.Authentication;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ComputersShopBusinessLogic.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.TextBody,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (AuthenticationException)
|
|
||||||
{ }
|
|
||||||
finally
|
|
||||||
{
|
|
||||||
client.Disconnect(true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return list;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -142,14 +142,5 @@ namespace ComputersShopClientApp.Controllers
|
|||||||
var prod = APIClient.GetRequest<ComputerViewModel>($"api/main/getcomputer?computerId={computer}");
|
var prod = APIClient.GetRequest<ComputerViewModel>($"api/main/getcomputer?computerId={computer}");
|
||||||
return count * (prod?.Price ?? 1);
|
return count * (prod?.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}"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,53 +0,0 @@
|
|||||||
@using ComputersShopContracts.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,5 @@ namespace ComputersShopDatabaseImplement
|
|||||||
public virtual DbSet<Order> Orders { set; get; }
|
public virtual DbSet<Order> Orders { set; get; }
|
||||||
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<MessageInfo> Messages { set; get; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,7 +15,7 @@ namespace ComputersShopDatabaseImplement.Implements
|
|||||||
{
|
{
|
||||||
public ClientViewModel? Delete(ClientBindingModel model)
|
public ClientViewModel? Delete(ClientBindingModel model)
|
||||||
{
|
{
|
||||||
using var context = new ComputersShopDataBase();
|
using var context = new ComputersShopDatabase();
|
||||||
var res = context.Clients.FirstOrDefault(x => x.Id == model.Id);
|
var res = context.Clients.FirstOrDefault(x => x.Id == model.Id);
|
||||||
if (res != null)
|
if (res != null)
|
||||||
{
|
{
|
||||||
@ -27,21 +27,17 @@ namespace ComputersShopDatabaseImplement.Implements
|
|||||||
|
|
||||||
public ClientViewModel? GetElement(ClientSearchModel model)
|
public ClientViewModel? GetElement(ClientSearchModel model)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(model.ClientFIO) &&
|
using var context = new ComputersShopDatabase();
|
||||||
string.IsNullOrEmpty(model.Email) &&
|
if (model.Id.HasValue)
|
||||||
string.IsNullOrEmpty(model.Password) &&
|
return context.Clients.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel;
|
||||||
!model.Id.HasValue)
|
if (model.Email != null && model.Password != null)
|
||||||
{
|
return context.Clients
|
||||||
return null;
|
.FirstOrDefault(x => x.Email.Equals(model.Email)
|
||||||
}
|
&& x.Password.Equals(model.Password))
|
||||||
using var context = new ComputersShopDataBase();
|
?.GetViewModel;
|
||||||
var temp = context.Clients
|
if (model.Email != null)
|
||||||
.FirstOrDefault(x => (string.IsNullOrEmpty(model.ClientFIO) || x.ClientFIO == model.ClientFIO) &&
|
return context.Clients.FirstOrDefault(x => x.Email.Equals(model.Email))?.GetViewModel;
|
||||||
(string.IsNullOrEmpty(model.Email) || x.Email == model.Email) &&
|
return null;
|
||||||
(string.IsNullOrEmpty(model.Password) || x.Password == model.Password) &&
|
|
||||||
(!model.Id.HasValue || x.Id == model.Id))
|
|
||||||
?.GetViewModel;
|
|
||||||
return temp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<ClientViewModel> GetFilteredList(ClientSearchModel model)
|
public List<ClientViewModel> GetFilteredList(ClientSearchModel model)
|
||||||
@ -57,7 +53,7 @@ namespace ComputersShopDatabaseImplement.Implements
|
|||||||
}
|
}
|
||||||
if (model.Email != null)
|
if (model.Email != null)
|
||||||
{
|
{
|
||||||
using var context = new ComputersShopDataBase();
|
using var context = new ComputersShopDatabase();
|
||||||
return context.Clients
|
return context.Clients
|
||||||
.Where(x => x.Email.Contains(model.Email))
|
.Where(x => x.Email.Contains(model.Email))
|
||||||
.Select(x => x.GetViewModel)
|
.Select(x => x.GetViewModel)
|
||||||
@ -68,13 +64,13 @@ namespace ComputersShopDatabaseImplement.Implements
|
|||||||
|
|
||||||
public List<ClientViewModel> GetFullList()
|
public List<ClientViewModel> GetFullList()
|
||||||
{
|
{
|
||||||
using var context = new ComputersShopDataBase();
|
using var context = new ComputersShopDatabase();
|
||||||
return context.Clients.Select(x => x.GetViewModel).ToList();
|
return context.Clients.Select(x => x.GetViewModel).ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ClientViewModel? Insert(ClientBindingModel model)
|
public ClientViewModel? Insert(ClientBindingModel model)
|
||||||
{
|
{
|
||||||
using var context = new ComputersShopDataBase();
|
using var context = new ComputersShopDatabase();
|
||||||
var res = Client.Create(model);
|
var res = Client.Create(model);
|
||||||
if (res != null)
|
if (res != null)
|
||||||
{
|
{
|
||||||
@ -86,7 +82,7 @@ namespace ComputersShopDatabaseImplement.Implements
|
|||||||
|
|
||||||
public ClientViewModel? Update(ClientBindingModel model)
|
public ClientViewModel? Update(ClientBindingModel model)
|
||||||
{
|
{
|
||||||
using var context = new ComputersShopDataBase();
|
using var context = new ComputersShopDatabase();
|
||||||
var res = context.Clients.FirstOrDefault(x => x.Id == model.Id);
|
var res = context.Clients.FirstOrDefault(x => x.Id == model.Id);
|
||||||
res?.Update(model);
|
res?.Update(model);
|
||||||
context.SaveChanges();
|
context.SaveChanges();
|
||||||
|
@ -21,8 +21,7 @@ namespace ComputersShopDatabaseImplement.Models
|
|||||||
|
|
||||||
[Required]
|
[Required]
|
||||||
public string Password { get; set; } = string.Empty;
|
public string Password { get; set; } = string.Empty;
|
||||||
[ForeignKey("ClientId")]
|
|
||||||
public virtual List<MessageInfo> Messages { get; set; } = new();
|
|
||||||
public int Id { get; set; }
|
public int Id { get; set; }
|
||||||
|
|
||||||
[ForeignKey("ClientId")]
|
[ForeignKey("ClientId")]
|
||||||
|
@ -1,57 +0,0 @@
|
|||||||
using ComputersShopContracts.BindingModels;
|
|
||||||
using ComputersShopContracts.ViewModels;
|
|
||||||
using ComputersShopDataModels.Models;
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel.DataAnnotations;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace ComputersShopDatabaseImplement.Models
|
|
||||||
{
|
|
||||||
public class MessageInfo : IMessageInfoModel
|
|
||||||
{
|
|
||||||
[Key]
|
|
||||||
public string MessageId { get; private set; } = string.Empty;
|
|
||||||
|
|
||||||
public int? ClientId { get; private set; }
|
|
||||||
|
|
||||||
public virtual Client? Client { get; set; }
|
|
||||||
|
|
||||||
public string SenderName { get; private set; } = string.Empty;
|
|
||||||
|
|
||||||
public DateTime DateDelivery { get; private set; } = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc);
|
|
||||||
|
|
||||||
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,
|
|
||||||
ClientId = model.ClientId,
|
|
||||||
MessageId = model.MessageId,
|
|
||||||
SenderName = model.SenderName,
|
|
||||||
DateDelivery = DateTime.SpecifyKind(model.DateDelivery, DateTimeKind.Utc)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public MessageInfoViewModel GetViewModel => new()
|
|
||||||
{
|
|
||||||
Body = Body,
|
|
||||||
Subject = Subject,
|
|
||||||
ClientId = ClientId,
|
|
||||||
MessageId = MessageId,
|
|
||||||
SenderName = SenderName,
|
|
||||||
DateDelivery = DateDelivery,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,5 +1,4 @@
|
|||||||
using ComputersShopContracts.BindingModels;
|
using ComputersShopContracts.BindingModels;
|
||||||
using ComputersShopContracts.BusinessLogicContracts;
|
|
||||||
using ComputersShopContracts.BusinessLogicsContracts;
|
using ComputersShopContracts.BusinessLogicsContracts;
|
||||||
using ComputersShopContracts.SearchModels;
|
using ComputersShopContracts.SearchModels;
|
||||||
using ComputersShopContracts.ViewModels;
|
using ComputersShopContracts.ViewModels;
|
||||||
@ -14,13 +13,11 @@ namespace ComputersShopRestApi.Controllers
|
|||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
private readonly IClientLogic _logic;
|
private readonly IClientLogic _logic;
|
||||||
private readonly IMessageInfoLogic _mailLogic;
|
|
||||||
|
|
||||||
public ClientController(IClientLogic logic, ILogger<ClientController> logger, IMessageInfoLogic mailLogic)
|
public ClientController(IClientLogic logic, ILogger<ClientController> logger)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_logic = logic;
|
_logic = logic;
|
||||||
_mailLogic = mailLogic;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
@ -69,21 +66,5 @@ namespace ComputersShopRestApi.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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,12 +1,7 @@
|
|||||||
using ComputersShopBusinessLogic.BusinessLogic;
|
using ComputersShopBusinessLogic.BusinessLogic;
|
||||||
using ComputersShopBusinessLogic.BusinessLogics;
|
|
||||||
using ComputersShopBusinessLogic.MailWorker;
|
|
||||||
using ComputersShopContracts.BindingModels;
|
|
||||||
using ComputersShopContracts.BusinessLogicContracts;
|
|
||||||
using ComputersShopContracts.BusinessLogicsContracts;
|
using ComputersShopContracts.BusinessLogicsContracts;
|
||||||
using ComputersShopContracts.StoragesContracts;
|
using ComputersShopContracts.StoragesContracts;
|
||||||
using ComputersShopDatabaseImplement.Implements;
|
using ComputersShopDatabaseImplement.Implements;
|
||||||
using ComputersShopDataBaseImplement.Implements;
|
|
||||||
using Microsoft.OpenApi.Models;
|
using Microsoft.OpenApi.Models;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
@ -19,12 +14,11 @@ builder.Services.AddTransient<IClientStorage, ClientStorage>();
|
|||||||
builder.Services.AddTransient<IOrderStorage, OrderStorage>();
|
builder.Services.AddTransient<IOrderStorage, OrderStorage>();
|
||||||
builder.Services.AddTransient<IImplementerStorage, ImplementerStorage>();
|
builder.Services.AddTransient<IImplementerStorage, ImplementerStorage>();
|
||||||
builder.Services.AddTransient<IComputerStorage, ComputerStorage>();
|
builder.Services.AddTransient<IComputerStorage, ComputerStorage>();
|
||||||
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<IComputerLogic, ComputerLogic>();
|
builder.Services.AddTransient<IComputerLogic, ComputerLogic>();
|
||||||
builder.Services.AddTransient<IMessageInfoLogic, MessageInfoLogic>();
|
|
||||||
|
|
||||||
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
|
||||||
@ -40,17 +34,6 @@ 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())
|
||||||
{
|
{
|
||||||
|
@ -5,11 +5,5 @@
|
|||||||
"Microsoft.AspNetCore": "Warning"
|
"Microsoft.AspNetCore": "Warning"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"AllowedHosts": "*",
|
"AllowedHosts": "*"
|
||||||
"SmtpClientHost": "smtp.gmail.com",
|
|
||||||
"SmtpClientPort": "587",
|
|
||||||
"PopHost": "pop.gmail.com",
|
|
||||||
"PopPort": "995",
|
|
||||||
"MailLogin": "rpplabs900@gmail.com",
|
|
||||||
"MailPassword": "wmbu qrgy ocwl tadm"
|
|
||||||
}
|
}
|
||||||
|
@ -9,9 +9,6 @@ using ComputersShopView;
|
|||||||
using ComputersShopBusinessLogic.OfficePackage.Implements;
|
using ComputersShopBusinessLogic.OfficePackage.Implements;
|
||||||
using ComputersShopBusinessLogic.OfficePackage;
|
using ComputersShopBusinessLogic.OfficePackage;
|
||||||
using ComputersShopBusinessLogic;
|
using ComputersShopBusinessLogic;
|
||||||
using ComputersShopBusinessLogic.MailWorker;
|
|
||||||
using ComputersShopContracts.BindingModels;
|
|
||||||
using ComputersShopDataBaseImplement.Implements;
|
|
||||||
|
|
||||||
|
|
||||||
namespace ComputersShop
|
namespace ComputersShop
|
||||||
@ -32,26 +29,6 @@ namespace ComputersShop
|
|||||||
var services = new ServiceCollection();
|
var services = new ServiceCollection();
|
||||||
ConfigureServices(services);
|
ConfigureServices(services);
|
||||||
_serviceProvider = services.BuildServiceProvider();
|
_serviceProvider = services.BuildServiceProvider();
|
||||||
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, "Error");
|
|
||||||
}
|
|
||||||
Application.Run(_serviceProvider.GetRequiredService<FormMain>());
|
Application.Run(_serviceProvider.GetRequiredService<FormMain>());
|
||||||
}
|
}
|
||||||
private static void ConfigureServices(ServiceCollection services)
|
private static void ConfigureServices(ServiceCollection services)
|
||||||
@ -66,7 +43,6 @@ namespace ComputersShop
|
|||||||
services.AddTransient<IComputerStorage, ComputerStorage>();
|
services.AddTransient<IComputerStorage, ComputerStorage>();
|
||||||
services.AddTransient<IClientStorage, ClientStorage>();
|
services.AddTransient<IClientStorage, ClientStorage>();
|
||||||
services.AddTransient<IImplementerStorage, ImplementerStorage>();
|
services.AddTransient<IImplementerStorage, ImplementerStorage>();
|
||||||
services.AddTransient<IMessageInfoStorage, MessageInfoStorage>();
|
|
||||||
|
|
||||||
services.AddTransient<IComponentLogic, ComponentLogic>();
|
services.AddTransient<IComponentLogic, ComponentLogic>();
|
||||||
services.AddTransient<IOrderLogic, OrderLogic>();
|
services.AddTransient<IOrderLogic, OrderLogic>();
|
||||||
@ -74,12 +50,11 @@ namespace ComputersShop
|
|||||||
services.AddTransient<IReportLogic, ReportLogic>();
|
services.AddTransient<IReportLogic, ReportLogic>();
|
||||||
services.AddTransient<IClientLogic, ClientLogic>();
|
services.AddTransient<IClientLogic, ClientLogic>();
|
||||||
services.AddTransient<IImplementerLogic, ImplementerLogic>();
|
services.AddTransient<IImplementerLogic, ImplementerLogic>();
|
||||||
services.AddTransient<IWorkProcess, WorkModeling>();
|
services.AddTransient<IWorkProcess, WorkModeling>()
|
||||||
|
|
||||||
services.AddTransient<AbstractSaveToWord, SaveToWord>();
|
services.AddTransient<AbstractSaveToWord, SaveToWord>();
|
||||||
services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
|
services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
|
||||||
services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
|
services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
|
||||||
services.AddSingleton<AbstractMailWorker, MailKitWorker>();
|
|
||||||
|
|
||||||
services.AddTransient<FormMain>();
|
services.AddTransient<FormMain>();
|
||||||
services.AddTransient<FormClients>();
|
services.AddTransient<FormClients>();
|
||||||
@ -94,6 +69,5 @@ namespace ComputersShop
|
|||||||
services.AddTransient<FormImplementer>();
|
services.AddTransient<FormImplementer>();
|
||||||
services.AddTransient<FormImplementers>();
|
services.AddTransient<FormImplementers>();
|
||||||
}
|
}
|
||||||
private static void MailCheck(object obj) => ServiceProvider?.GetService<AbstractMailWorker>()?.MailCheck();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user