отчеты, почта и фикс бд

This commit is contained in:
russell 2024-05-29 08:46:50 +04:00
parent 26f3a880ab
commit b0cf340079
60 changed files with 1882 additions and 251 deletions

View File

@ -21,7 +21,7 @@ namespace TravelAgencyBusinessLogic.BusinessLogics
public List<ExcursionViewModel>? ReadList(ExcursionSearchModel? model)
{
_logger.LogInformation("ReadList. Id: {Id}, ExcursionName: {ExcursionName}, UserId: {UserId}.", model?.Id, model?.ExcursionName, model?.UserId);
_logger.LogInformation("ReadList. Id: {Id}, ExcursionName: {ExcursionName}, UserId: {UserId}, PlaceId: {PlaceId}.", model?.Id, model?.ExcursionName, model?.UserId, model?.PlaceId);
var list = (model == null) ? _excursionStorage.GetFullList() : _excursionStorage.GetFilteredList(model);
if (list == null)
{

View File

@ -21,7 +21,7 @@ namespace TravelAgencyBusinessLogic.BusinessLogics
public List<PlaceViewModel>? ReadList(PlaceSearchModel? model)
{
_logger.LogInformation("ReadList. Id: {Id}, PlaceName: {PlaceName}, ExcursionId: {ExcursionId}.", model?.Id, model?.PlaceName, model?.ExcursionId);
_logger.LogInformation("ReadList. Id: {Id}, PlaceName: {PlaceName}.", model?.Id, model?.PlaceName);
var list = (model == null) ? _placeStorage.GetFullList() : _placeStorage.GetFilteredList(model);
if (list == null)
{
@ -101,11 +101,7 @@ namespace TravelAgencyBusinessLogic.BusinessLogics
{
throw new ArgumentNullException("Нет адреса места", nameof(model.PlaceAddress));
}
if (model.ExcursionId <= 0)
{
throw new ArgumentNullException("Некорректный идентификатор экскурсии", nameof(model.ExcursionId));
}
_logger.LogInformation("Place. Id: {id}, PlaceName: {PlaceName}, PlaceAddress: {PlaceAddress}, ExcursionId: {ExcursionId}", model.Id, model.PlaceName, model.PlaceAddress, model.ExcursionId);
_logger.LogInformation("Place. Id: {id}, PlaceName: {PlaceName}, PlaceAddress: {PlaceAddress}", model.Id, model.PlaceName, model.PlaceAddress);
var element = _placeStorage.GetElement(new PlaceSearchModel
{
PlaceName = model.PlaceName,

View File

@ -0,0 +1,136 @@
using TravelAgencyBusinessLogic.OfficePackage.HelperModels;
using TravelAgencyBusinessLogic.OfficePackage;
using TravelAgencyContracts.BindingModels;
using TravelAgencyContracts.BusinessLogicsContracts;
using TravelAgencyContracts.StoragesContracts;
using TravelAgencyContracts.ViewModels;
using TravelAgencyContracts.SearchModels;
namespace TravelAgencyBusinessLogic.BusinessLogics
{
public class ReportLogic : IReportLogic
{
private readonly ITourStorage _tourStorage;
private readonly IPlaceStorage _placeStorage;
private readonly IGuideStorage _guideStorage;
private readonly IExcursionGroupStorage _excursionGroupStorage;
private readonly IExcursionStorage _excursionStorage;
private readonly AbstractSaveToWord _saveToWord;
private readonly AbstractSaveToExcel _saveToExcel;
private readonly AbstractSaveToPdf _saveToPdf;
public ReportLogic(ITourStorage tourStorage,
IPlaceStorage placeStorage,
IGuideStorage guideStorage,
IExcursionGroupStorage excursionGroupStorage,
IExcursionStorage excursionStorage,
AbstractSaveToWord saveToWord,
AbstractSaveToExcel saveToExcel,
AbstractSaveToPdf saveToPdf)
{
_tourStorage = tourStorage;
_placeStorage = placeStorage;
_guideStorage = guideStorage;
_excursionGroupStorage = excursionGroupStorage;
_excursionStorage = excursionStorage;
_saveToWord = saveToWord;
_saveToExcel = saveToExcel;
_saveToPdf = saveToPdf;
}
public List<ReportTourPlaceViewModel> GetTourPlaces(ReportBindingModel model)
{
var result = new List<ReportTourPlaceViewModel>();
var excursions = _excursionStorage.GetFullList();
foreach (var tour in model.Tours)
{
var record = new ReportTourPlaceViewModel
{
Tour = _tourStorage.GetElement(new TourSearchModel{ Id = tour }),
Places = new HashSet<PlaceViewModel>()
};
foreach (var excursion in excursions)
{
if (excursion.ExcursionTours.ContainsKey(tour))
{
var place = _placeStorage.GetElement(new PlaceSearchModel { Id = excursion.PlaceId });
record.Places.Add(place);
}
}
result.Add(record);
}
return result;
}
public List<ReportTourPeriodViewModel> GetTourPeriod(ReportBindingModel model)
{
var result = new List<ReportTourPeriodViewModel>();
var tours = _tourStorage.GetFilteredList(new TourSearchModel
{
UserId = model.UserId,
DateFrom = model.DateFrom,
DateTo = model.DateTo
});
var excursionGroups = _excursionGroupStorage.GetFullList();
foreach (var tour in tours)
{
var record = new ReportTourPeriodViewModel
{
Tour = tour,
ExcursionGroups = new HashSet<ExcursionGroupViewModel>(),
Guides = new HashSet<GuideViewModel>(),
};
foreach (var excursionGroup in excursionGroups)
{
if (excursionGroup.ExcursionGroupTours.ContainsKey(tour.Id))
{
record.ExcursionGroups.Add(excursionGroup);
var guide = _guideStorage.GetElement(new GuideSearchModel { Id = excursionGroup.GuideId });
record.Guides.Add(guide);
}
}
result.Add(record);
}
return result;
}
public void SaveTourPlacesToWordFile(ReportBindingModel model)
{
_saveToWord.CreateDoc(new WordInfo
{
FileName = model.FileName,
Title = "Список мест для посещения по выбранным турам.",
TourPlaces = GetTourPlaces(model)
});
}
public void SaveTourPlacesToExcelFile(ReportBindingModel model)
{
_saveToExcel.CreateReport(new ExcelInfo
{
FileName = model.FileName,
Title = "Список мест",
TourPlaces = GetTourPlaces(model)
});
}
}
}

View File

@ -0,0 +1,49 @@
using Microsoft.Extensions.Logging;
using TravelAgencyContracts.BindingModels;
using TravelAgencyContracts.BusinessLogicsContracts;
namespace TravelAgencyBusinessLogic.MailWorker
{
public abstract class AbstractMailWorker
{
protected string _mailLogin = string.Empty;
protected string _mailPassword = string.Empty;
protected string _smtpClientHost = string.Empty;
protected int _smtpClientPort;
protected string _popHost = string.Empty;
protected int _popPort;
private readonly ILogger _logger;
public AbstractMailWorker(ILogger<AbstractMailWorker> logger)
{
_logger = logger;
}
public void MailConfig(MailConfigModel config)
{
_mailLogin = config.MailLogin;
_mailPassword = config.MailPassword;
_smtpClientHost = config.SmtpClientHost;
_smtpClientPort = config.SmtpClientPort;
_popHost = config.PopHost;
_popPort = config.PopPort;
_logger.LogDebug("Config: {login}, {password}, {clientHost}, {clientPort}, {popHost}, {popPort} ", _mailLogin, _mailPassword, _smtpClientHost, _smtpClientPort, _popHost, _popPort);
}
public async void MailSendAsync(MailSendInfoBindingModel info)
{
if (string.IsNullOrEmpty(_mailLogin) || string.IsNullOrEmpty(_mailPassword))
{
return;
}
if (string.IsNullOrEmpty(_smtpClientHost) || _smtpClientPort == 0)
{
return;
}
if (string.IsNullOrEmpty(info.MailAddress) || string.IsNullOrEmpty(info.Subject) || (string.IsNullOrEmpty(info.Text) && info.Pdf == null))
{
return;
}
_logger.LogDebug("Send Mail: {To}, {Subject}", info.MailAddress, info.Subject);
await SendMailAsync(info);
}
protected abstract Task SendMailAsync(MailSendInfoBindingModel info);
}
}

View File

@ -0,0 +1,47 @@
using TravelAgencyContracts.BindingModels;
using TravelAgencyContracts.BusinessLogicsContracts;
using MailKit.Net.Pop3;
using MailKit.Security;
using Microsoft.Extensions.Logging;
using System.Net.Mail;
using System.Text;
using System.Net;
namespace TravelAgencyBusinessLogic.MailWorker
{
public class MailKitWorker : AbstractMailWorker
{
public MailKitWorker(ILogger<MailKitWorker> logger) : base(logger) { }
protected override async Task SendMailAsync(MailSendInfoBindingModel info)
{
using var objMailMessage = new MailMessage();
using var objSmtpClient = new SmtpClient(_smtpClientHost, _smtpClientPort);
try
{
objMailMessage.From = new MailAddress(_mailLogin);
objMailMessage.To.Add(new MailAddress(info.MailAddress));
objMailMessage.Subject = info.Subject;
objMailMessage.SubjectEncoding = Encoding.UTF8;
objMailMessage.BodyEncoding = Encoding.UTF8;
if (info.Text != null)
{
objMailMessage.Body = info.Text;
}
if (info.Pdf != null)
{
var attachment = new Attachment (new MemoryStream(info.Pdf), info.FileName);
objMailMessage.Attachments.Add (attachment);
}
objSmtpClient.UseDefaultCredentials = false;
objSmtpClient.EnableSsl = true;
objSmtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
objSmtpClient.Credentials = new NetworkCredential(_mailLogin, _mailPassword);
await Task.Run(() => objSmtpClient.Send(objMailMessage));
}
catch (Exception ex)
{
throw;
}
}
}
}

View File

@ -0,0 +1,125 @@
using TravelAgencyBusinessLogic.OfficePackage.HelperEnums;
using TravelAgencyBusinessLogic.OfficePackage.HelperModels;
namespace TravelAgencyBusinessLogic.OfficePackage
{
public abstract class AbstractSaveToExcel
{
/// <summary>
/// Создание отчета
/// </summary>
/// <param name="info"></param>
public void CreateReport(ExcelInfo info)
{
CreateExcel(info);
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = 1,
Text = info.Title,
StyleInfo = ExcelStyleInfoType.Title
});
MergeCells(new ExcelMergeParameters
{
CellFromName = "A1",
CellToName = "C1"
});
uint rowIndex = 2;
foreach (var tp in info.TourPlaces)
{
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "A",
RowIndex = rowIndex,
Text = $"Тур: {tp.Tour.TourName}.",
StyleInfo = ExcelStyleInfoType.Text
});
rowIndex++;
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "B",
RowIndex = rowIndex,
Text = "Места для посещения:",
StyleInfo = ExcelStyleInfoType.Text
});
MergeCells(new ExcelMergeParameters
{
CellFromName = $"B{rowIndex}",
CellToName = $"C{rowIndex}"
});
rowIndex++;
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "B",
RowIndex = rowIndex,
Text = "Название:",
StyleInfo = ExcelStyleInfoType.Text
});
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "C",
RowIndex = rowIndex,
Text = "Адрес:",
StyleInfo = ExcelStyleInfoType.Text
});
rowIndex++;
foreach (var place in tp.Places)
{
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "B",
RowIndex = rowIndex,
Text = place.PlaceName,
StyleInfo = ExcelStyleInfoType.TextWithBorder
});
InsertCellInWorksheet(new ExcelCellParameters
{
ColumnName = "C",
RowIndex = rowIndex,
Text = place.PlaceAddress,
StyleInfo = ExcelStyleInfoType.TextWithBorder
});
rowIndex++;
}
}
SaveExcel(info);
}
/// <summary>
/// Создание excel-файла
/// </summary>
/// <param name="info"></param>
protected abstract void CreateExcel(ExcelInfo info);
/// <summary>
/// Добавляем новую ячейку в лист
/// </summary>
/// <param name="cellParameters"></param>
protected abstract void InsertCellInWorksheet(ExcelCellParameters excelParams);
/// <summary>
/// Объединение ячеек
/// </summary>
/// <param name="mergeParameters"></param>
protected abstract void MergeCells(ExcelMergeParameters excelParams);
/// <summary>
/// Сохранение файла
/// </summary>
/// <param name="info"></param>
protected abstract void SaveExcel(ExcelInfo info);
}
}

View File

@ -0,0 +1,77 @@
using TravelAgencyBusinessLogic.OfficePackage.HelperEnums;
using TravelAgencyBusinessLogic.OfficePackage.HelperModels;
namespace TravelAgencyBusinessLogic.OfficePackage
{
public abstract class AbstractSaveToPdf
{
public void CreateDoc(PdfInfo info)
{
CreatePdf(info);
CreateParagraph(new PdfParagraph { Text = info.Title, Style = "NormalTitle", ParagraphAlignment = PdfParagraphAlignmentType.Center });
CreateParagraph(new PdfParagraph { Text = $"с {info.DateFrom.ToShortDateString()} по {info.DateTo.ToShortDateString()}", Style = "Normal", ParagraphAlignment = PdfParagraphAlignmentType.Center });
CreateTable(new List<string> { "2cm", "3cm", "3cm", "4cm", "3cm", "3cm"});
CreateRow(new PdfRowParameters
{
Texts = new List<string> { "Тур", "Стоимость тура", "Дата тура", "Экскурсионная группа", "Количество участников", "Гид" },
Style = "NormalTitle",
ParagraphAlignment = PdfParagraphAlignmentType.Center
});
foreach (var tour in info.Tours)
{
CreateRow(new PdfRowParameters
{
Texts = new List<string> { tour.Tour.TourName, tour.Tour.Price.ToString(), tour.Tour.TourDate.ToShortDateString(), "", "", "" },
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Left
});
foreach(var excursionGroup in tour.ExcursionGroups)
{
CreateRow(new PdfRowParameters
{
Texts = new List<string> { "", "", "", excursionGroup.ExcursionGroupName, excursionGroup.ParticipantsAmount.ToString(), excursionGroup.GuideFIO},
Style = "Normal",
ParagraphAlignment = PdfParagraphAlignmentType.Left
});
}
}
SavePdf(info);
}
/// <summary>
/// Создание doc-файла
/// </summary>
/// <param name="info"></param>
protected abstract void CreatePdf(PdfInfo info);
/// <summary>
/// Создание параграфа с текстом
/// </summary>
/// <param name="title"></param>
/// <param name="style"></param>
protected abstract void CreateParagraph(PdfParagraph paragraph);
/// <summary>
/// Создание таблицы
/// </summary>
/// <param name="title"></param>
/// <param name="style"></param>
protected abstract void CreateTable(List<string> columns);
/// <summary>
/// Создание и заполнение строки
/// </summary>
/// <param name="rowParameters"></param>
protected abstract void CreateRow(PdfRowParameters rowParameters);
/// <summary>
/// Сохранение файла
/// </summary>
/// <param name="info"></param>
protected abstract void SavePdf(PdfInfo info);
}
}

View File

@ -0,0 +1,90 @@
using DocumentFormat.OpenXml.Wordprocessing;
using TravelAgencyBusinessLogic.OfficePackage.HelperEnums;
using TravelAgencyBusinessLogic.OfficePackage.HelperModels;
namespace TravelAgencyBusinessLogic.OfficePackage
{
public abstract class AbstractSaveToWord
{
public void CreateDoc(WordInfo info)
{
CreateWord(info);
CreateParagraph(new WordParagraph
{
Texts = new List<(string, WordTextProperties)> { (info.Title, new WordTextProperties { Bold = true, Size = "24", }) },
TextProperties = new WordTextProperties
{
Size = "24",
JustificationType = WordJustificationType.Center
}
});
foreach (var tourPlace in info.TourPlaces)
{
CreateParagraph(new WordParagraph
{
Texts = new List<(string, WordTextProperties)>
{
($"Тур: {tourPlace.Tour.TourName}. ", new WordTextProperties { Bold = true, Size = "24" })
},
TextProperties = new WordTextProperties
{
Size = "24",
JustificationType = WordJustificationType.Both
}
});
CreateParagraph(new WordParagraph
{
Texts = new List<(string, WordTextProperties)>
{
("Места для посещения:", new WordTextProperties { Bold = true, Size = "24" })
},
TextProperties = new WordTextProperties
{
Size = "24",
JustificationType = WordJustificationType.Both
}
});
foreach (var place in tourPlace.Places)
{
CreateParagraph(new WordParagraph
{
Texts = new List<(string, WordTextProperties)>
{
($"{place.PlaceName} - {place.PlaceAddress}", new WordTextProperties { Bold = false, Size = "24" })
},
TextProperties = new WordTextProperties
{
Size = "24",
JustificationType = WordJustificationType.Both
}
});
}
}
SaveWord(info);
}
/// <summary>
/// Создание doc-файла
/// </summary>
/// <param name="info"></param>
protected abstract void CreateWord(WordInfo info);
/// <summary>
/// Создание абзаца с текстом
/// </summary>
/// <param name="paragraph"></param>
/// <returns></returns>
protected abstract void CreateParagraph(WordParagraph paragraph);
/// <summary>
/// Сохранение файла
/// </summary>
/// <param name="info"></param>
protected abstract void SaveWord(WordInfo info);
}
}

View File

@ -0,0 +1,11 @@
namespace TravelAgencyBusinessLogic.OfficePackage.HelperEnums
{
public enum ExcelStyleInfoType
{
Title,
Text,
TextWithBorder
}
}

View File

@ -0,0 +1,11 @@
namespace TravelAgencyBusinessLogic.OfficePackage.HelperEnums
{
public enum PdfParagraphAlignmentType
{
Center,
Left,
Right
}
}

View File

@ -0,0 +1,9 @@
namespace TravelAgencyBusinessLogic.OfficePackage.HelperEnums
{
public enum WordJustificationType
{
Center,
Both
}
}

View File

@ -0,0 +1,17 @@
using TravelAgencyBusinessLogic.OfficePackage.HelperEnums;
namespace TravelAgencyBusinessLogic.OfficePackage.HelperModels
{
public class ExcelCellParameters
{
public string ColumnName { get; set; } = string.Empty;
public uint RowIndex { get; set; }
public string Text { get; set; } = string.Empty;
public string CellReference => $"{ColumnName}{RowIndex}";
public ExcelStyleInfoType StyleInfo { get; set; }
}
}

View File

@ -0,0 +1,13 @@
using TravelAgencyContracts.ViewModels;
namespace TravelAgencyBusinessLogic.OfficePackage.HelperModels
{
public class ExcelInfo
{
public string FileName { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty;
public List<ReportTourPlaceViewModel> TourPlaces { get; set; } = new();
}
}

View File

@ -0,0 +1,11 @@
namespace TravelAgencyBusinessLogic.OfficePackage.HelperModels
{
public class ExcelMergeParameters
{
public string CellFromName { get; set; } = string.Empty;
public string CellToName { get; set; } = string.Empty;
public string Merge => $"{CellFromName}:{CellToName}";
}
}

View File

@ -0,0 +1,17 @@
using TravelAgencyContracts.ViewModels;
namespace TravelAgencyBusinessLogic.OfficePackage.HelperModels
{
public class PdfInfo
{
public MemoryStream FileName { get; set; } = new();
public string Title { get; set; } = string.Empty;
public DateTime DateFrom { get; set; }
public DateTime DateTo { get; set; }
public List<ReportTourPeriodViewModel> Tours { get; set; } = new();
}
}

View File

@ -0,0 +1,13 @@
using TravelAgencyBusinessLogic.OfficePackage.HelperEnums;
namespace TravelAgencyBusinessLogic.OfficePackage.HelperModels
{
public class PdfParagraph
{
public string Text { get; set; } = string.Empty;
public string Style { get; set; } = string.Empty;
public PdfParagraphAlignmentType ParagraphAlignment { get; set; }
}
}

View File

@ -0,0 +1,13 @@
using TravelAgencyBusinessLogic.OfficePackage.HelperEnums;
namespace TravelAgencyBusinessLogic.OfficePackage.HelperModels
{
public class PdfRowParameters
{
public List<string> Texts { get; set; } = new();
public string Style { get; set; } = string.Empty;
public PdfParagraphAlignmentType ParagraphAlignment { get; set; }
}
}

View File

@ -0,0 +1,13 @@
using TravelAgencyContracts.ViewModels;
namespace TravelAgencyBusinessLogic.OfficePackage.HelperModels
{
public class WordInfo
{
public string FileName { get; set; } = string.Empty;
public string Title { get; set; } = string.Empty;
public List<ReportTourPlaceViewModel> TourPlaces { get; set; } = new();
}
}

View File

@ -0,0 +1,9 @@
namespace TravelAgencyBusinessLogic.OfficePackage.HelperModels
{
public class WordParagraph
{
public List<(string, WordTextProperties)> Texts { get; set; } = new();
public WordTextProperties? TextProperties { get; set; }
}
}

View File

@ -0,0 +1,13 @@
using TravelAgencyBusinessLogic.OfficePackage.HelperEnums;
namespace TravelAgencyBusinessLogic.OfficePackage.HelperModels
{
public class WordTextProperties
{
public string Size { get; set; } = string.Empty;
public bool Bold { get; set; }
public WordJustificationType JustificationType { get; set; }
}
}

View File

@ -0,0 +1,292 @@
using TravelAgencyBusinessLogic.OfficePackage.HelperEnums;
using TravelAgencyBusinessLogic.OfficePackage.HelperModels;
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Office2010.Excel;
using DocumentFormat.OpenXml.Office2013.Excel;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Spreadsheet;
namespace TravelAgencyBusinessLogic.OfficePackage.Implements
{
public class SaveToExcel : AbstractSaveToExcel
{
private SpreadsheetDocument? _spreadsheetDocument;
private SharedStringTablePart? _shareStringPart;
private Worksheet? _worksheet;
/// <summary>
/// Настройка стилей для файла
/// </summary>
/// <param name="workbookpart"></param>
private static void CreateStyles(WorkbookPart workbookpart)
{
var sp = workbookpart.AddNewPart<WorkbookStylesPart>();
sp.Stylesheet = new Stylesheet();
var fonts = new Fonts() { Count = 2U, KnownFonts = true };
var fontUsual = new Font();
fontUsual.Append(new FontSize() { Val = 12D });
fontUsual.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Theme = 1U });
fontUsual.Append(new FontName() { Val = "Times New Roman" });
fontUsual.Append(new FontFamilyNumbering() { Val = 2 });
fontUsual.Append(new FontScheme() { Val = FontSchemeValues.Minor });
var fontTitle = new Font();
fontTitle.Append(new Bold());
fontTitle.Append(new FontSize() { Val = 14D });
fontTitle.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Theme = 1U });
fontTitle.Append(new FontName() { Val = "Times New Roman" });
fontTitle.Append(new FontFamilyNumbering() { Val = 2 });
fontTitle.Append(new FontScheme() { Val = FontSchemeValues.Minor });
fonts.Append(fontUsual);
fonts.Append(fontTitle);
var fills = new Fills() { Count = 2U };
var fill1 = new Fill();
fill1.Append(new PatternFill() { PatternType = PatternValues.None });
var fill2 = new Fill();
fill2.Append(new PatternFill() { PatternType = PatternValues.Gray125 });
fills.Append(fill1);
fills.Append(fill2);
var borders = new Borders() { Count = 2U };
var borderNoBorder = new Border();
borderNoBorder.Append(new LeftBorder());
borderNoBorder.Append(new RightBorder());
borderNoBorder.Append(new TopBorder());
borderNoBorder.Append(new BottomBorder());
borderNoBorder.Append(new DiagonalBorder());
var borderThin = new Border();
var leftBorder = new LeftBorder() { Style = BorderStyleValues.Thin };
leftBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U });
var rightBorder = new RightBorder() { Style = BorderStyleValues.Thin };
rightBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U });
var topBorder = new TopBorder() { Style = BorderStyleValues.Thin };
topBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U });
var bottomBorder = new BottomBorder() { Style = BorderStyleValues.Thin };
bottomBorder.Append(new DocumentFormat.OpenXml.Office2010.Excel.Color() { Indexed = 64U });
borderThin.Append(leftBorder);
borderThin.Append(rightBorder);
borderThin.Append(topBorder);
borderThin.Append(bottomBorder);
borderThin.Append(new DiagonalBorder());
borders.Append(borderNoBorder);
borders.Append(borderThin);
var cellStyleFormats = new CellStyleFormats() { Count = 1U };
var cellFormatStyle = new CellFormat() { NumberFormatId = 0U, FontId = 0U, FillId = 0U, BorderId = 0U };
cellStyleFormats.Append(cellFormatStyle);
var cellFormats = new CellFormats() { Count = 3U };
var cellFormatFont = new CellFormat() { NumberFormatId = 0U, FontId = 0U, FillId = 0U, BorderId = 0U, FormatId = 0U, ApplyFont = true };
var cellFormatFontAndBorder = new CellFormat() { NumberFormatId = 0U, FontId = 0U, FillId = 0U, BorderId = 1U, FormatId = 0U, ApplyFont = true, ApplyBorder = true };
var cellFormatTitle = new CellFormat() { NumberFormatId = 0U, FontId = 1U, FillId = 0U, BorderId = 0U, FormatId = 0U, Alignment = new Alignment() { Vertical = VerticalAlignmentValues.Center, WrapText = true, Horizontal = HorizontalAlignmentValues.Center }, ApplyFont = true };
cellFormats.Append(cellFormatFont);
cellFormats.Append(cellFormatFontAndBorder);
cellFormats.Append(cellFormatTitle);
var cellStyles = new CellStyles() { Count = 1U };
cellStyles.Append(new CellStyle() { Name = "Normal", FormatId = 0U, BuiltinId = 0U });
var differentialFormats = new DocumentFormat.OpenXml.Office2013.Excel.DifferentialFormats() { Count = 0U };
var tableStyles = new TableStyles() { Count = 0U, DefaultTableStyle = "TableStyleMedium2", DefaultPivotStyle = "PivotStyleLight16" };
var stylesheetExtensionList = new StylesheetExtensionList();
var stylesheetExtension1 = new StylesheetExtension() { Uri = "{EB79DEF2-80B8-43e5-95BD-54CBDDF9020C}" };
stylesheetExtension1.AddNamespaceDeclaration("x14", "http://schemas.microsoft.com/office/spreadsheetml/2009/9/main");
stylesheetExtension1.Append(new SlicerStyles() { DefaultSlicerStyle = "SlicerStyleLight1" });
var stylesheetExtension2 = new StylesheetExtension() { Uri = "{9260A510-F301-46a8-8635-F512D64BE5F5}" };
stylesheetExtension2.AddNamespaceDeclaration("x15", "http://schemas.microsoft.com/office/spreadsheetml/2010/11/main");
stylesheetExtension2.Append(new TimelineStyles() { DefaultTimelineStyle = "TimeSlicerStyleLight1" });
stylesheetExtensionList.Append(stylesheetExtension1);
stylesheetExtensionList.Append(stylesheetExtension2);
sp.Stylesheet.Append(fonts);
sp.Stylesheet.Append(fills);
sp.Stylesheet.Append(borders);
sp.Stylesheet.Append(cellStyleFormats);
sp.Stylesheet.Append(cellFormats);
sp.Stylesheet.Append(cellStyles);
sp.Stylesheet.Append(differentialFormats);
sp.Stylesheet.Append(tableStyles);
sp.Stylesheet.Append(stylesheetExtensionList);
}
/// <summary>
/// Получение номера стиля из типа
/// </summary>
/// <param name="styleInfo"></param>
/// <returns></returns>
private static uint GetStyleValue(ExcelStyleInfoType styleInfo)
{
return styleInfo switch
{
ExcelStyleInfoType.Title => 2U,
ExcelStyleInfoType.TextWithBorder => 1U,
ExcelStyleInfoType.Text => 0U,
_ => 0U,
};
}
protected override void CreateExcel(ExcelInfo info)
{
_spreadsheetDocument = SpreadsheetDocument.Create(info.FileName, SpreadsheetDocumentType.Workbook);
// Создаем книгу (в ней хранятся листы)
var workbookpart = _spreadsheetDocument.AddWorkbookPart();
workbookpart.Workbook = new Workbook();
CreateStyles(workbookpart);
// Получаем/создаем хранилище текстов для книги
_shareStringPart = _spreadsheetDocument.WorkbookPart!.GetPartsOfType<SharedStringTablePart>().Any()
? _spreadsheetDocument.WorkbookPart.GetPartsOfType<SharedStringTablePart>().First()
: _spreadsheetDocument.WorkbookPart.AddNewPart<SharedStringTablePart>();
// Создаем SharedStringTable, если его нет
if (_shareStringPart.SharedStringTable == null)
{
_shareStringPart.SharedStringTable = new SharedStringTable();
}
// Создаем лист в книгу
var worksheetPart = workbookpart.AddNewPart<WorksheetPart>();
worksheetPart.Worksheet = new Worksheet(new SheetData());
// Добавляем лист в книгу
var sheets = _spreadsheetDocument.WorkbookPart.Workbook.AppendChild(new Sheets());
var sheet = new Sheet()
{
Id = _spreadsheetDocument.WorkbookPart.GetIdOfPart(worksheetPart),
SheetId = 1,
Name = "Лист"
};
sheets.Append(sheet);
_worksheet = worksheetPart.Worksheet;
}
protected override void InsertCellInWorksheet(ExcelCellParameters excelParams)
{
if (_worksheet == null || _shareStringPart == null)
{
return;
}
var sheetData = _worksheet.GetFirstChild<SheetData>();
if (sheetData == null)
{
return;
}
// Ищем строку, либо добавляем ее
Row row;
if (sheetData.Elements<Row>().Where(r => r.RowIndex! == excelParams.RowIndex).Any())
{
row = sheetData.Elements<Row>().Where(r => r.RowIndex! == excelParams.RowIndex).First();
}
else
{
row = new Row() { RowIndex = excelParams.RowIndex };
sheetData.Append(row);
}
// Ищем нужную ячейку
Cell cell;
if (row.Elements<Cell>().Where(c => c.CellReference!.Value == excelParams.CellReference).Any())
{
cell = row.Elements<Cell>().Where(c => c.CellReference!.Value == excelParams.CellReference).First();
}
else
{
// Все ячейки должны быть последовательно друг за другом расположены
// нужно определить, после какой вставлять
Cell? refCell = null;
foreach (Cell rowCell in row.Elements<Cell>())
{
if (string.Compare(rowCell.CellReference!.Value, excelParams.CellReference, true) > 0)
{
refCell = rowCell;
break;
}
}
var newCell = new Cell() { CellReference = excelParams.CellReference };
row.InsertBefore(newCell, refCell);
cell = newCell;
}
// вставляем новый текст
_shareStringPart.SharedStringTable.AppendChild(new SharedStringItem(new Text(excelParams.Text)));
_shareStringPart.SharedStringTable.Save();
cell.CellValue = new CellValue((_shareStringPart.SharedStringTable.Elements<SharedStringItem>().Count() - 1).ToString());
cell.DataType = new EnumValue<CellValues>(CellValues.SharedString);
cell.StyleIndex = GetStyleValue(excelParams.StyleInfo);
}
protected override void MergeCells(ExcelMergeParameters excelParams)
{
if (_worksheet == null)
{
return;
}
MergeCells mergeCells;
if (_worksheet.Elements<MergeCells>().Any())
{
mergeCells = _worksheet.Elements<MergeCells>().First();
}
else
{
mergeCells = new MergeCells();
if (_worksheet.Elements<CustomSheetView>().Any())
{
_worksheet.InsertAfter(mergeCells, _worksheet.Elements<CustomSheetView>().First());
}
else
{
_worksheet.InsertAfter(mergeCells, _worksheet.Elements<SheetData>().First());
}
}
var mergeCell = new MergeCell()
{
Reference = new StringValue(excelParams.Merge)
};
mergeCells.Append(mergeCell);
}
protected override void SaveExcel(ExcelInfo info)
{
if (_spreadsheetDocument == null)
{
return;
}
_spreadsheetDocument.WorkbookPart!.Workbook.Save();
_spreadsheetDocument.Dispose();
}
}
}

View File

@ -0,0 +1,114 @@
using TravelAgencyBusinessLogic.OfficePackage.HelperEnums;
using TravelAgencyBusinessLogic.OfficePackage.HelperModels;
using MigraDoc.DocumentObjectModel;
using MigraDoc.DocumentObjectModel.Tables;
using MigraDoc.Rendering;
namespace TravelAgencyBusinessLogic.OfficePackage.Implements
{
public class SaveToPdf : AbstractSaveToPdf
{
private Document? _document;
private Section? _section;
private Table? _table;
private static ParagraphAlignment GetParagraphAlignment(PdfParagraphAlignmentType type)
{
return type switch
{
PdfParagraphAlignmentType.Center => ParagraphAlignment.Center,
PdfParagraphAlignmentType.Left => ParagraphAlignment.Left,
PdfParagraphAlignmentType.Right => ParagraphAlignment.Right,
_ => ParagraphAlignment.Justify,
};
}
/// <summary>
/// Создание стилей для документа
/// </summary>
/// <param name="document"></param>
private static void DefineStyles(Document document)
{
var style = document.Styles["Normal"];
style.Font.Name = "Times New Roman";
style.Font.Size = 14;
style = document.Styles.AddStyle("NormalTitle", "Normal");
style.Font.Bold = true;
}
protected override void CreatePdf(PdfInfo info)
{
_document = new Document();
DefineStyles(_document);
_section = _document.AddSection();
}
protected override void CreateParagraph(PdfParagraph pdfParagraph)
{
if (_section == null)
{
return;
}
var paragraph = _section.AddParagraph(pdfParagraph.Text);
paragraph.Format.SpaceAfter = "1cm";
paragraph.Format.Alignment = GetParagraphAlignment(pdfParagraph.ParagraphAlignment);
paragraph.Style = pdfParagraph.Style;
}
protected override void CreateTable(List<string> columns)
{
if (_document == null)
{
return;
}
_table = _document.LastSection.AddTable();
foreach (var elem in columns)
{
_table.AddColumn(elem);
}
}
protected override void CreateRow(PdfRowParameters rowParameters)
{
if (_table == null)
{
return;
}
var row = _table.AddRow();
for (int i = 0; i < rowParameters.Texts.Count; ++i)
{
row.Cells[i].AddParagraph(rowParameters.Texts[i]);
if (!string.IsNullOrEmpty(rowParameters.Style))
{
row.Cells[i].Style = rowParameters.Style;
}
Unit borderWidth = 0.5;
row.Cells[i].Borders.Left.Width = borderWidth;
row.Cells[i].Borders.Right.Width = borderWidth;
row.Cells[i].Borders.Top.Width = borderWidth;
row.Cells[i].Borders.Bottom.Width = borderWidth;
row.Cells[i].Format.Alignment = GetParagraphAlignment(rowParameters.ParagraphAlignment);
row.Cells[i].VerticalAlignment = VerticalAlignment.Center;
}
}
protected override void SavePdf(PdfInfo info)
{
var renderer = new PdfDocumentRenderer(true)
{
Document = _document
};
renderer.RenderDocument();
renderer.PdfDocument.Save(info.FileName);
}
}
}

View File

@ -0,0 +1,135 @@
using TravelAgencyBusinessLogic.OfficePackage.HelperEnums;
using TravelAgencyBusinessLogic.OfficePackage.HelperModels;
using DocumentFormat.OpenXml;
using DocumentFormat.OpenXml.Packaging;
using DocumentFormat.OpenXml.Wordprocessing;
namespace TravelAgencyBusinessLogic.OfficePackage.Implements
{
public class SaveToWord : AbstractSaveToWord
{
private WordprocessingDocument? _wordDocument;
private Body? _docBody;
/// <summary>
/// Получение типа выравнивания
/// </summary>
/// <param name="type"></param>
/// <returns></returns>
private static JustificationValues GetJustificationValues(WordJustificationType type)
{
return type switch
{
WordJustificationType.Both => JustificationValues.Both,
WordJustificationType.Center => JustificationValues.Center,
_ => JustificationValues.Left,
};
}
/// <summary>
/// Настройки страницы
/// </summary>
/// <returns></returns>
private static SectionProperties CreateSectionProperties()
{
var properties = new SectionProperties();
var pageSize = new PageSize
{
Orient = PageOrientationValues.Portrait
};
properties.AppendChild(pageSize);
return properties;
}
/// <summary>
/// Задание форматирования для абзаца
/// </summary>
/// <param name="paragraphProperties"></param>
/// <returns></returns>
private static ParagraphProperties? CreateParagraphProperties(WordTextProperties? paragraphProperties)
{
if (paragraphProperties == null)
{
return null;
}
var properties = new ParagraphProperties();
properties.AppendChild(new Justification()
{
Val = GetJustificationValues(paragraphProperties.JustificationType)
});
properties.AppendChild(new SpacingBetweenLines
{
LineRule = LineSpacingRuleValues.Auto
});
properties.AppendChild(new Indentation());
var paragraphMarkRunProperties = new ParagraphMarkRunProperties();
if (!string.IsNullOrEmpty(paragraphProperties.Size))
{
paragraphMarkRunProperties.AppendChild(new FontSize { Val = paragraphProperties.Size });
}
properties.AppendChild(paragraphMarkRunProperties);
return properties;
}
protected override void CreateWord(WordInfo info)
{
_wordDocument = WordprocessingDocument.Create(info.FileName, WordprocessingDocumentType.Document);
MainDocumentPart mainPart = _wordDocument.AddMainDocumentPart();
mainPart.Document = new Document();
_docBody = mainPart.Document.AppendChild(new Body());
}
protected override void CreateParagraph(WordParagraph paragraph)
{
if (_docBody == null || paragraph == null)
{
return;
}
var docParagraph = new Paragraph();
docParagraph.AppendChild(CreateParagraphProperties(paragraph.TextProperties));
foreach (var run in paragraph.Texts)
{
var docRun = new Run();
var properties = new RunProperties();
properties.AppendChild(new FontSize { Val = run.Item2.Size });
if (run.Item2.Bold)
{
properties.AppendChild(new Bold());
}
docRun.AppendChild(properties);
docRun.AppendChild(new Text { Text = run.Item1, Space = SpaceProcessingModeValues.Preserve });
docParagraph.AppendChild(docRun);
}
_docBody.AppendChild(docParagraph);
}
protected override void SaveWord(WordInfo info)
{
if (_docBody == null || _wordDocument == null)
{
return;
}
_docBody.AppendChild(CreateSectionProperties());
_wordDocument.MainDocumentPart!.Document.Save();
_wordDocument.Dispose();
}
}
}

View File

@ -7,7 +7,10 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="DocumentFormat.OpenXml" Version="3.0.2" />
<PackageReference Include="MailKit" Version="4.6.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.1" />
<PackageReference Include="PdfSharp.MigraDoc.Standard" Version="1.51.15" />
</ItemGroup>
<ItemGroup>

View File

@ -14,6 +14,8 @@ namespace TravelAgencyContracts.BindingModels
public int UserId { get; set; }
public int PlaceId { get; set; }
public Dictionary<int, ITourModel> ExcursionTours { get; set; } = new();
}
}

View File

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TravelAgencyContracts.BindingModels
{
public class MailConfigModel
{
public string MailLogin { get; set; } = string.Empty;
public string MailPassword { get; set; } = string.Empty;
public string SmtpClientHost { get; set; } = string.Empty;
public int SmtpClientPort { get; set; }
public string PopHost { get; set; } = string.Empty;
public int PopPort { get; set; }
}
}

View File

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TravelAgencyContracts.BindingModels
{
public class MailSendInfoBindingModel
{
public string MailAddress { get; set; } = string.Empty;
public string Subject { get; set; } = string.Empty;
public string Text { get; set; } = string.Empty;
public byte[] Pdf { get; set; }
public string FileName { get; set; } = string.Empty;
}
}

View File

@ -9,7 +9,5 @@ namespace TravelAgencyContracts.BindingModels
public string PlaceName { get; set; } = string.Empty;
public string PlaceAddress { get; set; } = string.Empty;
public int ExcursionId { get; set; }
}
}

View File

@ -0,0 +1,15 @@
namespace TravelAgencyContracts.BindingModels
{
public class ReportBindingModel
{
public string FileName { get; set; } = string.Empty;
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
public int UserId { get; set; }
public List<int>? Tours = new();
}
}

View File

@ -0,0 +1,16 @@
using TravelAgencyContracts.BindingModels;
using TravelAgencyContracts.ViewModels;
namespace TravelAgencyContracts.BusinessLogicsContracts
{
public interface IReportLogic
{
List<ReportTourPlaceViewModel> GetTourPlaces(ReportBindingModel model);
List<ReportTourPeriodViewModel> GetTourPeriod(ReportBindingModel model);
void SaveTourPlacesToWordFile(ReportBindingModel model);
void SaveTourPlacesToExcelFile(ReportBindingModel model);
}
}

View File

@ -7,5 +7,7 @@
public string? ExcursionName { get; set; }
public int? UserId { get; set; }
public int? PlaceId { get; set; }
}
}

View File

@ -7,7 +7,5 @@
public string? PlaceName { get; set; }
public string? PlaceAddress { get; set; }
public int? ExcursionId { get; set; }
}
}

View File

@ -7,5 +7,9 @@
public string? TourName { get; set; }
public int? UserId { get; set; }
public DateTime? DateFrom { get; set; }
public DateTime? DateTo { get; set; }
}
}

View File

@ -18,6 +18,10 @@ namespace TravelAgencyContracts.ViewModels
public int UserId { get; set; }
public int PlaceId { get; set; }
public string? PlaceName { get; set; } = string.Empty;
public Dictionary<int, ITourModel> ExcursionTours { get; set; } = new();
}
}

View File

@ -12,7 +12,5 @@ namespace TravelAgencyContracts.ViewModels
[DisplayName("Адрес места")]
public string PlaceAddress { get; set; } = string.Empty;
public int ExcursionId { get; set; }
}
}

View File

@ -1,8 +0,0 @@
namespace TravelAgencyContracts.ViewModels
{
public class ReportPlaceTourViewModel
{
public string TourName { get; set; } = string.Empty;
public List<string> Places { get; set; } = new();
}
}

View File

@ -2,8 +2,10 @@
{
public class ReportTourPeriodViewModel
{
public string TourName { get; set; } = string.Empty;
public List<string> ExcursionGroups { get; set; } = new();
public List<string> Guides { get; set; } = new();
public TourViewModel Tour { get; set; } = new();
public HashSet<ExcursionGroupViewModel> ExcursionGroups { get; set; } = new();
public HashSet<GuideViewModel> Guides { get; set; } = new();
}
}

View File

@ -0,0 +1,9 @@
namespace TravelAgencyContracts.ViewModels
{
public class ReportTourPlaceViewModel
{
public TourViewModel Tour { get; set; } = new();
public HashSet<PlaceViewModel> Places { get; set; } = new();
}
}

View File

@ -10,6 +10,8 @@
int UserId { get; }
int PlaceId { get; }
Dictionary<int, ITourModel> ExcursionTours { get; }
}
}

View File

@ -5,7 +5,5 @@
string PlaceName { get; }
string PlaceAddress { get; }
int ExcursionId { get; }
}
}

View File

@ -14,6 +14,7 @@ namespace TravelAgencyDatabaseImplement.Implements
using var context = new TravelAgencyDatabase();
return context.Excursions
.Include(x => x.User)
.Include(x => x.Place)
.Include(x => x.Tours)
.ThenInclude(x => x.Tour)
.ToList()
@ -28,6 +29,7 @@ namespace TravelAgencyDatabaseImplement.Implements
{
return context.Excursions
.Include(x => x.User)
.Include(x => x.Place)
.Include(x => x.Tours)
.ThenInclude(x => x.Tour)
.Where(x => x.ExcursionName.Contains(model.ExcursionName))
@ -39,6 +41,7 @@ namespace TravelAgencyDatabaseImplement.Implements
{
return context.Excursions
.Include(x => x.User)
.Include(x => x.Place)
.Include(x => x.Tours)
.ThenInclude(x => x.Tour)
.Where(x => x.UserId.Equals(model.UserId))
@ -46,6 +49,18 @@ namespace TravelAgencyDatabaseImplement.Implements
.Select(x => x.GetViewModel)
.ToList();
}
if (model.PlaceId.HasValue)
{
return context.Excursions
.Include(x => x.User)
.Include(x => x.Place)
.Include(x => x.Tours)
.ThenInclude(x => x.Tour)
.Where(x => x.PlaceId.Equals(model.PlaceId))
.ToList()
.Select(x => x.GetViewModel)
.ToList();
}
return new();
}
@ -58,6 +73,7 @@ namespace TravelAgencyDatabaseImplement.Implements
using var context = new TravelAgencyDatabase();
return context.Excursions
.Include(x => x.User)
.Include(x => x.Place)
.Include(x => x.Tours)
.ThenInclude(x => x.Tour)
.FirstOrDefault(x => (!string.IsNullOrEmpty(model.ExcursionName) && x.ExcursionName == model.ExcursionName) ||

View File

@ -13,7 +13,6 @@ namespace TravelAgencyDatabaseImplement.Implements
{
using var context = new TravelAgencyDatabase();
return context.Places
.Include(x => x.Excursion)
.Select(x => x.GetViewModel)
.ToList();
}
@ -24,19 +23,10 @@ namespace TravelAgencyDatabaseImplement.Implements
if (!string.IsNullOrEmpty(model.PlaceName))
{
return context.Places
.Include(x => x.Excursion)
.Where(x => x.PlaceName.Contains(model.PlaceName))
.Select(x => x.GetViewModel)
.ToList();
}
if (model.ExcursionId.HasValue)
{
return context.Places
.Include(x => x.Excursion)
.Where(x => x.ExcursionId.Equals(model.ExcursionId))
.Select(x => x.GetViewModel)
.ToList();
}
return new();
}
@ -75,7 +65,6 @@ namespace TravelAgencyDatabaseImplement.Implements
context.Places.Add(newPlace);
context.SaveChanges();
return context.Places
.Include(x => x.Excursion)
.FirstOrDefault(x => x.Id == newPlace.Id)
?.GetViewModel;
}
@ -91,7 +80,6 @@ namespace TravelAgencyDatabaseImplement.Implements
place.Update(model);
context.SaveChanges();
return context.Places
.Include(x => x.Excursion)
.FirstOrDefault(x => x.Id == model.Id)
?.GetViewModel;
}
@ -103,7 +91,6 @@ namespace TravelAgencyDatabaseImplement.Implements
if (element != null)
{
var deletedElement = context.Places
.Include(x => x.Excursion)
.FirstOrDefault(x => x.Id == model.Id)
?.GetViewModel;
context.Places.Remove(element);

View File

@ -21,23 +21,24 @@ namespace TravelAgencyDatabaseImplement.Implements
public List<TourViewModel> GetFilteredList(TourSearchModel model)
{
using var context = new TravelAgencyDatabase();
if (!string.IsNullOrEmpty(model.TourName))
{
return context.Tours
.Include(x => x.User)
.Where(x => x.TourName.Contains(model.TourName))
var tours = context.Tours.Include(x => x.User)
.Select(x => x.GetViewModel)
.ToList();
if (!string.IsNullOrEmpty(model.TourName))
{
tours = tours.Where(x => x.TourName.Contains(model.TourName)).ToList();
}
if (model.UserId.HasValue)
{
return context.Tours
.Include(x => x.User)
.Where(x => x.UserId.Equals(model.UserId))
.Select(x => x.GetViewModel)
.ToList();
tours = tours.Where(x => x.UserId.Equals(model.UserId)).ToList();
}
return new();
if (model.DateFrom.HasValue && model.DateTo.HasValue)
{
tours = tours.Where(x => x.TourDate >= model.DateFrom && x.TourDate <= model.DateTo).ToList();
}
return tours ?? new();
}
public TourViewModel? GetElement(TourSearchModel model)

View File

@ -12,7 +12,7 @@ using TravelAgencyDatabaseImplement;
namespace TravelAgencyDatabaseImplement.Migrations
{
[DbContext(typeof(TravelAgencyDatabase))]
[Migration("20240429175309_InitialCreate")]
[Migration("20240529001818_InitialCreate")]
partial class InitialCreate
{
/// <inheritdoc />
@ -41,6 +41,9 @@ namespace TravelAgencyDatabaseImplement.Migrations
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("PlaceId")
.HasColumnType("int");
b.Property<double>("Price")
.HasColumnType("float");
@ -49,6 +52,8 @@ namespace TravelAgencyDatabaseImplement.Migrations
b.HasKey("Id");
b.HasIndex("PlaceId");
b.HasIndex("UserId");
b.ToTable("Excursions");
@ -163,9 +168,6 @@ namespace TravelAgencyDatabaseImplement.Migrations
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ExcursionId")
.HasColumnType("int");
b.Property<string>("PlaceAddress")
.IsRequired()
.HasColumnType("nvarchar(max)");
@ -176,8 +178,6 @@ namespace TravelAgencyDatabaseImplement.Migrations
b.HasKey("Id");
b.HasIndex("ExcursionId");
b.ToTable("Places");
});
@ -292,12 +292,20 @@ namespace TravelAgencyDatabaseImplement.Migrations
modelBuilder.Entity("TravelAgencyDatabaseImplement.Models.Excursion", b =>
{
b.HasOne("TravelAgencyDatabaseImplement.Models.Place", "Place")
.WithMany("Excursions")
.HasForeignKey("PlaceId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("TravelAgencyDatabaseImplement.Models.User", "User")
.WithMany("Excursions")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.Navigation("Place");
b.Navigation("User");
});
@ -358,17 +366,6 @@ namespace TravelAgencyDatabaseImplement.Migrations
b.Navigation("Tour");
});
modelBuilder.Entity("TravelAgencyDatabaseImplement.Models.Place", b =>
{
b.HasOne("TravelAgencyDatabaseImplement.Models.Excursion", "Excursion")
.WithMany("Places")
.HasForeignKey("ExcursionId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Excursion");
});
modelBuilder.Entity("TravelAgencyDatabaseImplement.Models.Tour", b =>
{
b.HasOne("TravelAgencyDatabaseImplement.Models.User", "User")
@ -412,8 +409,6 @@ namespace TravelAgencyDatabaseImplement.Migrations
modelBuilder.Entity("TravelAgencyDatabaseImplement.Models.Excursion", b =>
{
b.Navigation("Places");
b.Navigation("Tours");
});
@ -431,6 +426,8 @@ namespace TravelAgencyDatabaseImplement.Migrations
modelBuilder.Entity("TravelAgencyDatabaseImplement.Models.Place", b =>
{
b.Navigation("Excursions");
b.Navigation("Trips");
});

View File

@ -26,6 +26,20 @@ namespace TravelAgencyDatabaseImplement.Migrations
table.PrimaryKey("PK_Guides", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Places",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
PlaceName = table.Column<string>(type: "nvarchar(max)", nullable: false),
PlaceAddress = table.Column<string>(type: "nvarchar(max)", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Places", x => x.Id);
});
migrationBuilder.CreateTable(
name: "Users",
columns: table => new
@ -100,11 +114,18 @@ namespace TravelAgencyDatabaseImplement.Migrations
ExcursionName = table.Column<string>(type: "nvarchar(max)", nullable: false),
ExcursionDescription = table.Column<string>(type: "nvarchar(max)", nullable: false),
Price = table.Column<double>(type: "float", nullable: false),
UserId = table.Column<int>(type: "int", nullable: false)
UserId = table.Column<int>(type: "int", nullable: false),
PlaceId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Excursions", x => x.Id);
table.ForeignKey(
name: "FK_Excursions_Places_PlaceId",
column: x => x.PlaceId,
principalTable: "Places",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_Excursions_Users_UserId",
column: x => x.UserId,
@ -137,22 +158,27 @@ namespace TravelAgencyDatabaseImplement.Migrations
});
migrationBuilder.CreateTable(
name: "Places",
name: "TripPlaces",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
PlaceName = table.Column<string>(type: "nvarchar(max)", nullable: false),
PlaceAddress = table.Column<string>(type: "nvarchar(max)", nullable: false),
ExcursionId = table.Column<int>(type: "int", nullable: false)
TripId = table.Column<int>(type: "int", nullable: false),
PlaceId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Places", x => x.Id);
table.PrimaryKey("PK_TripPlaces", x => x.Id);
table.ForeignKey(
name: "FK_Places_Excursions_ExcursionId",
column: x => x.ExcursionId,
principalTable: "Excursions",
name: "FK_TripPlaces_Places_PlaceId",
column: x => x.PlaceId,
principalTable: "Places",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_TripPlaces_Trips_TripId",
column: x => x.TripId,
principalTable: "Trips",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
@ -209,32 +235,6 @@ namespace TravelAgencyDatabaseImplement.Migrations
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateTable(
name: "TripPlaces",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
TripId = table.Column<int>(type: "int", nullable: false),
PlaceId = table.Column<int>(type: "int", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_TripPlaces", x => x.Id);
table.ForeignKey(
name: "FK_TripPlaces_Places_PlaceId",
column: x => x.PlaceId,
principalTable: "Places",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
table.ForeignKey(
name: "FK_TripPlaces_Trips_TripId",
column: x => x.TripId,
principalTable: "Trips",
principalColumn: "Id",
onDelete: ReferentialAction.Cascade);
});
migrationBuilder.CreateIndex(
name: "IX_ExcursionGroups_GuideId",
table: "ExcursionGroups",
@ -255,6 +255,11 @@ namespace TravelAgencyDatabaseImplement.Migrations
table: "ExcursionGroupTours",
column: "TourId");
migrationBuilder.CreateIndex(
name: "IX_Excursions_PlaceId",
table: "Excursions",
column: "PlaceId");
migrationBuilder.CreateIndex(
name: "IX_Excursions_UserId",
table: "Excursions",
@ -270,11 +275,6 @@ namespace TravelAgencyDatabaseImplement.Migrations
table: "ExcursionTours",
column: "TourId");
migrationBuilder.CreateIndex(
name: "IX_Places_ExcursionId",
table: "Places",
column: "ExcursionId");
migrationBuilder.CreateIndex(
name: "IX_Tours_UserId",
table: "Tours",
@ -312,22 +312,22 @@ namespace TravelAgencyDatabaseImplement.Migrations
name: "ExcursionGroups");
migrationBuilder.DropTable(
name: "Tours");
name: "Excursions");
migrationBuilder.DropTable(
name: "Places");
name: "Tours");
migrationBuilder.DropTable(
name: "Trips");
migrationBuilder.DropTable(
name: "Excursions");
migrationBuilder.DropTable(
name: "Guides");
name: "Places");
migrationBuilder.DropTable(
name: "Users");
migrationBuilder.DropTable(
name: "Guides");
}
}
}

