Слил
This commit is contained in:
commit
c1bd43b7e1
51
Bank/BankBusinessLogic/MailWorker/AbstractMailWorker.cs
Normal file
51
Bank/BankBusinessLogic/MailWorker/AbstractMailWorker.cs
Normal file
@ -0,0 +1,51 @@
|
||||
using BankContracts.BindingModels;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BankBusinessLogic.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 ILogger _logger;
|
||||
|
||||
public AbstractMailWorker(ILogger<AbstractMailWorker> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
protected abstract Task SendMailAsync(MailSendInfoBindingModel info);
|
||||
}
|
||||
}
|
45
Bank/BankBusinessLogic/MailWorker/MailKitWorker.cs
Normal file
45
Bank/BankBusinessLogic/MailWorker/MailKitWorker.cs
Normal file
@ -0,0 +1,45 @@
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Mail;
|
||||
using System.Net.Mime;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using BankContracts.BindingModels;
|
||||
|
||||
namespace BankBusinessLogic.MailWorker
|
||||
{
|
||||
public class MailKitWorker : AbstractMailWorker
|
||||
{
|
||||
public MailKitWorker(ILogger<MailKitWorker> logger)
|
||||
: base(logger) { }
|
||||
|
||||
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;
|
||||
Attachment attachment = new Attachment("C:\\Users\\user\\Downloads\\TransfersWithdrawalsList.pdf", new ContentType(MediaTypeNames.Application.Pdf));
|
||||
objMailMessage.Attachments.Add(attachment);
|
||||
objSmtpClient.UseDefaultCredentials = false;
|
||||
objSmtpClient.EnableSsl = true;
|
||||
objSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
|
||||
objSmtpClient.Credentials = new NetworkCredential(_mailLogin, _mailPassword);
|
||||
await Task.Run(() => objSmtpClient.Send(objMailMessage));
|
||||
}
|
||||
catch
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
18
Bank/BankContracts/BindingModels/MailConfigBindingModel.cs
Normal file
18
Bank/BankContracts/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 BankContracts.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; }
|
||||
}
|
||||
}
|
15
Bank/BankContracts/BindingModels/MailSendInfoBindingModel.cs
Normal file
15
Bank/BankContracts/BindingModels/MailSendInfoBindingModel.cs
Normal file
@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace BankContracts.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;
|
||||
}
|
||||
}
|
@ -13,6 +13,6 @@ namespace BankContracts.BindingModels
|
||||
public DateTime? DateTo { get; set; }
|
||||
public List<int>? SelectedAccountIds { get; set; }
|
||||
public List<int>? SelectedCardIds { get; set; }
|
||||
public string Email { get; set; } = string.Empty;
|
||||
public string? Email { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ namespace BankContracts.BusinessLogicsContracts
|
||||
void SaveTransfersToExcelFile(ReportBindingModel model);
|
||||
void SaveOperationsRequestsToPdfFile(ReportBindingModel model);
|
||||
void SaveTransfersWithdrawalsToPdfFile(ReportBindingModel model);
|
||||
void SendTransfersWithdrawalsToEmail(ReportBindingModel model);
|
||||
void SandOperationsRequestsToEmail(ReportBindingModel model);
|
||||
}
|
||||
}
|
||||
|
@ -16,8 +16,6 @@ namespace BankContracts.BusinessLogicsContracts
|
||||
bool Create(RequestBindingModel model);
|
||||
bool Update(RequestBindingModel model);
|
||||
bool Delete(RequestBindingModel model);
|
||||
//todo методы смены статуса
|
||||
//bool DeclineRequest(RequestBindingModel model);
|
||||
//bool SatisfyRequest(RequestBindingModel model);
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -512,10 +512,27 @@ namespace BankManagersClientApp.Controllers
|
||||
}
|
||||
return View();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region//Error
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
[HttpPost]
|
||||
public void TransfersWithdrawalsListReport(DateTime dateFrom, DateTime dateTo)
|
||||
{
|
||||
if (APIClient.Client == null)
|
||||
{
|
||||
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||
}
|
||||
APIClient.PostRequest("api/report/sendtransferswithdrawalstoemail", new ReportBindingModel
|
||||
{
|
||||
FileName = "C:\\Users\\user\\Downloads\\TransfersWithdrawalsList.pdf",
|
||||
DateFrom = dateFrom,
|
||||
DateTo = dateTo,
|
||||
Email = APIClient.Client.Email,
|
||||
});
|
||||
Response.Redirect("TransfersWithdrawalsListReport");
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region//Error
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
public IActionResult Error()
|
||||
{
|
||||
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
||||
|
@ -2,22 +2,30 @@
|
||||
ViewData["Title"] = "TransfersWithdrawalsListReport";
|
||||
}
|
||||
<div class="text-center">
|
||||
<h3 class="display-4">Список счетов с расшифровкой по переводам и выдачам</h3>
|
||||
<h3 class="display-4">Список счетов с расшифровкой по переводам и выдачам по периоду</h3>
|
||||
</div>
|
||||
<div class="text-center">
|
||||
@{
|
||||
<div class="row mb-5">
|
||||
<div class="col-4">Начальная дата:</div>
|
||||
<div class="col-8">
|
||||
<input type="date" id="startDate" name="startDate" class="form-control">
|
||||
<input type="date" id="dateFrom" name="dateFrom" class="form-control">
|
||||
</div>
|
||||
</div>
|
||||
<div class="row mb-5">
|
||||
<div class="col-4">Конечная дата:</div>
|
||||
<div class="col-8">
|
||||
<input type="date" id="endDate" name="endDate" class="form-control">
|
||||
<input type="date" id="dateTo" name="dateTo" class="form-control">
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4"><input type="submit" value="Создать отчет" class="btn btn-primary" /></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4"><input type="submit" value="Отправить на почту" class="btn btn-primary" /></div>
|
||||
</div>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
@ -30,13 +38,5 @@
|
||||
</thead>
|
||||
<tbody></tbody>
|
||||
</table>
|
||||
<div class="row">
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4"><input type="submit" value="Создать отчет" class="btn btn-primary" /></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-8"></div>
|
||||
<div class="col-4"><input type="submit" value="Отправить на почту" class="btn btn-primary" /></div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
@ -70,6 +70,19 @@ namespace BankRestApi.Controllers
|
||||
throw;
|
||||
}
|
||||
}
|
||||
[HttpPost]
|
||||
public void SendTransfersWithdrawalsToEmail(ReportBindingModel model)
|
||||
{
|
||||
try
|
||||
{
|
||||
_logic.SendTransfersWithdrawalsToEmail(model);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.LogError(ex, "Ошибка сохранения переводов в ворд");
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public void SendOperationsRequestsToEmail(ReportBindingModel model)
|
||||
|
@ -1,6 +1,8 @@
|
||||
using BankBusinessLogic.BusinessLogic;
|
||||
using BankBusinessLogic.MailWorker;
|
||||
using BankBusinessLogic.OfficePackage;
|
||||
using BankBusinessLogic.OfficePackage.Implements;
|
||||
using BankContracts.BindingModels;
|
||||
using BankContracts.BusinessLogicsContracts;
|
||||
using BankContracts.StoragesContracts;
|
||||
using BankDatabaseImplement.Implements;
|
||||
@ -43,6 +45,8 @@ builder.Services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
|
||||
builder.Services.AddTransient<AbstractSaveToWord, SaveToWord>();
|
||||
builder.Services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
|
||||
|
||||
builder.Services.AddSingleton<AbstractMailWorker, MailKitWorker>();
|
||||
|
||||
builder.Services.AddLogging(option =>
|
||||
{
|
||||
option.SetMinimumLevel(LogLevel.Information);
|
||||
@ -63,6 +67,17 @@ 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())
|
||||
{
|
||||
|
@ -10,7 +10,6 @@
|
||||
"SmtpClientPort": "587",
|
||||
"PopHost": "pop.gmail.com",
|
||||
"PopPort": "995",
|
||||
|
||||
"MailLogin": "forlabspibd23@gmail.com",
|
||||
"MailPassword": "euby honk jvrl rrjj"
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user