diff --git a/VeterinaryClinic/VeterinaryClinicBusinessLogics/MailWorker/MailKitWorker.cs b/VeterinaryClinic/VeterinaryClinicBusinessLogics/MailWorker/MailKitWorker.cs index 568146d..ed9b95b 100644 --- a/VeterinaryClinic/VeterinaryClinicBusinessLogics/MailWorker/MailKitWorker.cs +++ b/VeterinaryClinic/VeterinaryClinicBusinessLogics/MailWorker/MailKitWorker.cs @@ -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; diff --git a/VeterinaryClinic/VeterinaryClinicRestApi/Program.cs b/VeterinaryClinic/VeterinaryClinicRestApi/Program.cs index bb685de..12d4f77 100644 --- a/VeterinaryClinic/VeterinaryClinicRestApi/Program.cs +++ b/VeterinaryClinic/VeterinaryClinicRestApi/Program.cs @@ -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(); -builder.Services.AddTransient(); -builder.Services.AddTransient(); -builder.Services.AddTransient(); -builder.Services.AddTransient(); -builder.Services.AddTransient(); - -builder.Services.AddTransient(); -builder.Services.AddTransient(); -builder.Services.AddTransient(); -builder.Services.AddTransient(); -builder.Services.AddTransient(); -builder.Services.AddTransient(); - -builder.Services.AddTransient(); -builder.Services.AddTransient(); -builder.Services.AddTransient(); -builder.Services.AddTransient(); -builder.Services.AddSingleton(); - 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(); diff --git a/VeterinaryClinic/VeterinaryClinicWebApp/Controllers/AnimalController.cs b/VeterinaryClinic/VeterinaryClinicWebApp/Controllers/AnimalController.cs index e9f115f..752d46d 100644 --- a/VeterinaryClinic/VeterinaryClinicWebApp/Controllers/AnimalController.cs +++ b/VeterinaryClinic/VeterinaryClinicWebApp/Controllers/AnimalController.cs @@ -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("Введены не все данные!"); } diff --git a/VeterinaryClinic/VeterinaryClinicWebApp/Controllers/HomeController.cs b/VeterinaryClinic/VeterinaryClinicWebApp/Controllers/HomeController.cs index 990ecb7..bf6b3cc 100644 --- a/VeterinaryClinic/VeterinaryClinicWebApp/Controllers/HomeController.cs +++ b/VeterinaryClinic/VeterinaryClinicWebApp/Controllers/HomeController.cs @@ -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 /// /// [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"); diff --git a/VeterinaryClinic/VeterinaryClinicWebApp/Controllers/VisitController.cs b/VeterinaryClinic/VeterinaryClinicWebApp/Controllers/VisitController.cs index f0ead43..e6b5ba1 100644 --- a/VeterinaryClinic/VeterinaryClinicWebApp/Controllers/VisitController.cs +++ b/VeterinaryClinic/VeterinaryClinicWebApp/Controllers/VisitController.cs @@ -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("Введены не все данные!"); } diff --git a/VeterinaryClinic/VeterinaryClinicWebApp/Program.cs b/VeterinaryClinic/VeterinaryClinicWebApp/Program.cs index 5513c0c..a29c6ec 100644 --- a/VeterinaryClinic/VeterinaryClinicWebApp/Program.cs +++ b/VeterinaryClinic/VeterinaryClinicWebApp/Program.cs @@ -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(); + +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. diff --git a/VeterinaryClinic/VeterinaryClinicWebApp/Views/Animal/Animals.cshtml b/VeterinaryClinic/VeterinaryClinicWebApp/Views/Animal/Animals.cshtml index cf2a27f..f770959 100644 --- a/VeterinaryClinic/VeterinaryClinicWebApp/Views/Animal/Animals.cshtml +++ b/VeterinaryClinic/VeterinaryClinicWebApp/Views/Animal/Animals.cshtml @@ -57,7 +57,7 @@ } else { -

Нет назначенных лекарств

+

Нет назначенных медикаментов

} diff --git a/VeterinaryClinic/VeterinaryClinicWebApp/Views/Home/Reports.cshtml b/VeterinaryClinic/VeterinaryClinicWebApp/Views/Home/Reports.cshtml index f949d62..7ae5e72 100644 --- a/VeterinaryClinic/VeterinaryClinicWebApp/Views/Home/Reports.cshtml +++ b/VeterinaryClinic/VeterinaryClinicWebApp/Views/Home/Reports.cshtml @@ -41,11 +41,16 @@ -
+ @*
-
+
*@ +
+ + + +
diff --git a/VeterinaryClinic/VeterinaryClinicWebApp/appsettings.json b/VeterinaryClinic/VeterinaryClinicWebApp/appsettings.json index 238f900..3cdac55 100644 --- a/VeterinaryClinic/VeterinaryClinicWebApp/appsettings.json +++ b/VeterinaryClinic/VeterinaryClinicWebApp/appsettings.json @@ -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/" }