View File

@ -38,6 +38,9 @@ namespace TravelAgencyDatabaseImplement.Migrations
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("PlaceId")
.HasColumnType("int");
b.Property<double>("Price")
.HasColumnType("float");
@ -46,6 +49,8 @@ namespace TravelAgencyDatabaseImplement.Migrations
b.HasKey("Id");
b.HasIndex("PlaceId");
b.HasIndex("UserId");
b.ToTable("Excursions");
@ -160,9 +165,6 @@ namespace TravelAgencyDatabaseImplement.Migrations
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<int>("ExcursionId")
.HasColumnType("int");
b.Property<string>("PlaceAddress")
.IsRequired()
.HasColumnType("nvarchar(max)");
@ -173,8 +175,6 @@ namespace TravelAgencyDatabaseImplement.Migrations
b.HasKey("Id");
b.HasIndex("ExcursionId");
b.ToTable("Places");
});
@ -289,12 +289,20 @@ namespace TravelAgencyDatabaseImplement.Migrations
modelBuilder.Entity("TravelAgencyDatabaseImplement.Models.Excursion", b =>
{
b.HasOne("TravelAgencyDatabaseImplement.Models.Place", "Place")
.WithMany("Excursions")
.HasForeignKey("PlaceId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.HasOne("TravelAgencyDatabaseImplement.Models.User", "User")
.WithMany("Excursions")
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Restrict)
.IsRequired();
b.Navigation("Place");
b.Navigation("User");
});
@ -355,17 +363,6 @@ namespace TravelAgencyDatabaseImplement.Migrations
b.Navigation("Tour");
});
modelBuilder.Entity("TravelAgencyDatabaseImplement.Models.Place", b =>
{
b.HasOne("TravelAgencyDatabaseImplement.Models.Excursion", "Excursion")
.WithMany("Places")
.HasForeignKey("ExcursionId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
b.Navigation("Excursion");
});
modelBuilder.Entity("TravelAgencyDatabaseImplement.Models.Tour", b =>
{
b.HasOne("TravelAgencyDatabaseImplement.Models.User", "User")
@ -409,8 +406,6 @@ namespace TravelAgencyDatabaseImplement.Migrations
modelBuilder.Entity("TravelAgencyDatabaseImplement.Models.Excursion", b =>
{
b.Navigation("Places");
b.Navigation("Tours");
});
@ -428,6 +423,8 @@ namespace TravelAgencyDatabaseImplement.Migrations
modelBuilder.Entity("TravelAgencyDatabaseImplement.Models.Place", b =>
{
b.Navigation("Excursions");
b.Navigation("Trips");
});

View File

@ -25,6 +25,11 @@ namespace TravelAgencyDatabaseImplement.Models
[DeleteBehavior(DeleteBehavior.Restrict)]
public virtual User User { get; set; }
[Required]
public int PlaceId { get; set; }
public virtual Place Place { get; set; }
private Dictionary<int, ITourModel>? _excursionTours = null;
[NotMapped]
@ -44,9 +49,6 @@ namespace TravelAgencyDatabaseImplement.Models
[ForeignKey("ExcursionId")]
public virtual List<ExcursionTour> Tours { get; set; } = new();
[ForeignKey("ExcursionId")]
public virtual List<Place> Places { get; set; } = new();
public static Excursion? Create(TravelAgencyDatabase context, ExcursionBindingModel? model)
{
if (model == null)
@ -60,6 +62,9 @@ namespace TravelAgencyDatabaseImplement.Models
ExcursionDescription = model.ExcursionDescription,
Price = model.Price,
UserId = model.UserId,
PlaceId = model.PlaceId,
Place = context.Places
.First(x => x.Id == model.PlaceId),
Tours = model.ExcursionTours.Select(x => new ExcursionTour
{
Tour = context.Tours.First(y => y.Id == x.Key)
@ -72,9 +77,13 @@ namespace TravelAgencyDatabaseImplement.Models
{
return;
}
using var context = new TravelAgencyDatabase();
ExcursionName = model.ExcursionName;
ExcursionDescription = model.ExcursionDescription;
Price = model.Price;
PlaceId = model.PlaceId;
Place = context.Places
.First(x => x.Id == model.PlaceId);
}
public ExcursionViewModel GetViewModel => new()
@ -84,6 +93,8 @@ namespace TravelAgencyDatabaseImplement.Models
ExcursionDescription = ExcursionDescription,
Price = Price,
UserId = UserId,
PlaceId = PlaceId,
PlaceName = Place?.PlaceName,
ExcursionTours = ExcursionTours
};

View File

@ -21,14 +21,13 @@ namespace TravelAgencyDatabaseImplement.Models
[Required]
public string PlaceAddress { get; set; } = string.Empty;
[Required]
public int ExcursionId { get; set; }
public virtual Excursion Excursion { get; set; }
[ForeignKey("PlaceId")]
public virtual List<TripPlace> Trips { get; set; } = new();
[ForeignKey("PlaceId")]
public virtual List<Excursion> Excursions { get; set; } = new();
public static Place? Create(PlaceBindingModel? model)
{
if (model == null)
@ -39,8 +38,7 @@ namespace TravelAgencyDatabaseImplement.Models
{
Id = model.Id,
PlaceName = model.PlaceName,
PlaceAddress = model.PlaceAddress,
ExcursionId = model.ExcursionId
PlaceAddress = model.PlaceAddress
};
}
public void Update(PlaceBindingModel? model)
@ -51,15 +49,13 @@ namespace TravelAgencyDatabaseImplement.Models
}
PlaceName = model.PlaceName;
PlaceAddress = model.PlaceAddress;
ExcursionId = model.ExcursionId;
}
public PlaceViewModel GetViewModel => new()
{
Id = Id,
PlaceName = PlaceName,
PlaceAddress = PlaceAddress,
ExcursionId = ExcursionId
PlaceAddress = PlaceAddress
};
}
}

View File

