Почтааааааа

This commit is contained in:
Владимир Данилов 2024-05-30 01:20:47 +04:00
parent b0510098af
commit 305719faef
9 changed files with 42 additions and 56 deletions

View File

@ -7,6 +7,7 @@ using System.Net;
using System.Text;
using System.Threading.Tasks;
using VeterinaryClinicContracts.BindingModels;
using System.Net.Mime;
namespace VeterinaryClinicBusinessLogics.MailWorker
{
@ -34,10 +35,11 @@ namespace VeterinaryClinicBusinessLogics.MailWorker
objMailMessage.To.Add(new MailAddress(info.MailAddress));
objMailMessage.Subject = info.Subject;
objMailMessage.Body = info.Text;
objMailMessage.Attachments.Add(new Attachment(info.Path));
// Указываем параметры
objMailMessage.SubjectEncoding = Encoding.UTF8;
objMailMessage.BodyEncoding = Encoding.UTF8;
Attachment attachment = new Attachment("D:\\report.pdf", new ContentType(MediaTypeNames.Application.Pdf));
objMailMessage.Attachments.Add(attachment);
// Указываем параметры
objSmtpClient.UseDefaultCredentials = false;
objSmtpClient.EnableSsl = true;
objSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;

View File

@ -10,45 +10,10 @@ using System.Text;
var builder = WebApplication.CreateBuilder(args);
// Ðåãèñòðàöèÿ ïîñòàâùèêà êîäèðîâîê
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
builder.Logging.SetMinimumLevel(LogLevel.Trace);
//builder.Logging.AddLog4Net("log4net.config");
// Add services to the container.
builder.Services.AddTransient<IAnimalStorage, AnimalStorage>();
builder.Services.AddTransient<IMedicationStorage, MedicationStorage>();
builder.Services.AddTransient<IServiceStorage, ServiceStorage>();
builder.Services.AddTransient<IUserStorage, UserStorage>();
builder.Services.AddTransient<IVaccinationStorage, VaccinationStorage>();
builder.Services.AddTransient<IVisitStorage, VisitStorage>();
builder.Services.AddTransient<IAnimalLogic, AnimalLogic>();
builder.Services.AddTransient<IMedicationLogic, MedicationLogic>();
builder.Services.AddTransient<IServiceLogic, ServiceLogic>();
builder.Services.AddTransient<IUserLogic, UserLogic>();
builder.Services.AddTransient<IVaccinationLogic, VaccinationLogic>();
builder.Services.AddTransient<IVisitLogic, VisitLogic>();
builder.Services.AddTransient<IReportLogic, ReportLogic>();
builder.Services.AddTransient<AbstractSaveToWord, SaveToWord>();
builder.Services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
builder.Services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
builder.Services.AddSingleton<AbstractMailWorker, MailKitWorker>();
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo
{
Title = "VeterinaryClinicRestApi",
Version = "v1"
});
});
builder.Services.AddSwaggerGen();
var app = builder.Build();

View File

@ -61,7 +61,7 @@ namespace VeterinaryClinicWebApp.Controllers
throw new Exception("Необходимо авторизоваться!");
}
if (string.IsNullOrEmpty(type) || string.IsNullOrEmpty(breed) || age < 0 || medication == null)
if (string.IsNullOrEmpty(type) || string.IsNullOrEmpty(breed) || age < 0)
{
throw new Exception("Введены не все данные!");
}
@ -111,7 +111,7 @@ namespace VeterinaryClinicWebApp.Controllers
throw new Exception("Необходимо авторизоваться!");
}
if (string.IsNullOrEmpty(type) || string.IsNullOrEmpty(breed) || age < 0 || medication == null)
if (string.IsNullOrEmpty(type) || string.IsNullOrEmpty(breed) || age < 0)
{
throw new Exception("Введены не все данные!");
}

View File

@ -6,6 +6,7 @@ using VeterinaryClinicContracts.BusinessLogicsContracts;
using VeterinaryClinicContracts.SearchModels;
using VeterinaryClinicDataModels.Enums;
using VeterinaryClinicWebApp.Models;
using static System.Runtime.InteropServices.JavaScript.JSType;
namespace VeterinaryClinicWebApp.Controllers;
@ -288,29 +289,23 @@ public class HomeController : Controller
/// Îòïðàâèòü ïî ïî÷òå îò÷¸ò
/// </summary>
[HttpPost]
public void SendReport(IFormFile fileUpload)
public void SendReport(DateTime dateFrom, DateTime dateTo)
{
if (APIClient.User == null)
{
throw new Exception("Íåîáõîäèìî àâòîðèçîâàòüñÿ!");
}
if (fileUpload == null || fileUpload.Length <= 0)
if (dateFrom == DateTime.MinValue || dateTo == DateTime.MinValue)
{
throw new Exception("Ôàéë íå âûáğàí èëè ïóñò!");
throw new Exception("Ââåäåíû íå âñå äàííûå!");
}
// Ïóòü äî ôàéëà
var uploadPath = @"D:\";
var fileName = Path.GetFileName(fileUpload.FileName);
var fullPath = Path.Combine(uploadPath, fileName);
_mailLogic.MailSendAsync(new MailSendInfoBindingModel
{
MailAddress = APIClient.User.Email,
Subject = $"{fileName.Split('.')[0]}",
Text = $"Îò÷¸ò îòïğàâëåí {DateTime.Now}",
Path = fullPath
Subject = $"Îò÷åò {APIClient.User.FullName}",
Text = $"Îò÷åò ñ {dateFrom.ToShortDateString()} ïî {dateTo.ToShortDateString()}"
});
Response.Redirect("/Home/Reports");

View File

@ -69,7 +69,7 @@ namespace VeterinaryClinicWebApp.Controllers
throw new Exception("Необходимо авторизоваться!");
}
if (dateVisit == DateTime.MinValue || service == null)
if (dateVisit == DateTime.MinValue)
{
throw new Exception("Введены не все данные!");
}
@ -117,7 +117,7 @@ namespace VeterinaryClinicWebApp.Controllers
throw new Exception("Необходимо авторизоваться!");
}
if (dateVisit == DateTime.MinValue || service == null)
if (dateVisit == DateTime.MinValue)
{
throw new Exception("Введены не все данные!");
}

View File

@ -7,6 +7,7 @@ using VeterinaryClinicDatabaseImplement.Implements;
using VeterinaryClinicWebApp;
using VeterinaryClinicBusinessLogics.MailWorker;
using System.Text;
using VeterinaryClinicContracts.BindingModels;
var builder = WebApplication.CreateBuilder(args);
@ -47,6 +48,18 @@ builder.Services.AddSession(options =>
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())
});
APIClient.Connect(builder.Configuration);
// Configure the HTTP request pipeline.

View File

@ -57,7 +57,7 @@
}
else
{
<p>Нет назначенных лекарств</p>
<p>Нет назначенных медикаментов</p>
}
</td>
<td>

View File

@ -41,11 +41,16 @@
</div>
<!-- Отправить отчет на почту -->
<div class="d-flex">
@* <div class="d-flex">
<label for="fileUpload" class="d-block"></label>
<input type="file" id="fileUpload" name="fileUpload" class="form-control-file d-inline-block w-auto">
<button type="submit" class="btn btn-primary" formaction="@Url.Action("SendReport", "Home")">Отправить отчет на почту</button>
</div>
</div> *@
<form asp-controller="Home" asp-action="SendReport" method="post">
<input type="hidden" name="dateFrom" readonly value="@(ViewBag.DateFrom)" />
<input type="hidden" name="dateTo" readonly value="@(ViewBag.DateTo)" />
<button type="submit" class="btn btn-primary">Отправить отчет на почту</button>
</form>
<!-- Вывести отчет на форму -->
<div class="text-center">

View File

@ -6,6 +6,12 @@
}
},
"AllowedHosts": "*",
"SmtpClientHost": "smtp.gmail.com",
"SmtpClientPort": "587",
"PopHost": "pop.gmail.com",
"PopPort": "995",
"MailLogin": "hugolyter@gmail.com",
"MailPassword": "erpt vlrs aogd xoun",
"IPAddress": "http://localhost:5159/"
}