123 lines
3.8 KiB
C#
123 lines
3.8 KiB
C#
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;
|
||
|
||
public string SendReportWord(List<int> reservations)
|
||
{
|
||
var fileName = GenerateFileName();
|
||
_reportLogic.SaveListCleaningToWordFile(new ReportBindingModel
|
||
{
|
||
FileName = fileName,
|
||
Reservations = reservations
|
||
});
|
||
return fileName;
|
||
}
|
||
|
||
public string SendReportExcel(List<int> reservations)
|
||
{
|
||
var filename = GenerateFileName("xlsx");
|
||
_reportLogic.SaveListCleaningToExcelFile(new ReportBindingModel
|
||
{
|
||
FileName = filename,
|
||
Reservations = reservations
|
||
});
|
||
return filename;
|
||
}
|
||
|
||
public List<ReportGuestViewModel> GetPreRenderReport(DateTime from, DateTime to)
|
||
{
|
||
return _reportLogic.GetGuests(new ReportBindingModel
|
||
{
|
||
From = from,
|
||
To = to
|
||
});
|
||
}
|
||
|
||
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)
|
||
});
|
||
}
|
||
} |