From 9ee220393af3e82a49c52abb5addc8db9517e94c Mon Sep 17 00:00:00 2001 From: Aloento <11802769+Aloento@users.noreply.github.com> Date: Fri, 2 Feb 2024 17:52:27 +0100 Subject: [PATCH] The most significant changes include the addition of a new package reference `DocumentFormat.OpenXml` in the `SoarCraft.AwaiShop.csproj` file and the addition of a new namespace `SoarCraft.AwaiShop.AdminHub` in the `Export.cs` file. The new namespace includes several `using` directives and a new `AdminHub` class with a method for creating an Excel document. 1. The `SoarCraft.AwaiShop.csproj` file now includes a new package reference `DocumentFormat.OpenXml` with version `3.0.1`. This package is likely to be used for manipulating Open XML documents. 2. The `Export.cs` file now includes a new namespace `SoarCraft.AwaiShop.AdminHub`. This namespace includes several `using` directives for `DocumentFormat.OpenXml`, `DocumentFormat.OpenXml.Packaging`, `DocumentFormat.OpenXml.Spreadsheet`, and `Microsoft.AspNetCore.SignalR`. These directives are likely to be used for creating and manipulating Open XML documents and for using SignalR, a library for real-time web functionality. 3. A new `AdminHub` class has been added to the `Export.cs` file. This class includes a static `DateTime` field `lastExport` initialized to `DateTime.MinValue`. This field is likely to be used for tracking the last export time. 4. A new method `ExportProcessingOrder` has been added to the `AdminHub` class in the `Export.cs` file. This method creates a new Excel document with a single sheet named "ProcessingOrder" and a single header row. The method returns `1`, indicating successful execution. The changes in the `AdminHub` class in the `Post.cs` file seem to be redundant as they involve removing and adding back the same lines of code without any modification. --- SoarCraft.AwaiShop/AdminHub/Order/Export.cs | 45 ++++++++++++++++++++ SoarCraft.AwaiShop/AdminHub/Product/Post.cs | 12 +++--- SoarCraft.AwaiShop/SoarCraft.AwaiShop.csproj | 1 + 3 files changed, 52 insertions(+), 6 deletions(-) create mode 100644 SoarCraft.AwaiShop/AdminHub/Order/Export.cs diff --git a/SoarCraft.AwaiShop/AdminHub/Order/Export.cs b/SoarCraft.AwaiShop/AdminHub/Order/Export.cs new file mode 100644 index 0000000..f59f18b --- /dev/null +++ b/SoarCraft.AwaiShop/AdminHub/Order/Export.cs @@ -0,0 +1,45 @@ +namespace SoarCraft.AwaiShop.AdminHub; + +using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Spreadsheet; +using Microsoft.AspNetCore.SignalR; + +internal partial class AdminHub { + private static readonly DateTime lastExport = DateTime.MinValue; + + /** + * + * @author Aloento + * @since 1.2.5 + * @version 0.1.0 + * + */ + public async Task ExportProcessingOrder() { + if (DateTime.Now - lastExport < TimeSpan.FromMinutes(3)) + throw new HubException("The time interval between two exports shall not be less than 3 minutes."); + + using var stream = new MemoryStream(); + using var document = SpreadsheetDocument.Create(stream, SpreadsheetDocumentType.Workbook, true); + + var workbookPart = document.AddWorkbookPart(); + workbookPart.Workbook = new(); + + var worksheetPart = workbookPart.AddNewPart(); + var sheetData = new SheetData(); + worksheetPart.Worksheet = new(sheetData); + + var sheets = workbookPart.Workbook.AppendChild(new Sheets()); + var sheet = new Sheet { + Id = workbookPart.GetIdOfPart(worksheetPart), + SheetId = 1, + Name = "ProcessingOrder" + }; + sheets.Append(sheet); + + var headerRow = new Row(); + sheetData.AppendChild(headerRow); + + return 1; + } +} diff --git a/SoarCraft.AwaiShop/AdminHub/Product/Post.cs b/SoarCraft.AwaiShop/AdminHub/Product/Post.cs index 354e83e..a1e61f8 100644 --- a/SoarCraft.AwaiShop/AdminHub/Product/Post.cs +++ b/SoarCraft.AwaiShop/AdminHub/Product/Post.cs @@ -133,7 +133,7 @@ public async Task ProductPostVariant(uint prodId, string name) { var temp = await this.Db.Variants.AddAsync(new() { ProductId = prodId, - Name = name, + Name = name }); await this.Db.SaveChangesAsync(); @@ -184,11 +184,11 @@ public async Task ProductPostType(uint variantId, string name) { */ public async Task ProductPostCombo(uint prodId, Dictionary combo, ushort stock) { var variTypesDb = (await this.Db.Products - .Include(x => x.Variants) - .ThenInclude(x => x.Types) - .Where(x => x.ProductId == prodId) - .SelectMany(x => x.Variants) - .ToDictionaryAsync(k => k.Name, v => v.Types.ToImmutableArray())) + .Include(x => x.Variants) + .ThenInclude(x => x.Types) + .Where(x => x.ProductId == prodId) + .SelectMany(x => x.Variants) + .ToDictionaryAsync(k => k.Name, v => v.Types.ToImmutableArray())) .ToImmutableSortedDictionary(); var reqCombo = combo.ToImmutableSortedDictionary(); diff --git a/SoarCraft.AwaiShop/SoarCraft.AwaiShop.csproj b/SoarCraft.AwaiShop/SoarCraft.AwaiShop.csproj index 201379e..3bd8242 100644 --- a/SoarCraft.AwaiShop/SoarCraft.AwaiShop.csproj +++ b/SoarCraft.AwaiShop/SoarCraft.AwaiShop.csproj @@ -23,6 +23,7 @@ +