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

123 lines
3.8 KiB
C#
Raw Permalink 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.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;
2023-05-19 20:55:43 +04:00
public string SendReportWord(List<int> reservations)
2023-05-19 17:52:18 +04:00
{
var fileName = GenerateFileName();
_reportLogic.SaveListCleaningToWordFile(new ReportBindingModel
{
2023-05-19 20:55:43 +04:00
FileName = fileName,
Reservations = reservations
2023-05-19 17:52:18 +04:00
});
2023-05-19 20:55:43 +04:00
return fileName;
2023-05-19 17:52:18 +04:00
}
2023-05-19 20:55:43 +04:00
public string SendReportExcel(List<int> reservations)
2023-05-19 17:52:18 +04:00
{
var filename = GenerateFileName("xlsx");
_reportLogic.SaveListCleaningToExcelFile(new ReportBindingModel
{
2023-05-19 20:55:43 +04:00
FileName = filename,
Reservations = reservations
2023-05-19 17:52:18 +04:00
});
2023-05-19 20:55:43 +04:00
return filename;
}
public List<ReportGuestViewModel> GetPreRenderReport(DateTime from, DateTime to)
{
return _reportLogic.GetGuests(new ReportBindingModel
2023-05-19 17:52:18 +04:00
{
2023-05-19 20:55:43 +04:00
From = from,
To = to
2023-05-19 17:52:18 +04:00
});
}
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)
});
}
}