@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Mvc;
using DocumentFormat.OpenXml.Presentation;
using Microsoft.AspNetCore.Mvc;
using TravelAgencyContracts.BindingModels;
using TravelAgencyContracts.BusinessLogicsContracts;
using TravelAgencyContracts.SearchModels;
@ -15,11 +16,14 @@ namespace TravelAgencyWebApp.Controllers
private readonly ITourLogic _tourLogic;
public ExcursionController(ILogger<ExcursionController> logger, IExcursionLogic excursionLogic, ITourLogic tourLogic)
private readonly IPlaceLogic _placeLogic;
public ExcursionController(ILogger<ExcursionController> logger, IExcursionLogic excursionLogic, ITourLogic tourLogic, IPlaceLogic placeLogic)
{
_logger = logger;
_excursionLogic = excursionLogic;
_tourLogic = tourLogic;
_placeLogic = placeLogic;
}
[HttpGet]
@ -49,18 +53,20 @@ namespace TravelAgencyWebApp.Controllers
UserId = LoggedinUser.User.Id,
});
ViewBag.Places = _placeLogic.ReadList(null);
return View();
}
[HttpPost]
public void CreateExcursion(string excursionName, string excursionDescription, double price, List<int> tours)
public void CreateExcursion(string excursionName, string excursionDescription, int place, double price, List<int> tours)
{
if (LoggedinUser.User == null)
{
throw new Exception("Необходимо авторизоваться!");
}
if (string.IsNullOrEmpty(excursionName) || string.IsNullOrEmpty(excursionDescription) || price <= 0 || tours == null)
if (string.IsNullOrEmpty(excursionName) || string.IsNullOrEmpty(excursionDescription) || price <= 0 || place <= 0 || tours == null)
{
throw new Exception("Введены не все данные!");
}
@ -77,6 +83,7 @@ namespace TravelAgencyWebApp.Controllers
ExcursionDescription = excursionDescription,
Price = price,
UserId = LoggedinUser.User.Id,
PlaceId = place,
ExcursionTours = excursionTours
});
@ -96,6 +103,8 @@ namespace TravelAgencyWebApp.Controllers
UserId = LoggedinUser.User.Id,
});
ViewBag.Places = _placeLogic.ReadList(null);
return View(_excursionLogic.ReadElement(new ExcursionSearchModel
{
Id = id
@ -103,14 +112,14 @@ namespace TravelAgencyWebApp.Controllers
}
[HttpPost]
public void UpdateExcursion(int id, string excursionName, string excursionDescription, double price, List<int> tours)
public void UpdateExcursion(int id, string excursionName, string excursionDescription, int place, double price, List<int> tours)
{
if (LoggedinUser.User == null)
{
throw new Exception("Необходимо авторизоваться!");
}
if (string.IsNullOrEmpty(excursionName) || string.IsNullOrEmpty(excursionDescription) || price <= 0 || tours == null)
if (string.IsNullOrEmpty(excursionName) || string.IsNullOrEmpty(excursionDescription) || price <= 0 || place <= 0 || tours == null)
{
throw new Exception("Введены не все данные!");
}
@ -128,6 +137,7 @@ namespace TravelAgencyWebApp.Controllers
ExcursionDescription = excursionDescription,
Price = price,
UserId = LoggedinUser.User.Id,
PlaceId = place,
ExcursionTours = excursionTours
});

View File

@ -5,6 +5,12 @@ using Microsoft.AspNetCore.Mvc;
using System.Diagnostics;
using TravelAgencyContracts.BusinessLogicsContracts;
using TravelAgencyContracts.SearchModels;
using TravelAgencyBusinessLogic.BusinessLogics;
using DocumentFormat.OpenXml.Spreadsheet;
using TravelAgencyBusinessLogic.OfficePackage;
using TravelAgencyBusinessLogic.MailWorker;
using DocumentFormat.OpenXml.Wordprocessing;
using TravelAgencyDatabaseImplement.Models;
namespace TravelAgencyWebApp.Controllers
{
@ -14,10 +20,25 @@ namespace TravelAgencyWebApp.Controllers
private readonly IUserLogic _userLogic;
public HomeController(ILogger<HomeController> logger, IUserLogic userLogic)
private readonly IReportLogic _reportLogic;
private readonly ITourLogic _tourLogic;
private readonly IGuideLogic _guideLogic;
private readonly AbstractSaveToPdf _pdfLogic;
private readonly AbstractMailWorker _mailLogic;
public HomeController(ILogger<HomeController> logger, IUserLogic userLogic, IReportLogic reportLogic, ITourLogic tourLogic, IGuideLogic guideLogic, AbstractSaveToPdf pdfLogic, AbstractMailWorker mailLogic)
{
_logger = logger;
_userLogic = userLogic;
_reportLogic = reportLogic;
_tourLogic = tourLogic;
_guideLogic = guideLogic;
_pdfLogic = pdfLogic;
_mailLogic = mailLogic;
}
public IActionResult Index()
@ -41,21 +62,6 @@ namespace TravelAgencyWebApp.Controllers
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
[HttpGet]
public IActionResult ReportMenu()
{
return View();
}
[HttpGet]
public IActionResult ReportPlaceTour()
{
return View(new List<ReportPlaceTourViewModel>());
}
[HttpGet]
public IActionResult ReportTourPeriod()
{
return View(new List<ReportTourPeriodViewModel>());
}
[HttpGet]
public IActionResult Enter()
@ -130,5 +136,143 @@ namespace TravelAgencyWebApp.Controllers
Response.Redirect("Enter");
}
[HttpGet]
public IActionResult ReportMenu()
{
return View();
}
[HttpGet]
public IActionResult ReportTourPlace()
{
if (LoggedinUser.User == null)
{
return Redirect("~/Home/Enter");
}
ViewBag.Tours = _tourLogic.ReadList(new TourSearchModel
{
UserId = LoggedinUser.User.Id,
});
return View();
}
[HttpGet]
public IActionResult ReportTourPeriod()
{
if (LoggedinUser.User == null)
{
return Redirect("~/Home/Enter");
}
return View();
}
[HttpPost]
public IActionResult ReportTourPeriod(DateTime dateFrom, DateTime dateTo)
{
if (LoggedinUser.User == null)
{
return Redirect("~/Home/Enter");
}
if (dateFrom == DateTime.MinValue || dateTo == DateTime.MinValue)
{
throw new Exception("Введены не все данные!");
}
ViewBag.DateFrom = dateFrom;
ViewBag.DateTo = dateTo;
return View(_reportLogic.GetTourPeriod(new ReportBindingModel
{
DateFrom = dateFrom,
DateTo = dateTo,
UserId = LoggedinUser.User.Id
}));
}
[HttpPost]
public IActionResult CreateReport(List<int> tours, string type)
{
if (LoggedinUser.User == null)
{
throw new Exception("Необходимо авторизоваться!");
}
if (tours == null)
{
throw new Exception("Выберите туры!");
}
if (type.Equals("docx"))
{
_reportLogic.SaveTourPlacesToWordFile(new ReportBindingModel
{
FileName = $@"C:\Users\User\Downloads\Список мест по турам{DateTime.Now.ToString("dd-MM-yyyy HH-mm-ss")}.docx",
UserId = LoggedinUser.User.Id,
Tours = tours
});
} else if (type.Equals("xlsx"))
{
_reportLogic.SaveTourPlacesToExcelFile(new ReportBindingModel
{
FileName = $@"C:\Users\User\Downloads\Список мест по турам{DateTime.Now.ToString("dd-MM-yyyy HH-mm-ss")}.xlsx",
UserId = LoggedinUser.User.Id,
Tours = tours
});
}
ViewBag.Tours = _tourLogic.ReadList(new TourSearchModel
{
UserId = LoggedinUser.User.Id,
});
return View("ReportTourPlace", tours);
}
[HttpPost]
public void SentPdfToMail(DateTime dateFrom, DateTime dateTo)
{
if (LoggedinUser.User == null)
{
throw new Exception("Необходимо авторизоваться!");
}
if (dateFrom == DateTime.MinValue || dateTo == DateTime.MinValue)
{
throw new Exception("Введены не все данные!");
}
using (MemoryStream memoryStream = new MemoryStream())
{
SendMailReport(dateFrom, dateTo, memoryStream);
}
Response.Redirect("/Home/ReportTourPeriod");
}
public void SendMailReport(DateTime? dateFrom, DateTime? dateTo, MemoryStream stream)
{
var tours = _reportLogic.GetTourPeriod(new ReportBindingModel
{
DateFrom = dateFrom,
DateTo = dateTo,
UserId = LoggedinUser.User.Id,
});
if (tours == null)
return;
_pdfLogic.CreateDoc(new()
{
DateFrom = dateFrom!.Value,
DateTo = dateTo!.Value,
FileName = stream,
Tours = tours,
Title = "Отчет"
});
byte[] report = stream.GetBuffer();
_mailLogic.MailSendAsync(new() { MailAddress = LoggedinUser.User.Email, Subject = "Отчет", FileName = "PdfReport.pdf", Pdf = report });
}
}
}

View File

