Skip to content
This repository has been archived by the owner on Mar 24, 2024. It is now read-only.

Commit

Permalink
The most significant changes include the addition of a new package re…
Browse files Browse the repository at this point in the history
…ference `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.
  • Loading branch information
Aloento committed Feb 2, 2024
1 parent c480e11 commit 9ee2203
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 6 deletions.
45 changes: 45 additions & 0 deletions SoarCraft.AwaiShop/AdminHub/Order/Export.cs
Original file line number Diff line number Diff line change
@@ -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;

/**
* <remarks>
* @author Aloento
* @since 1.2.5
* @version 0.1.0
* </remarks>
*/
public async Task<dynamic> 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<WorksheetPart>();
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;
}
}
12 changes: 6 additions & 6 deletions SoarCraft.AwaiShop/AdminHub/Product/Post.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public async Task<uint> ProductPostVariant(uint prodId, string name) {

var temp = await this.Db.Variants.AddAsync(new() {
ProductId = prodId,
Name = name,
Name = name
});

await this.Db.SaveChangesAsync();
Expand Down Expand Up @@ -184,11 +184,11 @@ public async Task<uint> ProductPostType(uint variantId, string name) {
*/
public async Task<uint> ProductPostCombo(uint prodId, Dictionary<string, string> 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();
Expand Down
1 change: 1 addition & 0 deletions SoarCraft.AwaiShop/SoarCraft.AwaiShop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="DocumentFormat.OpenXml" Version="3.0.1" />
<PackageReference Include="JetBrains.Annotations" Version="2023.3.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="8.0.1" />
Expand Down

0 comments on commit 9ee2203

Please sign in to comment.