PIbd-22_Bazunov_AI_Hotel/Hotel/HotelView/Api.cs

123 lines
4.0 KiB
C#
Raw Normal View History

2023-05-19 17:52:18 +04:00
using System.Net.Mail;
using HotelBusinessLogic.MailWorker;
using HotelContracts.BindingModels;
using HotelContracts.BusinessLogicsContracts;
using HotelContracts.SearchModels;
using HotelContracts.StoragesContracts;
using HotelContracts.ViewModels;
namespace HotelView;
public class Api
{
private readonly IMaitreLogic _maitreLogic;
private readonly AbstractMailWorker _mailWorker;
private readonly IReportLogic _reportLogic;
public MaitreViewModel? Maitre { get; private set; }
public Api(IMaitreLogic maitreLogic,
IRoomLogic roomLogic,
IGuestLogic guestLogic,
IReservationLogic reservationLogic,
ICleaningInstrumentsLogic getCleaningInstrumentsLogic,
ICleaningLogic getCleaningLogic,
AbstractMailWorker mailWorker,
IReportLogic reportLogic)
{
_maitreLogic = maitreLogic;
GetRoomLogic = roomLogic;
GetGuestLogic = guestLogic;
GetReservationLogic = reservationLogic;
GetCleaningInstrumentsLogic = getCleaningInstrumentsLogic;
GetCleaningLogic = getCleaningLogic;
_mailWorker = mailWorker;
_reportLogic = reportLogic;
}
public IRoomLogic GetRoomLogic { get; }
public IGuestLogic GetGuestLogic { get; }
public IReservationLogic GetReservationLogic { get; }
public ICleaningInstrumentsLogic GetCleaningInstrumentsLogic { get; }
public ICleaningLogic GetCleaningLogic { get; }
public void Auth(string email, string password)
{
var maitreViewModel = _maitreLogic.ReadElement(new MaitreSearchModel
{
Login = email
});
if (maitreViewModel is null) return;
if (maitreViewModel.Password.Equals(password))
{
Maitre = maitreViewModel;
}
}
public bool Register(string login,
string password,
string name,
string secondName,
string lastName)
{
return _maitreLogic.Create(new MaitreBindingModel
{
Login = login,
Password = password,
Name = name,
SecondName = secondName,
LastName = lastName
});
}
private string GenerateFileName(string ext = "docx") =>
"C:/Users/andre/source/repos/PIbd-22_Bazunov_AI_Hotel/Hotel/HotelView/TempDirectoryForReports/" +
Maitre.Fio.Replace(" ", "_") + "_" +
DateTime.Now.ToShortDateString() + "." + ext;
public void SendReportWord()
{
var fileName = GenerateFileName();
_reportLogic.SaveListCleaningToWordFile(new ReportBindingModel
{
FileName = fileName
});
_mailWorker.MailSendAsync(new MailSendInfoBindingModel
{
MailAddress = Maitre.Login,
Subject = "Список составляющих комплектов для подготовки номеров",
AttachmentMail = new Attachment(fileName)
});
}
public void SendReportExcel()
{
var filename = GenerateFileName("xlsx");
_reportLogic.SaveListCleaningToExcelFile(new ReportBindingModel
{
FileName = filename
});
_mailWorker.MailSendAsync(new MailSendInfoBindingModel
{
MailAddress = Maitre.Login,
Subject = "Список составляющих комплектов для подготовки номеров",
AttachmentMail = new Attachment(filename)
});
}
public void SendReportPdf(DateTime from, DateTime to)
{
var filename = GenerateFileName("pdf");
_reportLogic.SaveGuestsToPdfFile(new ReportBindingModel
{
FileName = filename,
To = to,
From = from
});
_mailWorker.MailSendAsync(new MailSendInfoBindingModel
{
MailAddress = Maitre.Login,
Subject = "Список гостей с " + from.ToShortDateString() + " по " + to.ToShortDateString(),
AttachmentMail = new Attachment(filename)
});
}
}