@ -1,7 +1,11 @@
using TravelAgencyBusinessLogic.BusinessLogics;
using TravelAgencyBusinessLogic.OfficePackage.Implements;
using TravelAgencyBusinessLogic.OfficePackage;
using TravelAgencyContracts.BusinessLogicsContracts;
using TravelAgencyContracts.StoragesContracts;
using TravelAgencyDatabaseImplement.Implements;
using TravelAgencyWebApp;
using TravelAgencyBusinessLogic.MailWorker;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
@ -23,8 +27,33 @@ builder.Services.AddTransient<IGuideLogic, GuideLogic>();
builder.Services.AddTransient<IPlaceLogic, PlaceLogic>();
builder.Services.AddTransient<ITripLogic, TripLogic>();
builder.Services.AddTransient<IReportLogic, ReportLogic>();
builder.Services.AddTransient<AbstractSaveToWord, SaveToWord>();
builder.Services.AddTransient<AbstractSaveToExcel, SaveToExcel>();
builder.Services.AddTransient<AbstractSaveToPdf, SaveToPdf>();
builder.Services.AddSingleton<AbstractMailWorker, MailKitWorker>();
var app = builder.Build();
var mailSender = app.Services.GetService<AbstractMailWorker>();
mailSender?.MailConfig(new()
{
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())
});
var guideLogic = app.Services.GetService<IGuideLogic>();
var tripLogic = app.Services.GetService<ITripLogic>();
var placeLogic = app.Services.GetService<IPlaceLogic>();
var seeder = new SeedingService(guideLogic, tripLogic, placeLogic);
seeder.SeedGuarantor();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{

View File

@ -0,0 +1,109 @@
using DocumentFormat.OpenXml.Bibliography;
using System.Drawing;
using TravelAgencyBusinessLogic.BusinessLogics;
using TravelAgencyContracts.BindingModels;
using TravelAgencyContracts.BusinessLogicsContracts;
using TravelAgencyContracts.SearchModels;
using TravelAgencyContracts.ViewModels;
using TravelAgencyDatabaseImplement.Models;
using TravelAgencyDataModels.Models;
namespace TravelAgencyWebApp
{
public class SeedingService
{
private readonly IGuideLogic _guideLogic;
private readonly ITripLogic _tripLogic;
private readonly IPlaceLogic _placeLogic;
public SeedingService(IGuideLogic guideLogic, ITripLogic tripLogic, IPlaceLogic placeLogic)
{
_guideLogic = guideLogic;
_tripLogic = tripLogic;
_placeLogic = placeLogic;
}
public void SeedGuarantor()
{
if (_guideLogic.ReadList(null) == null || _guideLogic.ReadList(null)?.ToList().Count < 1)
{
string[] domains = { "gmail.com", "yahoo.com", "hotmail.com", "outlook.com" };
string[] prefixes = { "ivan", "pavel", "", "anna", "sergei", "vasili" };
string[] firstNames = { "Иван", "Петр", "Алексей" };
string[] lastNames = { "Иванов", "Петров", "Сидоров" };
string[] middleNames = { "Иванович", "Петрович", "Алексеевич" };
Random random = new Random();
for (int i = 0; i < 10; i++)
{
string areaCode = random.Next(100, 1000).ToString();
string firstPart = random.Next(100, 1000).ToString();
string secondPart = random.Next(1000, 10000).ToString();
string randomPrefix = prefixes[random.Next(prefixes.Length)];
string randomDomain = domains[random.Next(domains.Length)];
string firstName = firstNames[random.Next(firstNames.Length)];
string lastName = lastNames[random.Next(lastNames.Length)];
string middleName = middleNames[random.Next(middleNames.Length)];
_guideLogic.Create(new GuideBindingModel
{
GuideFIO = $"{lastName} {firstName} {middleName}",
Email = $"{randomPrefix}{i}@{randomDomain}",
PhoneNumber = $"+7 ({areaCode}) {firstPart}-{secondPart}"
});
}
}
if (_placeLogic.ReadList(null) == null || _placeLogic.ReadList(null)?.ToList().Count < 1)
{
string[] streets = { "Цветной бульвар", "Ленинградский проспект", "Тверская улица", "Пресненская набережная", "Садовая улица" };
string[] cities = { "Москва", "Санкт-Петербург", "Новосибирск", "Екатеринбург" };
Random random = new Random();
for (int i = 0; i < 10; i++)
{
string street = streets[random.Next(streets.Length)];
string city = cities[random.Next(cities.Length)];
int houseNumber = random.Next(1, 100);
_placeLogic.Create(new PlaceBindingModel
{
PlaceName = $"Место {i}",
PlaceAddress = $"{city}, {street}, {houseNumber}"
});
}
}
if (_tripLogic.ReadList(null) == null || _tripLogic.ReadList(null)?.ToList().Count < 1)
{
var guides = _guideLogic.ReadList(null);
var places = _placeLogic.ReadList(null);
Random random = new Random();
for (int i = 0; i < 10; i++)
{
int year = random.Next(2024, 2026);
int month = random.Next(1, 13);
int day = random.Next(1, 29);
int guideId = guides[random.Next(0, guides.Count)].Id;
Dictionary<int, IPlaceModel> tripPlaces = new Dictionary<int, IPlaceModel>();
foreach(var place in places)
{
if (random.Next(0, 2) == 1)
{
tripPlaces.Add(place.Id, place);
}
}
_tripLogic.Create(new TripBindingModel
{
TripName = $"Поездка {i}",
TripDate = new DateTime(year, month, day),
GuideId = guideId,
TripPlaces = tripPlaces
});
}
}
}
}
}

View File

@ -17,6 +17,12 @@
<div class="col-4">Цена:</div>
<div class="col-8"><input type="text" id="price" name="price" /></div>
</div>
<div class="row">
<div class="col-4">Место для посещения:</div>
<div class="col-8">
<select id="place" name="place" class="form-control" asp-items="@(new SelectList(@ViewBag.Places,"Id", "PlaceName"))"></select>
</div>
</div>
<div class="container">
<div>Туры</div>
<div class="table-responsive-lg">

View File

@ -34,6 +34,9 @@
<th>
Описание
</th>
<th>
Место для посещения
</th>
<th>
Цена
</th>
@ -54,6 +57,9 @@
<td>
@Html.DisplayFor(modelItem => excursion.ExcursionDescription)
</td>
<td>
@Html.DisplayFor(modelItem => excursion.PlaceName)
</td>
<td>
@Html.DisplayFor(modelItem => excursion.Price)
</td>

View File

@ -20,6 +20,18 @@
<div class="col-4">Цена:</div>
<div class="col-8"><input type="text" id="price" name="price" value="@Model.Price" /></div>
</div>
<div class="row">
<div class="col-4">Место для посещения:</div>
<div class="col-8">
<select id="place" name="place" class="form-control">
@foreach (var place in ViewBag.Places)
{
var isSelected = Model.PlaceId.Equals(place.Id);
<option value="@place.Id" selected="@isSelected">@place.PlaceName</option>
}
</select>
</div>
</div>
<div class="container">
<div>Туры</div>
<div class="table-responsive-lg">

View File

@ -5,7 +5,7 @@
<div class="text-center">
<h1 class="display-4">Меню создания отчетов</h1>
<div class="list-group">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="ReportPlaceTour">
<a class="nav-link text-dark" asp-area="" asp-controller="Home" asp-action="ReportTourPlace">
Отчет мест для
посещения по выбранным турам
</a>

View File

@ -1,48 +0,0 @@
@using TravelAgencyContracts.ViewModels
@model List<ReportPlaceTourViewModel>
@{
ViewData["Title"] = "Places per tour report";
}
<div class="text-center">
<h1 class="display-4">Список мест для посещения по выбранным турам</h1>
</div>
<form asp-controller="Report" method="post">
<button type="submit" class="btn btn-primary">Сгенерировать отчет в Word</button>
</form>
<form asp-controller="Report" method="post">
<button type="submit" class="btn btn-primary">Сгенерировать отчет в Excel</button>
</form>
<div class="row">
<div class="col-4">Выберите тур:</div>
<div class="col-8">
<select id="tour" name="tour" class="form-control" asp-items="@(new SelectList(@ViewBag.Tours,"Id", "TourName"))"></select>
</div>
</div>
<table class="table">
<thead>
<tr>
<th>Тур</th>
<th>Место</th>
</tr>
</thead>
<tbody>
@foreach (var tour in Model)
{
<tr>
<td>@tour.TourName</td>
<td>
<ul>
@foreach (var place in tour.Places)
{
<li>@place</li>
}
</ul>
</td>
</tr>
}
</tbody>
</table>

View File

@ -13,53 +13,64 @@
</h1>
</div>
<form asp-controller="Report" method="post">
<button type="submit" class="btn btn-primary">Отправить отчет на почту</button>
</form>
<form method="post">
<div class="row mb-5">
<div class="row mb-5">
<div class="col-4">Начальная дата:</div>
<div class="col-8">
<input type="date" id="startDate" name="startDate" class="form-control">
<input type="date" id="startDate" name="dateFrom" @(@ViewBag.DateFrom != null ? $"value={@ViewBag.DateFrom.ToString("yyyy-MM-dd")}" : "") class="form-control">
</div>
</div>
<div class="row mb-5">
</div>
<div class="row mb-5">
<div class="col-4">Конечная дата:</div>
<div class="col-8">
<input type="date" id="endDate" name="endDate" class="form-control">
<input type="date" id="endDate" name="dateTo" @(@ViewBag.DateTo != null ? $"value={@ViewBag.DateTo.ToString("yyyy-MM-dd")}" : "") class="form-control">
</div>
</div>
</div>
<button type="submit" class="btn btn-primary">Сформировать отчет</button>
<button type="submit" class="btn btn-primary" formaction="@Url.Action("SentPdfToMail", "Home")">Отправить отчет на почту</button>
</form>
<table class="table">
<thead>
<tr>
<th>Тур</th>
<th>Стоимость тура</th>
<th>Дата тура</th>
<th>Экскурсионная группа</th>
<th>Количество участников</th>
<th>Гид</th>
</tr>
</thead>
<tbody>
@foreach (var tour in Model)
@if (Model == null || Model.Count <= 0)
{
<td class="text-center" colspan="6">Нет доступных данных</td>
}
else
{
foreach (var record in Model)
{
<td>@record.Tour.TourName</td>
<td>@record.Tour.Price</td>
<td>@record.Tour.TourDate</td>
<td></td>
<td></td>
<td></td>
var excursionGroups = new List<ExcursionGroupViewModel>(record.ExcursionGroups);
var guides = new List<GuideViewModel>(record.Guides);
for (int i = 0; i < excursionGroups.Count; i++)
{
<tr>
<td>@tour.TourName</td>
<td>
<ul>
@foreach (var excursionGroup in tour.ExcursionGroups)
{
<li>@excursionGroup</li>
}
</ul>
</td>
<td>
<ul>
@foreach (var guide in tour.Guides)
{
<li>@guide</li>
}
</ul>
</td>
<td></td>
<td></td>
<td></td>
<td>@excursionGroups[i].ExcursionGroupName</td>
<td>@excursionGroups[i].ParticipantsAmount</td>
<td>@guides[i].GuideFIO</td>
</tr>
}
}
}
</tbody>
</table>

View File

@ -0,0 +1,51 @@
@using TravelAgencyContracts.ViewModels
@model List<int>
@{
ViewData["Title"] = "Places per tour report";
}
<div class="text-center">
<h1 class="display-4">Список мест для посещения по выбранным турам</h1>
</div>
<form method="post">
<div>Выберите тур:</div>
<div class="table-responsive-lg">
<table id="tourstable" class="display">
<thead>
<tr>
<th>Название</th>
<th>Выбор</th>
</tr>
</thead>
<tbody>
@foreach (var tour in ViewBag.Tours)
{
var isChecked = false;
if (Model != null && Model.Count > 0) {
isChecked = Model.Any(x => x.Equals(tour.Id));
}
<tr>
<td>@tour.TourName</td>
<td>
<input type="checkbox" name="tours" @(isChecked ? "checked" : "") value="@tour.Id" />
</td>
</tr>
}
</tbody>
</table>
</div>
<div>
<label class="form-label">Выберите формат файла:</label>
<div class="form-check">
<input class="form-check-input" type="radio" name="type" value="docx" id="docx" checked>
<label class="form-check-label" for="docx">Word-файл</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="type" value="xlsx" id="xlsx">
<label class="form-check-label" for="xlsx">Excel-файл</label>
</div>
</div>
<button type="submit" class="btn btn-primary" formaction="@Url.Action("CreateReport", "Home")">Сохранить отчет</button>
</form>

View File

@ -5,5 +5,12 @@
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
"AllowedHosts": "*",
"SmtpClientHost": "smtp.gmail.com",
"SmtpClientPort": "587",
"PopHost": "pop.gmail.com",
"PopPort": "995",
"MailLogin": "carrepairshoplab7@gmail.com",
"MailPassword": "mmxi snox imiz ugqq"
}