diff --git a/LawFim/LawFirmBusinessLogic/OfficePackages/AbstractSaveToExcelClientsConsultation.cs b/LawFim/LawFirmBusinessLogic/OfficePackages/AbstractSaveToExcelClientsConsultation.cs index 6126c8b..434f874 100644 --- a/LawFim/LawFirmBusinessLogic/OfficePackages/AbstractSaveToExcelClientsConsultation.cs +++ b/LawFim/LawFirmBusinessLogic/OfficePackages/AbstractSaveToExcelClientsConsultation.cs @@ -35,13 +35,13 @@ namespace LawFirmBusinessLogic.OfficePackages StyleInfo = ExcelStyleInfoType.Text }); rowIndex++; - foreach (var hearing in ch.Hearings) + foreach (var consultation in ch.Consultations) { InsertCellInWorksheet(new ExcelCellParameters { ColumnName = "B", RowIndex = rowIndex, - Text = hearing.Court, + Text = consultation.Cost, StyleInfo = ExcelStyleInfoType.TextWithBroder }); @@ -49,7 +49,7 @@ namespace LawFirmBusinessLogic.OfficePackages { ColumnName = "C", RowIndex = rowIndex, - Text = hearing.HearingDate.ToString(), + Text = consultation.ConsultationDate.ToString(), StyleInfo = ExcelStyleInfoType.TextWithBroder }); diff --git a/LawFim/LawFirmBusinessLogic/OfficePackages/AbstractSaveToWordClientsConsultation.cs b/LawFim/LawFirmBusinessLogic/OfficePackages/AbstractSaveToWordClientsConsultation.cs index d9852f1..43f607e 100644 --- a/LawFim/LawFirmBusinessLogic/OfficePackages/AbstractSaveToWordClientsConsultation.cs +++ b/LawFim/LawFirmBusinessLogic/OfficePackages/AbstractSaveToWordClientsConsultation.cs @@ -21,7 +21,7 @@ namespace LawFirmBusinessLogic.OfficePackages }); foreach (var clientsConsultation in info.ClientsConsultation) { - foreach (var hearing in clientsConsultation.Hearings) + foreach (var consultation in clientsConsultation.Consultations) { @@ -29,8 +29,8 @@ namespace LawFirmBusinessLogic.OfficePackages { Texts = new List<(string, WordTextProperties)> { (clientsConsultation.ClientFIO, new WordTextProperties - { Size = "24", Bold=true}), (" " + hearing.Court, new WordTextProperties { Size = "24"}), - (" " + hearing.HearingDate.ToString(), new WordTextProperties { Size = "24"}) + { Size = "24", Bold=true}), (" " + consultation.Cost, new WordTextProperties { Size = "24"}), + (" " + consultation.ConsultationDate.ToString(), new WordTextProperties { Size = "24"}) }, TextProperties = new WordTextProperties { diff --git a/LawFim/LawFirmContracts/ViewModels/ReportClientsConsultationViewModel.cs b/LawFim/LawFirmContracts/ViewModels/ReportClientsConsultationViewModel.cs index 06b6c93..1d7ee92 100644 --- a/LawFim/LawFirmContracts/ViewModels/ReportClientsConsultationViewModel.cs +++ b/LawFim/LawFirmContracts/ViewModels/ReportClientsConsultationViewModel.cs @@ -5,6 +5,6 @@ public string ClientFIO { get; set; } = string.Empty; public double? ConsultationCost { get; set; } public DateTime? ConsultationDate { get; set; } - // public List<(DateTime ConsultationDate, string Cost)> Consultations { get; set; } = new(); + public List<(DateTime ConsultationDate, string Cost)> Consultations { get; set; } = new(); } } diff --git a/LawFim/LawFirmRestApi/Controllers/ReportClientsController.cs b/LawFim/LawFirmRestApi/Controllers/ReportClientsController.cs new file mode 100644 index 0000000..c78cc5b --- /dev/null +++ b/LawFim/LawFirmRestApi/Controllers/ReportClientsController.cs @@ -0,0 +1,102 @@ +using LawFirmBusinessLogic.MailWorker; +using LawFirmContracts.BindingModels.Mails; +using LawFirmContracts.BindingModels; +using LawFirmContracts.BusinessLogicContracts; +using LawFirmContracts.ViewModels; +using Microsoft.AspNetCore.Mvc; + +namespace LawFirmRestApi.Controllers +{ + [Route("api/[controller]/[action]")] + [ApiController] + public class ReportClientsController : Controller + { + private readonly ILogger _logger; + private readonly IReportLogic _reportLogic; + + private readonly AbstractMailWorker _mailWorker; + public ReportClientsController(ILogger logger, IReportLogic reportLogic, AbstractMailWorker abstractMailWorker) + { + _logger = logger; + _reportLogic = reportLogic; + _mailWorker = abstractMailWorker; + } + [HttpPost] + public void SaveClientsPdfFile(ReportBindingModel report) + { + try + { + _reportLogic.SaveClientsToPdfFile(new ReportBindingModel + { + DateFrom = report.DateFrom, + DateTo = report.DateTo, + FileName = "D:\\CourseWork\\pdfclientsreport.pdf", + ClientId = report.ClientId, + ExecutorId = report.ExecutorId, + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания отчета"); + throw; + } + } + [HttpPost] + public void SaveClientsWordFile(ReportBindingModel report) + { + try + { + _reportLogic.SaveClientsConsultationToWordFile(new ReportBindingModel { ExecutorId = report.ExecutorId, FileName = "D:\\CourseWork\\wordclientsreport.docx", ClientId = report.ClientId }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания отчета"); + throw; + } + } + [HttpPost] + public void SaveClientsExcelFile(ReportBindingModel report) + { + try + { + _reportLogic.SaveClientsConsultationToExcelFile(new ReportBindingModel { ExecutorId = report.ExecutorId, FileName = "D:\\CourseWork\\excelclientsreport.xlsx", ClientId = report.ClientId }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания отчета"); + throw; + } + } + [HttpPost] + public void MailSend(MailSendInfoBindingModel report) + { + try + { + _mailWorker.MailSendAsync(new MailSendInfoBindingModel + { + MailAddress = report.MailAddress, + Subject = report.Subject, + Text = report.Text + }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка отправки письма"); + throw; + } + } + [HttpGet] + public List GetClientsReport(DateTime dateFrom, DateTime dateTo, int executorId) + { + try + { + return _reportLogic.GetGetClients(new ReportBindingModel { DateFrom = dateFrom, DateTo = dateTo, ExecutorId = executorId }); + } + catch (Exception ex) + { + _logger.LogError(ex, "Ошибка создания отчета"); + throw; + } + } + } +} diff --git a/LawFim/LawFirmRestApi/Program.cs b/LawFim/LawFirmRestApi/Program.cs index 98b317c..674af47 100644 --- a/LawFim/LawFirmRestApi/Program.cs +++ b/LawFim/LawFirmRestApi/Program.cs @@ -1,8 +1,12 @@ using LawFirmBusinessLogic.BusinessLogics; +using LawFirmBusinessLogic.MailWorker; +using LawFirmBusinessLogic.OfficePackages.Implements; +using LawFirmBusinessLogic.OfficePackages; using LawFirmContracts.BusinessLogicContracts; using LawFirmContracts.StoragesContracts; using LawFirmDatabaseImplement.Implements; using Microsoft.OpenApi.Models; +using LawFirmContracts.BindingModels.Mails; var builder = WebApplication.CreateBuilder(args); @@ -26,6 +30,7 @@ builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); +builder.Services.AddTransient(); builder.Services.AddTransient(); builder.Services.AddTransient(); @@ -34,6 +39,13 @@ 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.AddControllers(); // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle @@ -45,6 +57,17 @@ builder.Services.AddSwaggerGen(c => c.SwaggerDoc("v1", new OpenApiInfo })); 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()) +}); // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment())