Почта работает
This commit is contained in:
parent
b42564d7f7
commit
616ab0c5c4
@ -1,5 +1,6 @@
|
|||||||
using HostrelHeadwaiterApp.Models;
|
using HostrelHeadwaiterApp.Models;
|
||||||
using HotelContracts.BindingModels;
|
using HotelContracts.BindingModels;
|
||||||
|
using HotelContracts.BusinessLogicsContracts;
|
||||||
using HotelContracts.SearchModels;
|
using HotelContracts.SearchModels;
|
||||||
using HotelContracts.ViewModels;
|
using HotelContracts.ViewModels;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
@ -10,10 +11,12 @@ namespace HostrelHeadwaiterApp.Controllers
|
|||||||
public class HomeController : Controller
|
public class HomeController : Controller
|
||||||
{
|
{
|
||||||
private readonly ILogger<HomeController> _logger;
|
private readonly ILogger<HomeController> _logger;
|
||||||
|
private readonly IReportHeadwaiterLogic _report;
|
||||||
|
|
||||||
public HomeController(ILogger<HomeController> logger)
|
public HomeController(ILogger<HomeController> logger, IReportHeadwaiterLogic report)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
|
_report = report;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IActionResult CreateDinner()
|
public IActionResult CreateDinner()
|
||||||
@ -627,6 +630,11 @@ namespace HostrelHeadwaiterApp.Controllers
|
|||||||
return new PhysicalFileResult("E:\\ReportsCourseWork\\excelfile.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
return new PhysicalFileResult("E:\\ReportsCourseWork\\excelfile.xlsx", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IActionResult GetPdfFile()
|
||||||
|
{
|
||||||
|
return new PhysicalFileResult("E:\\ReportsCourseWork\\pdffile.pdf", "application/pdf");
|
||||||
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public IActionResult ListDinnersToPdfFile()
|
public IActionResult ListDinnersToPdfFile()
|
||||||
{
|
{
|
||||||
@ -634,26 +642,82 @@ namespace HostrelHeadwaiterApp.Controllers
|
|||||||
{
|
{
|
||||||
return Redirect("~/Home/Enter");
|
return Redirect("~/Home/Enter");
|
||||||
}
|
}
|
||||||
|
return View("ListDinnersToPdfFile");
|
||||||
return View();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpPost]
|
[HttpPost]
|
||||||
public void ListDinnersToPdfFile(DateTime dateFrom, DateTime dateTo)
|
public void ListDinnersToPdfFile(DateTime dateFrom, DateTime dateTo, string headwaiterEmail)
|
||||||
{
|
{
|
||||||
if (APIClient.Headwaiter == null)
|
if (APIClient.Headwaiter == null)
|
||||||
{
|
{
|
||||||
throw new Exception("Не авторизованы");
|
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||||
}
|
}
|
||||||
|
if (string.IsNullOrEmpty(headwaiterEmail))
|
||||||
APIClient.PostRequest("api/Report/CreateHeadwaiterReportToPdfFile", new ReportHeadwaiterBindingModel()
|
{
|
||||||
|
throw new Exception("Email пуст");
|
||||||
|
}
|
||||||
|
APIClient.PostRequest("api/report/CreateHeadwaiterReportToPdfFile", new ReportHeadwaiterBindingModel
|
||||||
{
|
{
|
||||||
DateFrom = dateFrom,
|
DateFrom = dateFrom,
|
||||||
DateTo = dateTo,
|
DateTo = dateTo,
|
||||||
HeadwaiterId = APIClient.Headwaiter.Id
|
HeadwaiterId = APIClient.Headwaiter.Id
|
||||||
});
|
});
|
||||||
|
APIClient.PostRequest("api/report/SendPdfToMail", new MailSendInfoBindingModel
|
||||||
|
{
|
||||||
|
MailAddress = headwaiterEmail,
|
||||||
|
Subject = "Отчет по участникам (pdf)",
|
||||||
|
Text = "Отчет по участникам с " + dateFrom.ToShortDateString() + " до " + dateTo.ToShortDateString()
|
||||||
|
});
|
||||||
Response.Redirect("ListDinnersToPdfFile");
|
Response.Redirect("ListDinnersToPdfFile");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[HttpGet]
|
||||||
|
public string GetDinnersReport(DateTime dateFrom, DateTime dateTo)
|
||||||
|
{
|
||||||
|
if (APIClient.Headwaiter == null)
|
||||||
|
{
|
||||||
|
throw new Exception("Вы как суда попали? Суда вход только авторизованным");
|
||||||
|
}
|
||||||
|
List<ReportDinnersViewModel> result;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = _report.GetDinners(new ReportHeadwaiterBindingModel
|
||||||
|
{
|
||||||
|
HeadwaiterId = APIClient.Headwaiter.Id,
|
||||||
|
DateFrom = dateFrom,
|
||||||
|
DateTo = dateTo
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
_logger.LogError(ex, "Ошибка создания отчета");
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
string table = "";
|
||||||
|
foreach (var report in result)
|
||||||
|
{
|
||||||
|
table += $"<h2>{report.DinnerName}</h2>";
|
||||||
|
table += $"<table>";
|
||||||
|
table += "<thead>";
|
||||||
|
table += "<tr>";
|
||||||
|
table += $"<th>Имя комнаты</th>";
|
||||||
|
table += $"<th>Цена комнаты</th>";
|
||||||
|
table += $"<th>Название зала</th>";
|
||||||
|
table += $"<th>Дата броинирования</th>";
|
||||||
|
table += "</tr>";
|
||||||
|
table += "</thead>";
|
||||||
|
table += "<tbody>";
|
||||||
|
table += "<tr>";
|
||||||
|
table += $"<td>{report.RoomName}</td>";
|
||||||
|
table += $"<td>{report.RoomPrice}</td>";
|
||||||
|
table += $"<td>{report.NameHall}</td>";
|
||||||
|
table += $"<td>{report.BookingDate}</td>";
|
||||||
|
table += "</tr>";
|
||||||
|
table += "</tbody>";
|
||||||
|
table += "</table>";
|
||||||
|
}
|
||||||
|
//table += $"<h3 style=\"align-self: self-start;\">Итого: {result.Item2}</h3>";
|
||||||
|
return table;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -7,12 +7,15 @@
|
|||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Microsoft.AspNet.WebPages" Version="3.2.9" />
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.15" />
|
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.15" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\HotelBusinessLogic\HotelBusinessLogic.csproj" />
|
||||||
<ProjectReference Include="..\HotelContracts\HotelContracts.csproj" />
|
<ProjectReference Include="..\HotelContracts\HotelContracts.csproj" />
|
||||||
|
<ProjectReference Include="..\HotelDataBaseImplement\HotelDataBaseImplement.csproj" />
|
||||||
<ProjectReference Include="..\HotelDataModels\HotelDataModels.csproj" />
|
<ProjectReference Include="..\HotelDataModels\HotelDataModels.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
@ -1,6 +1,19 @@
|
|||||||
using HostrelHeadwaiterApp;
|
using HostrelHeadwaiterApp;
|
||||||
|
using HotelBusinessLogic.BusinessLogics;
|
||||||
|
using HotelBusinessLogic.OfficePackage;
|
||||||
|
using HotelBusinessLogic.OfficePackage.Implements;
|
||||||
|
using HotelContracts.BusinessLogicsContracts;
|
||||||
|
using HotelContracts.StoragesContracts;
|
||||||
|
using HotelDataBaseImplement.Implemets;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
builder.Services.AddTransient<IReportHeadwaiterLogic, ReportLogicHeadwaiter>();
|
||||||
|
builder.Services.AddTransient<IDinnerStorage, DinnerStorage>();
|
||||||
|
builder.Services.AddTransient<IConferenceBookingStorage, ConferenceBookingStorage>();
|
||||||
|
builder.Services.AddTransient<IRoomStorage, RoomStorage>();
|
||||||
|
builder.Services.AddTransient<AbstractSaveToExcelHeadwaiter, SaveToExcelHeadwaiter>();
|
||||||
|
builder.Services.AddTransient<AbstractSaveToPdfHeadwaiter, SaveToPdfHeadwaiter>();
|
||||||
|
builder.Services.AddTransient<AbstractSaveToWordHeadwaitre, SaveToWordHeadwaiter>();
|
||||||
|
|
||||||
// Add services to the container.
|
// Add services to the container.
|
||||||
builder.Services.AddControllersWithViews();
|
builder.Services.AddControllersWithViews();
|
||||||
@ -9,12 +22,12 @@ var app = builder.Build();
|
|||||||
APIClient.Connect(builder.Configuration);
|
APIClient.Connect(builder.Configuration);
|
||||||
|
|
||||||
// Configure the HTTP request pipeline.
|
// Configure the HTTP request pipeline.
|
||||||
if (!app.Environment.IsDevelopment())
|
//if (!app.Environment.IsDevelopment())
|
||||||
{
|
//{
|
||||||
app.UseExceptionHandler("/Home/Error");
|
app.UseExceptionHandler("/Home/Error");
|
||||||
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
|
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
|
||||||
app.UseHsts();
|
app.UseHsts();
|
||||||
}
|
//}
|
||||||
|
|
||||||
app.UseHttpsRedirection();
|
app.UseHttpsRedirection();
|
||||||
app.UseStaticFiles();
|
app.UseStaticFiles();
|
||||||
|
@ -1,19 +1,18 @@
|
|||||||
@{
|
@using HotelContracts.ViewModels
|
||||||
ViewData["Title"] = "ListDinnersToPdf";
|
|
||||||
|
@{
|
||||||
|
ViewData["Title"] = "ListDinnersToPdfFile";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
<div class="text-center">
|
<div class="text-center">
|
||||||
<h2
|
<h2 class="u-text u-text-custom-color-1 u-text-default u-text-1"> Отчет по участникам за период </h2>
|
||||||
class="u-text u-text-custom-color-1 u-text-default u-text-1"
|
|
||||||
>
|
|
||||||
Создание отчета по участникам за период
|
|
||||||
</h2>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="text-center">
|
||||||
|
@{
|
||||||
<form method="post">
|
<form method="post">
|
||||||
<div class="u-form-group u-form-name u-label-top">
|
<div class="u-form-email u-form-group u-label-top">
|
||||||
<label class="u-label u-text-custom-color-1 u-label-1">Дата начала периода:</label>
|
<label class="u-label u-text-custom-color-1 u-label-2" for="dateFrom">Начало периода</label>
|
||||||
<input
|
<input
|
||||||
type="datetime-local"
|
type="datetime-local"
|
||||||
placeholder="Выберите дату начала периода"
|
placeholder="Выберите дату начала периода"
|
||||||
@ -21,15 +20,54 @@
|
|||||||
class="u-input u-input-rectangle"/>
|
class="u-input u-input-rectangle"/>
|
||||||
</div>
|
</div>
|
||||||
<div class="u-form-email u-form-group u-label-top">
|
<div class="u-form-email u-form-group u-label-top">
|
||||||
<label class="u-label u-text-custom-color-1 u-label-2">Дата конца периода:</label>
|
<label class="u-label u-text-custom-color-1 u-label-2" for="dateTo">Окончание периода</label>
|
||||||
<input
|
<input
|
||||||
type="datetime-local"
|
type="datetime-local"
|
||||||
placeholder="Выберите дату конца периода"
|
placeholder="Выберите дату окончания периода"
|
||||||
id="dateTo" name="dateTo"
|
id="dateTo" name="dateTo"
|
||||||
class="u-input u-input-rectangle"/>
|
class="u-input u-input-rectangle"/>
|
||||||
|
</div>
|
||||||
|
<div class="u-form-group u-form-name u-label-top">
|
||||||
|
<label class="u-label u-text-custom-color-1 u-label-1">Введите почту</label>
|
||||||
|
<input
|
||||||
|
type="email"
|
||||||
|
placeholder="Введите вашу почту"
|
||||||
|
name="headwaiterEmail"
|
||||||
|
class="u-input u-input-rectangle"/>
|
||||||
</div>
|
</div>
|
||||||
<div class="u-align-right u-form-group u-form-submit u-label-top">
|
<div class="u-align-right u-form-group u-form-submit u-label-top">
|
||||||
<div class="col-8"></div>
|
<div class="col-8"></div>
|
||||||
<div class="col-4"><input type="submit" value="Сформировать отчёт" class="u-active-custom-color-6 u-border-none u-btn u-btn-submit u-button-style u-custom-color-1 u-hover-custom-color-2 u-btn-1" /></div>
|
<div class="col-4"><input type="submit" value="Отправить на почту" class="u-active-custom-color-6 u-border-none u-btn u-btn-submit u-button-style u-custom-color-1 u-hover-custom-color-2 u-btn-1" /></div>
|
||||||
|
</div>
|
||||||
|
<div class="mt-3" id="report">
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
|
<div class="u-align-right u-form-group u-form-submit u-label-top">
|
||||||
|
<div class="col-8"></div>
|
||||||
|
<div class="col-4"><button type="button" id="demonstrate" class="u-active-custom-color-6 u-border-none u-btn u-btn-submit u-button-style u-custom-color-1 u-hover-custom-color-2 u-btn-1">Продемонстрировать</button></div>
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
@section Scripts {
|
||||||
|
<script>
|
||||||
|
function check() {
|
||||||
|
var dateFrom = $('#dateFrom').val();
|
||||||
|
var dateTo = $('#dateTo').val();
|
||||||
|
if (dateFrom && dateTo) {
|
||||||
|
$.ajax({
|
||||||
|
method: "GET",
|
||||||
|
url: "/Home/GetDinnersReport",
|
||||||
|
data: { dateFrom: dateFrom, dateTo: dateTo },
|
||||||
|
success: function (result) {
|
||||||
|
if (result != null) {
|
||||||
|
$('#report').html(result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
check();
|
||||||
|
$('#demonstrate').on('click', (e) => check());
|
||||||
|
</script>
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
using HotelContracts.BindingModels;
|
using HotelBusinessLogic.MailWorker;
|
||||||
|
using HotelContracts.BindingModels;
|
||||||
using HotelContracts.BusinessLogicsContracts;
|
using HotelContracts.BusinessLogicsContracts;
|
||||||
using HotelContracts.SearchModels;
|
using HotelContracts.SearchModels;
|
||||||
using HotelContracts.StoragesContracts;
|
using HotelContracts.StoragesContracts;
|
||||||
@ -17,11 +18,15 @@ namespace HotelBusinessLogic.BusinessLogics
|
|||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IConferenceBookingStorage _conferenceBookingStorage;
|
private readonly IConferenceBookingStorage _conferenceBookingStorage;
|
||||||
|
private readonly AbstractMailWorker _mailWorker;
|
||||||
|
private readonly IHeadwaiterLogic _headwaiterLogic;
|
||||||
|
|
||||||
public ConferenceBookingLogic(ILogger<ConferenceBookingLogic> logger, IConferenceBookingStorage conferenceBookingStorage)
|
public ConferenceBookingLogic(ILogger<ConferenceBookingLogic> logger, IConferenceBookingStorage conferenceBookingStorage, IHeadwaiterLogic headwaiterLogic, AbstractMailWorker mailWorker)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_conferenceBookingStorage = conferenceBookingStorage;
|
_conferenceBookingStorage = conferenceBookingStorage;
|
||||||
|
_mailWorker = mailWorker;
|
||||||
|
_headwaiterLogic = headwaiterLogic;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool AddDinnerToConferenceBooking(ConferenceBookingSearchModel model, IDinnerModel dinner)
|
public bool AddDinnerToConferenceBooking(ConferenceBookingSearchModel model, IDinnerModel dinner)
|
||||||
@ -62,12 +67,16 @@ namespace HotelBusinessLogic.BusinessLogics
|
|||||||
CheckModel(model);
|
CheckModel(model);
|
||||||
model.ConferenceBookingDinners = new();
|
model.ConferenceBookingDinners = new();
|
||||||
|
|
||||||
if (_conferenceBookingStorage.Insert(model) == null)
|
var result = _conferenceBookingStorage.Insert(model);
|
||||||
|
|
||||||
|
if (result == null)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Insert operation failed");
|
_logger.LogWarning("Insert operation failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SendConferenceBookingMessage(result.HeadwaiterId, $"Гостиница \"Развитие\", План питания №{result.Id}", $"План питания №{result.Id} под названием {result.NameHall} и стоимостью {result.BookingDate} добавлен");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,12 +86,16 @@ namespace HotelBusinessLogic.BusinessLogics
|
|||||||
|
|
||||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||||
|
|
||||||
if (_conferenceBookingStorage.Delete(model) == null)
|
var result = _conferenceBookingStorage.Delete(model);
|
||||||
|
|
||||||
|
if (result == null)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Delete operation failed");
|
_logger.LogWarning("Delete operation failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SendConferenceBookingMessage(result.HeadwaiterId, $"Гостиница \"Развитие\", План питания №{result.Id}", $"План питания №{result.Id} под названием {result.NameHall} и стоимостью {result.BookingDate} удален");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,5 +171,24 @@ namespace HotelBusinessLogic.BusinessLogics
|
|||||||
_logger.LogInformation("ConferenceBooking. Id: { Id}", model.Id);
|
_logger.LogInformation("ConferenceBooking. Id: { Id}", model.Id);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool SendConferenceBookingMessage(int headwaiterId, string subject, string text)
|
||||||
|
{
|
||||||
|
var headwaiter = _headwaiterLogic.ReadElement(new() { Id = headwaiterId });
|
||||||
|
|
||||||
|
if (headwaiter == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
_mailWorker.MailSendAsync(new()
|
||||||
|
{
|
||||||
|
MailAddress = headwaiter.HeadwaiterEmail,
|
||||||
|
Subject = subject,
|
||||||
|
Text = text
|
||||||
|
});
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ using HotelContracts.BusinessLogicsContracts;
|
|||||||
using HotelContracts.SearchModels;
|
using HotelContracts.SearchModels;
|
||||||
using HotelContracts.StoragesContracts;
|
using HotelContracts.StoragesContracts;
|
||||||
using HotelContracts.ViewModels;
|
using HotelContracts.ViewModels;
|
||||||
|
using HotelBusinessLogic.MailWorker;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -16,23 +17,31 @@ namespace HotelBusinessLogic.BusinessLogics
|
|||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IDinnerStorage _dinnerStorage;
|
private readonly IDinnerStorage _dinnerStorage;
|
||||||
|
private readonly AbstractMailWorker _mailWorker;
|
||||||
|
private readonly IHeadwaiterLogic _headwaiterLogic;
|
||||||
|
|
||||||
public DinnerLogic(ILogger<DinnerLogic> logger, IDinnerStorage dinnerStorage)
|
public DinnerLogic(ILogger<DinnerLogic> logger, IDinnerStorage dinnerStorage, AbstractMailWorker mailWorker, IHeadwaiterLogic headwaiterLogic)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_dinnerStorage = dinnerStorage;
|
_dinnerStorage = dinnerStorage;
|
||||||
|
_mailWorker = mailWorker;
|
||||||
|
_headwaiterLogic = headwaiterLogic;
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool Create(DinnerBindingModel model)
|
public bool Create(DinnerBindingModel model)
|
||||||
{
|
{
|
||||||
CheckModel(model);
|
CheckModel(model);
|
||||||
|
|
||||||
if (_dinnerStorage.Insert(model) == null)
|
var result = _dinnerStorage.Insert(model);
|
||||||
|
|
||||||
|
if (result == null)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Insert operation failed");
|
_logger.LogWarning("Insert operation failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SendDinnerMessage(result.HeadwaiterId, $"Гостиница \"Развитие\", Участник №{result.Id}", $"Участник №{result.Id} по имени {result.DinnerName} и с гражданством {result.DinnerPrice} добавлен");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,12 +51,16 @@ namespace HotelBusinessLogic.BusinessLogics
|
|||||||
|
|
||||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||||
|
|
||||||
if (_dinnerStorage.Delete(model) == null)
|
var result = _dinnerStorage.Delete(model);
|
||||||
|
|
||||||
|
if (result == null)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Delete operation failed");
|
_logger.LogWarning("Delete operation failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SendDinnerMessage(result.HeadwaiterId, $"Гостиница \"Развитие\", Участник №{result.Id}", $"Участник №{result.Id} по имени {result.DinnerName} и с гражданством {result.DinnerPrice} удален");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,5 +139,24 @@ namespace HotelBusinessLogic.BusinessLogics
|
|||||||
|
|
||||||
_logger.LogInformation("Dinner. DinnerName:{DinnerName}.DinnerPrice:{ DinnerPrice}. Id: { Id}", model.DinnerName, model.DinnerPrice, model.Id);
|
_logger.LogInformation("Dinner. DinnerName:{DinnerName}.DinnerPrice:{ DinnerPrice}. Id: { Id}", model.DinnerName, model.DinnerPrice, model.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool SendDinnerMessage(int headwaiterId, string subject, string text)
|
||||||
|
{
|
||||||
|
var headwaiter = _headwaiterLogic.ReadElement(new() { Id = headwaiterId });
|
||||||
|
|
||||||
|
if (headwaiter == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
_mailWorker.MailSendAsync(new()
|
||||||
|
{
|
||||||
|
MailAddress = headwaiter.HeadwaiterEmail,
|
||||||
|
Subject = subject,
|
||||||
|
Text = text
|
||||||
|
});
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -138,6 +138,16 @@ namespace HotelBusinessLogic.BusinessLogics
|
|||||||
|
|
||||||
public void SaveDinnersToPdfFile(ReportHeadwaiterBindingModel model)
|
public void SaveDinnersToPdfFile(ReportHeadwaiterBindingModel model)
|
||||||
{
|
{
|
||||||
|
if (model.DateFrom == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Дата начала не задана");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (model.DateTo == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentException("Дата окончания не задана");
|
||||||
|
}
|
||||||
|
|
||||||
_saveToPdf.CreateDoc(new PdfInfoHeadwaiter
|
_saveToPdf.CreateDoc(new PdfInfoHeadwaiter
|
||||||
{
|
{
|
||||||
FileName = model.FileName,
|
FileName = model.FileName,
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
using HotelContracts.BindingModels;
|
using HotelBusinessLogic.MailWorker;
|
||||||
|
using HotelContracts.BindingModels;
|
||||||
using HotelContracts.BusinessLogicsContracts;
|
using HotelContracts.BusinessLogicsContracts;
|
||||||
using HotelContracts.SearchModels;
|
using HotelContracts.SearchModels;
|
||||||
using HotelContracts.StoragesContracts;
|
using HotelContracts.StoragesContracts;
|
||||||
@ -17,23 +18,31 @@ namespace HotelBusinessLogic.BusinessLogics
|
|||||||
{
|
{
|
||||||
private readonly ILogger _logger;
|
private readonly ILogger _logger;
|
||||||
private readonly IRoomStorage _roomStorage;
|
private readonly IRoomStorage _roomStorage;
|
||||||
|
private readonly AbstractMailWorker _mailWorker;
|
||||||
|
private readonly IHeadwaiterLogic _headwaiterLogic;
|
||||||
|
|
||||||
public RoomLogic(ILogger<RoomLogic> logger, IRoomStorage roomStorage)
|
public RoomLogic(ILogger<RoomLogic> logger, IRoomStorage roomStorage, IHeadwaiterLogic headwaiterLogic, AbstractMailWorker mailWorker)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
_roomStorage = roomStorage;
|
_roomStorage = roomStorage;
|
||||||
|
_mailWorker = mailWorker;
|
||||||
|
_headwaiterLogic = headwaiterLogic;
|
||||||
}
|
}
|
||||||
public bool Create(RoomBindingModel model)
|
public bool Create(RoomBindingModel model)
|
||||||
{
|
{
|
||||||
CheckModel(model);
|
CheckModel(model);
|
||||||
model.RoomDinners = new();
|
model.RoomDinners = new();
|
||||||
|
|
||||||
if (_roomStorage.Insert(model) == null)
|
var result = _roomStorage.Insert(model);
|
||||||
|
|
||||||
|
if (result == null)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Insert operation failed");
|
_logger.LogWarning("Insert operation failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SendRoomMessage(result.HeadwaiterId, $"Гостиница \"Развитие\", Конференция №{result.Id}", $"Конференция №{result.Id} под названием {result.RoomName} и датой начала {result.RoomPrice} добавлена {result.RoomFrame}");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,12 +52,17 @@ namespace HotelBusinessLogic.BusinessLogics
|
|||||||
|
|
||||||
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
_logger.LogInformation("Delete. Id:{Id}", model.Id);
|
||||||
|
|
||||||
if (_roomStorage.Delete(model) == null)
|
var result = _roomStorage.Delete(model);
|
||||||
|
|
||||||
|
if (result == null)
|
||||||
{
|
{
|
||||||
_logger.LogWarning("Delete operation failed");
|
_logger.LogWarning("Delete operation failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SendRoomMessage(result.HeadwaiterId, $"Гостиница \"Развитие\", Конференция №{result.Id}", $"Конференция №{result.Id} под названием {result.RoomName} и датой начала {result.RoomPrice} удалена {result.RoomFrame}");
|
||||||
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,5 +182,24 @@ namespace HotelBusinessLogic.BusinessLogics
|
|||||||
|
|
||||||
_logger.LogInformation("Room. RoomName:{RoomName}.RoomFrame:{ RoomFrame}.RoomPrice:{ RoomPrice}. Id: { Id}", model.RoomName, model.RoomFrame, model.RoomPrice, model.Id);
|
_logger.LogInformation("Room. RoomName:{RoomName}.RoomFrame:{ RoomFrame}.RoomPrice:{ RoomPrice}. Id: { Id}", model.RoomName, model.RoomFrame, model.RoomPrice, model.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool SendRoomMessage(int headwaiterId, string subject, string text)
|
||||||
|
{
|
||||||
|
var headwaiter = _headwaiterLogic.ReadElement(new() { Id = headwaiterId });
|
||||||
|
|
||||||
|
if (headwaiter == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
_mailWorker.MailSendAsync(new()
|
||||||
|
{
|
||||||
|
MailAddress = headwaiter.HeadwaiterEmail,
|
||||||
|
Subject = subject,
|
||||||
|
Text = text
|
||||||
|
});
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ namespace HotelBusinessLogic.MailWorker
|
|||||||
objMailMessage.Body = info.Text;
|
objMailMessage.Body = info.Text;
|
||||||
objMailMessage.SubjectEncoding = Encoding.UTF8;
|
objMailMessage.SubjectEncoding = Encoding.UTF8;
|
||||||
objMailMessage.BodyEncoding = Encoding.UTF8;
|
objMailMessage.BodyEncoding = Encoding.UTF8;
|
||||||
Attachment attachment = new Attachment("F:\\ReportsCourseWork\\pdffile.pdf", new ContentType(MediaTypeNames.Application.Pdf));
|
Attachment attachment = new Attachment("E:\\ReportsCourseWork\\pdffile.pdf", new ContentType(MediaTypeNames.Application.Pdf));
|
||||||
objMailMessage.Attachments.Add(attachment);
|
objMailMessage.Attachments.Add(attachment);
|
||||||
|
|
||||||
objSmtpClient.UseDefaultCredentials = false;
|
objSmtpClient.UseDefaultCredentials = false;
|
||||||
|
@ -9,7 +9,7 @@ namespace HotelBusinessLogic.OfficePackage.HelperModels
|
|||||||
{
|
{
|
||||||
public class PdfInfoHeadwaiter
|
public class PdfInfoHeadwaiter
|
||||||
{
|
{
|
||||||
public string FileName { get; set; } = string.Empty;
|
public string FileName { get; set; } = "E:\\ReportsCourseWork\\pdffile.pdf";
|
||||||
public string Title { get; set; } = string.Empty;
|
public string Title { get; set; } = string.Empty;
|
||||||
public DateTime DateFrom { get; set; }
|
public DateTime DateFrom { get; set; }
|
||||||
public DateTime DateTo { get; set; }
|
public DateTime DateTo { get; set; }
|
||||||
|
@ -34,7 +34,7 @@ namespace HotelRestApi.Controllers
|
|||||||
DateFrom = model.DateFrom,
|
DateFrom = model.DateFrom,
|
||||||
DateTo = model.DateTo,
|
DateTo = model.DateTo,
|
||||||
OrganiserId = model.OrganiserId,
|
OrganiserId = model.OrganiserId,
|
||||||
FileName = "F:\\ReportsCourseWork\\pdffile.pdf",
|
FileName = "E:\\ReportsCourseWork\\pdffile.pdf",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@ -121,7 +121,7 @@ namespace HotelRestApi.Controllers
|
|||||||
{
|
{
|
||||||
_reportHeadwaiterLogic.SaveDinnersToPdfFile(new ReportHeadwaiterBindingModel
|
_reportHeadwaiterLogic.SaveDinnersToPdfFile(new ReportHeadwaiterBindingModel
|
||||||
{
|
{
|
||||||
FileName = "Отчет PDF.pdf",
|
FileName = "E:\\ReportsCourseWork\\pdffile.pdf",
|
||||||
DateFrom = model.DateFrom,
|
DateFrom = model.DateFrom,
|
||||||
DateTo = model.DateTo,
|
DateTo = model.DateTo,
|
||||||
HeadwaiterId = model.HeadwaiterId,
|
HeadwaiterId = model.HeadwaiterId,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user