Compare commits

..

No commits in common. "85c1a88c19ca19002532b7581092c997d35c6f8f" and "a7b6812a9ffa41d22b423f9f982672612b2d2ec9" have entirely different histories.

28 changed files with 45 additions and 249 deletions

View File

@ -8,7 +8,6 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="DocumentFormat.OpenXml" Version="2.20.0" /> <PackageReference Include="DocumentFormat.OpenXml" Version="2.20.0" />
<PackageReference Include="MailKit" Version="4.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" /> <PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="7.0.0" />
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.15" /> <PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.15" />
</ItemGroup> </ItemGroup>

View File

@ -8,8 +8,8 @@ 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 BankBusinessLogic.OfficePackage; using ConfectioneryBusinessLogic.OfficePackage;
using BankBusinessLogic.OfficePackage.HelperModels; using ConfectioneryBusinessLogic.OfficePackage.HelperModels;
namespace BankBusinessLogic.BusinessLogics namespace BankBusinessLogic.BusinessLogics
{ {

View File

@ -1,66 +0,0 @@
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);
}
}

View File

@ -1,47 +0,0 @@
using BankContracts.BindingModels;
using BankContracts.BusinessLogicsContracts;
using MailKit.Net.Pop3;
using MailKit.Security;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Mail;
using System.Net;
using System.Text;
using System.Threading.Tasks;
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;
objMailMessage.Attachments.Add(new Attachment(info.Attachment, info.FileName, "application/pdf"));
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;
}
}
}
}

View File

@ -1,12 +1,12 @@
using BankBusinessLogic.OfficePackage.HelperEnums; using ConfectioneryBusinessLogic.OfficePackage.HelperEnums;
using BankBusinessLogic.OfficePackage.HelperModels; using ConfectioneryBusinessLogic.OfficePackage.HelperModels;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace BankBusinessLogic.OfficePackage namespace ConfectioneryBusinessLogic.OfficePackage
{ {
public abstract class AbstractSaveToExcel public abstract class AbstractSaveToExcel
{ {

View File

@ -1,12 +1,12 @@
using BankBusinessLogic.OfficePackage.HelperEnums; using ConfectioneryBusinessLogic.OfficePackage.HelperEnums;
using BankBusinessLogic.OfficePackage.HelperModels; using ConfectioneryBusinessLogic.OfficePackage.HelperModels;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace BankBusinessLogic.OfficePackage namespace ConfectioneryBusinessLogic.OfficePackage
{ {
public abstract class AbstractSaveToPdf public abstract class AbstractSaveToPdf
{ {

View File

@ -1,12 +1,12 @@
using BankBusinessLogic.OfficePackage.HelperEnums; using ConfectioneryBusinessLogic.OfficePackage.HelperEnums;
using BankBusinessLogic.OfficePackage.HelperModels; using ConfectioneryBusinessLogic.OfficePackage.HelperModels;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace BankBusinessLogic.OfficePackage namespace ConfectioneryBusinessLogic.OfficePackage
{ {
public abstract class AbstractSaveToWord public abstract class AbstractSaveToWord
{ {

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace BankBusinessLogic.OfficePackage.HelperEnums namespace ConfectioneryBusinessLogic.OfficePackage.HelperEnums
{ {
public enum ExcelStyleInfoType public enum ExcelStyleInfoType
{ {

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace BankBusinessLogic.OfficePackage.HelperEnums namespace ConfectioneryBusinessLogic.OfficePackage.HelperEnums
{ {
public enum PdfParagraphAlignmentType public enum PdfParagraphAlignmentType
{ {

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace BankBusinessLogic.OfficePackage.HelperEnums namespace ConfectioneryBusinessLogic.OfficePackage.HelperEnums
{ {
public enum WordJustificationType public enum WordJustificationType
{ {

View File

@ -1,11 +1,11 @@
using BankBusinessLogic.OfficePackage.HelperEnums; using ConfectioneryBusinessLogic.OfficePackage.HelperEnums;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace BankBusinessLogic.OfficePackage.HelperModels namespace ConfectioneryBusinessLogic.OfficePackage.HelperModels
{ {
public class ExcelCellParameters public class ExcelCellParameters
{ {

View File

@ -5,7 +5,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace BankBusinessLogic.OfficePackage.HelperModels namespace ConfectioneryBusinessLogic.OfficePackage.HelperModels
{ {
public class ExcelInfo public class ExcelInfo
{ {

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace BankBusinessLogic.OfficePackage.HelperModels namespace ConfectioneryBusinessLogic.OfficePackage.HelperModels
{ {
public class ExcelMergeParameters public class ExcelMergeParameters
{ {

View File

@ -5,7 +5,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace BankBusinessLogic.OfficePackage.HelperModels namespace ConfectioneryBusinessLogic.OfficePackage.HelperModels
{ {
public class PdfInfo public class PdfInfo
{ {

View File

@ -1,11 +1,11 @@
using BankBusinessLogic.OfficePackage.HelperEnums; using ConfectioneryBusinessLogic.OfficePackage.HelperEnums;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace BankBusinessLogic.OfficePackage.HelperModels namespace ConfectioneryBusinessLogic.OfficePackage.HelperModels
{ {
public class PdfParagraph public class PdfParagraph
{ {

View File

@ -1,11 +1,11 @@
using BankBusinessLogic.OfficePackage.HelperEnums; using ConfectioneryBusinessLogic.OfficePackage.HelperEnums;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace BankBusinessLogic.OfficePackage.HelperModels namespace ConfectioneryBusinessLogic.OfficePackage.HelperModels
{ {
public class PdfRowParameters public class PdfRowParameters
{ {

View File

@ -5,7 +5,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace BankBusinessLogic.OfficePackage.HelperModels namespace ConfectioneryBusinessLogic.OfficePackage.HelperModels
{ {
public class WordInfo public class WordInfo
{ {

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace BankBusinessLogic.OfficePackage.HelperModels namespace ConfectioneryBusinessLogic.OfficePackage.HelperModels
{ {
public class WordParagraph public class WordParagraph
{ {

View File

@ -1,11 +1,11 @@
using BankBusinessLogic.OfficePackage.HelperEnums; using ConfectioneryBusinessLogic.OfficePackage.HelperEnums;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace BankBusinessLogic.OfficePackage.HelperModels namespace ConfectioneryBusinessLogic.OfficePackage.HelperModels
{ {
public class WordTextProperties public class WordTextProperties
{ {

View File

@ -1,5 +1,5 @@
using BankBusinessLogic.OfficePackage.HelperEnums; using ConfectioneryBusinessLogic.OfficePackage.HelperEnums;
using BankBusinessLogic.OfficePackage.HelperModels; using ConfectioneryBusinessLogic.OfficePackage.HelperModels;
using DocumentFormat.OpenXml.Office2010.Excel; using DocumentFormat.OpenXml.Office2010.Excel;
using DocumentFormat.OpenXml.Office2013.Excel; using DocumentFormat.OpenXml.Office2013.Excel;
using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Packaging;
@ -11,7 +11,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace BankBusinessLogic.OfficePackage.Implements namespace ConfectioneryBusinessLogic.OfficePackage.Implements
{ {
public class SaveToExcel : AbstractSaveToExcel public class SaveToExcel : AbstractSaveToExcel
{ {

View File

@ -1,5 +1,5 @@
using BankBusinessLogic.OfficePackage.HelperEnums; using ConfectioneryBusinessLogic.OfficePackage.HelperEnums;
using BankBusinessLogic.OfficePackage.HelperModels; using ConfectioneryBusinessLogic.OfficePackage.HelperModels;
using MigraDoc.DocumentObjectModel; using MigraDoc.DocumentObjectModel;
using MigraDoc.DocumentObjectModel.Tables; using MigraDoc.DocumentObjectModel.Tables;
using MigraDoc.Rendering; using MigraDoc.Rendering;
@ -9,7 +9,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace BankBusinessLogic.OfficePackage.Implements namespace ConfectioneryBusinessLogic.OfficePackage.Implements
{ {
public class SaveToPdf : AbstractSaveToPdf public class SaveToPdf : AbstractSaveToPdf
{ {

View File

@ -1,5 +1,5 @@
using BankBusinessLogic.OfficePackage.HelperEnums; using ConfectioneryBusinessLogic.OfficePackage.HelperEnums;
using BankBusinessLogic.OfficePackage.HelperModels; using ConfectioneryBusinessLogic.OfficePackage.HelperModels;
using DocumentFormat.OpenXml.Packaging; using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing; using DocumentFormat.OpenXml.Wordprocessing;
using DocumentFormat.OpenXml; using DocumentFormat.OpenXml;
@ -9,7 +9,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace BankBusinessLogic.OfficePackage.Implements namespace ConfectioneryBusinessLogic.OfficePackage.Implements
{ {
public class SaveToWord : AbstractSaveToWord public class SaveToWord : AbstractSaveToWord
{ {

View File

@ -1,23 +0,0 @@
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; }
}
}

View File

@ -1,18 +0,0 @@
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;
public MemoryStream Attachment { get; set; } = new MemoryStream();
public string FileName { get; set; } = string.Empty;
}
}

View File

@ -1,11 +1,9 @@
using BankBusinessLogic.MailWorker; using BankContracts.BindingModels;
using BankContracts.BindingModels;
using BankContracts.BusinessLogicsContracts; using BankContracts.BusinessLogicsContracts;
using BankContracts.SearchModels; using BankContracts.SearchModels;
using BankContracts.ViewModels; using BankContracts.ViewModels;
using BankDatabaseImplement.Models; using BankDatabaseImplement.Models;
using BankDataModels.Models; using BankDataModels.Models;
using MailKit;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Metadata;
using OperatorApp.Models; using OperatorApp.Models;
@ -21,9 +19,8 @@ namespace OperatorApp.Controllers
private readonly ITransferLogic _transferLogic; private readonly ITransferLogic _transferLogic;
private readonly IOperatorLogic _operatorLogic; private readonly IOperatorLogic _operatorLogic;
private readonly IReportLogic _reportLogic; private readonly IReportLogic _reportLogic;
private readonly AbstractMailWorker _mailWorker;
public HomeController(ILogger<HomeController> logger, IDealLogic dealLogic, IPaymentLogic paymentLogic, ITransferLogic transferLogic, IOperatorLogic operatorLogic, IReportLogic reportLogic, AbstractMailWorker mailWorker) public HomeController(ILogger<HomeController> logger, IDealLogic dealLogic, IPaymentLogic paymentLogic, ITransferLogic transferLogic, IOperatorLogic operatorLogic, IReportLogic reportLogic)
{ {
_logger = logger; _logger = logger;
_dealLogic = dealLogic; _dealLogic = dealLogic;
@ -31,7 +28,6 @@ namespace OperatorApp.Controllers
_transferLogic = transferLogic; _transferLogic = transferLogic;
_operatorLogic = operatorLogic; _operatorLogic = operatorLogic;
_reportLogic = reportLogic; _reportLogic = reportLogic;
_mailWorker = mailWorker;
} }
public IActionResult Index() public IActionResult Index()
@ -233,8 +229,7 @@ namespace OperatorApp.Controllers
{ {
if (APIClient.Operator == null) if (APIClient.Operator == null)
{ {
Response.WriteAsync($"<script language=\"javascript\">alert('You need to login!');</script>"); throw new Exception("Вы как суда попали? Суда вход только авторизованным");
Response.Redirect("/Home/Enter");
} }
ViewBag.Payments = _paymentLogic.ReadList(new PaymentSearchModel { OperatorId = APIClient.Operator.Id }); ViewBag.Payments = _paymentLogic.ReadList(new PaymentSearchModel { OperatorId = APIClient.Operator.Id });
return View(); return View();
@ -274,26 +269,10 @@ namespace OperatorApp.Controllers
return View(new ReportBindingModel()); return View(new ReportBindingModel());
} }
[HttpPost] [HttpPost]
public void TransfersReport(DateTime dateFrom, DateTime dateTo) public IActionResult TransfersReport(DateTime dateFrom, DateTime dateTo)
{ {
MemoryStream report = _reportLogic.SaveTransferPurchaseToPDF(new ReportBindingModel { DateFrom = dateFrom, DateTo = dateTo }); MemoryStream report = _reportLogic.SaveTransferPurchaseToPDF(new ReportBindingModel { DateFrom = dateFrom, DateTo = dateTo });
try return File(report, "application/pdf", "test.pdf");
{
_mailWorker.MailSendAsync(new MailSendInfoBindingModel
{
Subject = "Отчёт о закупках",
Text = "От банка \"Вы банкрот\"",
MailAddress = "",
FileName = "test.pdf",
Attachment = report
});
Response.Redirect("/");
}
catch (Exception ex)
{
Response.WriteAsync($"<script language=\"javascript\">alert('{ex.Message}');</script>");
Response.Redirect("/");
}
} }
} }
} }

View File

@ -2,11 +2,9 @@ using BankBusinessLogic.BusinessLogics;
using BankContracts.BusinessLogicsContracts; using BankContracts.BusinessLogicsContracts;
using BankContracts.StoragesContracts; using BankContracts.StoragesContracts;
using BankDatabaseImplement.Implements; using BankDatabaseImplement.Implements;
using BankBusinessLogic.OfficePackage; using ConfectioneryBusinessLogic.OfficePackage;
using BankBusinessLogic.OfficePackage.Implements; using ConfectioneryBusinessLogic.OfficePackage.Implements;
using OperatorApp; using OperatorApp;
using BankBusinessLogic.MailWorker;
using BankContracts.BindingModels;
var builder = WebApplication.CreateBuilder(args); var builder = WebApplication.CreateBuilder(args);
@ -24,7 +22,6 @@ builder.Services.AddTransient<ICurrencyStorage, CurrencyStorage>();
builder.Services.AddTransient<AbstractSaveToWord, SaveToWord>(); builder.Services.AddTransient<AbstractSaveToWord, SaveToWord>();
builder.Services.AddTransient<AbstractSaveToExcel, SaveToExcel>(); builder.Services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
builder.Services.AddTransient<AbstractSaveToPdf, SaveToPdf>(); builder.Services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
builder.Services.AddSingleton<AbstractMailWorker, MailKitWorker>();
builder.Services.AddTransient<IDealLogic, DealLogic>(); builder.Services.AddTransient<IDealLogic, DealLogic>();
builder.Services.AddTransient<IPaymentLogic, PaymentLogic>(); builder.Services.AddTransient<IPaymentLogic, PaymentLogic>();
@ -34,25 +31,6 @@ builder.Services.AddTransient<IReportLogic, ReportLogic>();
var app = builder.Build(); var app = builder.Build();
try
{
var mailSender = app.Services.GetService<AbstractMailWorker>();
mailSender?.MailConfig(new MailConfigBindingModel
{
MailLogin = builder.Configuration["MailLogin"] ?? string.Empty,
MailPassword = builder.Configuration["MailPassword"] ?? string.Empty,
SmtpClientHost = builder.Configuration["SmtpClientHost"] ?? string.Empty,
SmtpClientPort = Convert.ToInt32(builder.Configuration["SmtpClientPort"]),
PopHost = builder.Configuration["PopHost"] ?? string.Empty,
PopPort = Convert.ToInt32(builder.Configuration["PopPort"])
});
}
catch (Exception ex)
{
var logger = app.Services.GetService<ILogger>();
logger?.LogError(ex, "Îøèáêà ðàáîòû ñ ïî÷òîé");
}
APIClient.Connect(builder.Configuration); APIClient.Connect(builder.Configuration);
// Configure the HTTP request pipeline. // Configure the HTTP request pipeline.

View File

@ -1,5 +1,5 @@
@{ @{
ViewData["Title"] = "CreateTransfer"; ViewData["Title"] = "CreatePayment";
} }
<div class="text-center"> <div class="text-center">
<h2 class="display-4">Создание зачисления</h2> <h2 class="display-4">Создание зачисления</h2>

View File

@ -6,11 +6,5 @@
} }
}, },
"AllowedHosts": "*", "AllowedHosts": "*",
"IPAddress": "http://localhost:5225", "IPAddress": "http://localhost:5225"
"SmtpClientHost": "smtp.gmail.com",
"SmtpClientPort": "587",
"PopHost": "pop.gmail.com",
"PopPort": "995",
"MailLogin": "rpplab7@gmail.com",
"MailPassword": "edjc dmsf pqne gxwy"
} }