Skip to content
This repository was archived by the owner on Oct 14, 2024. It is now read-only.

Commit d031c06

Browse files
authored
[Front] v1.3.0 (#70)
1 parent 6401263 commit d031c06

File tree

21 files changed

+815
-663
lines changed

21 files changed

+815
-663
lines changed

TSystems.LoveOTC/AdminHub/Product/Delete.cs

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ namespace TSystems.LoveOTC.AdminHub;
22

33
using Microsoft.EntityFrameworkCore;
44
using Models;
5+
using Z.EntityFramework.Plus;
56

67
internal partial class AdminHub {
78
/**
@@ -104,7 +105,7 @@ public async Task<bool> ProductDeleteType(uint variantId, string reqType) {
104105
await this.deleteType(
105106
await this.Db.Types
106107
.Where(x => x.VariantId == variantId && x.Name == reqType)
107-
.Include(x => x.Combos)
108+
.IncludeOptimized(x => x.Combos)
108109
.SingleAsync()
109110
);
110111

@@ -179,4 +180,29 @@ public async Task<bool> ProductDeleteProduct(uint prodId) {
179180

180181
return await this.Db.SaveChangesAsync() > 0;
181182
}
183+
184+
/**
185+
* <remarks>
186+
* @author Aloento
187+
* @since 1.2.0
188+
* @version 0.1.0
189+
* </remarks>
190+
*/
191+
public async Task<bool> ProductDetachCategory(uint prodId) {
192+
var prod = await this.Db.Products
193+
.SingleAsync(x => x.ProductId == prodId);
194+
195+
if (prod.CategoryId is null)
196+
return false;
197+
198+
await this.Db.Categories
199+
.Where(x =>
200+
x.CategoryId == prod.CategoryId &&
201+
x.Products.Count == 0)
202+
.ExecuteDeleteAsync();
203+
204+
prod.CategoryId = null;
205+
206+
return await this.Db.SaveChangesAsync() > 0;
207+
}
182208
}

TSystems.LoveOTC/AdminHub/Product/Patch.cs

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ namespace TSystems.LoveOTC.AdminHub;
66
using Microsoft.AspNetCore.SignalR;
77
using Microsoft.EntityFrameworkCore;
88
using Models;
9+
using Z.EntityFramework.Plus;
910

1011
internal partial class AdminHub {
1112
/**
@@ -35,7 +36,7 @@ public async Task<bool> ProductPatchName(uint prodId, string name) {
3536
* <remarks>
3637
* @author Aloento
3738
* @since 0.1.0
38-
* @version 1.0.0
39+
* @version 1.1.1
3940
* </remarks>
4041
*/
4142
public async Task<bool> ProductPatchCategory(uint prodId, string name) {
@@ -46,23 +47,35 @@ public async Task<bool> ProductPatchCategory(uint prodId, string name) {
4647
if (!valid.IsValid(name))
4748
throw new HubException(valid.FormatErrorMessage("Name"));
4849

49-
var newCate = await this.Db.Categories
50-
.Where(x => x.Name == name)
51-
.SingleOrDefaultAsync()
52-
?? (await this.Db.Categories.AddAsync(new() {
53-
Name = name
54-
})).Entity;
50+
Product prod;
51+
Category? newCate;
5552

56-
var prod = await this.Db.Products
57-
.Include(x => x.Category)
58-
.SingleAsync(x => x.ProductId == prodId);
53+
{
54+
var defProd = this.Db.Products
55+
.DeferredSingle(x => x.ProductId == prodId)
56+
.FutureValue();
5957

60-
var inUse = await this.Db.Products
61-
.Where(x => x.CategoryId == prod.CategoryId && x.ProductId != prod.ProductId)
62-
.AnyAsync();
58+
var defNewCate = this.Db.Categories
59+
.DeferredSingleOrDefault(x => x.Name == name)
60+
.FutureValue();
6361

64-
if (!inUse)
65-
this.Db.Categories.Remove(prod.Category!);
62+
prod = await defProd.ValueAsync();
63+
newCate = await defNewCate.ValueAsync();
64+
}
65+
66+
if (prod.CategoryId is not null)
67+
await this.Db.Categories
68+
.Where(x =>
69+
x.CategoryId == prod.CategoryId &&
70+
x.Products.Count == 0)
71+
.ExecuteDeleteAsync();
72+
73+
if (newCate is null)
74+
newCate = (await this.Db.Categories.AddAsync(new() {
75+
Name = name
76+
})).Entity;
77+
else if (prod.CategoryId == newCate.CategoryId)
78+
return true;
6679

6780
prod.Category = newCate;
6881

@@ -118,7 +131,6 @@ public async Task<bool> ProductPatchCaption(uint photoId, string caption) {
118131
* <summary>
119132
* Include Combos
120133
* </summary>
121-
*
122134
* <remarks>
123135
* @author Aloento
124136
* @since 0.5.0
@@ -236,7 +248,7 @@ public async Task<bool> ProductPatchType(uint variantId, string oldName, string
236248

237249
if (any) {
238250
var oldType = await type
239-
.Include(x => x.Combos)
251+
.IncludeOptimized(x => x.Combos)
240252
.SingleAsync();
241253

242254
oldType.IsArchived = true;
@@ -292,7 +304,7 @@ public async Task<bool> ProductPatchCombo(uint comboId, Dictionary<string, strin
292304
.Where(x => x.ProductId == queryCombo
293305
.Select(c => c.ProductId)
294306
.Single())
295-
.Include(x => x.Types)
307+
.IncludeOptimized(x => x.Types)
296308
.Select(x => new {
297309
x.Name,
298310
x.Types

TSystems.LoveOTC/Program.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using TSystems.LoveOTC;
66
using TSystems.LoveOTC.AdminHub;
77
using TSystems.LoveOTC.Hub;
8+
using Z.EntityFramework.Extensions;
89

910
var builder = WebApplication.CreateBuilder(args);
1011

@@ -27,12 +28,13 @@
2728
});
2829

2930
builder.Services.AddDbContext<ShopContext>(x => {
31+
EntityFrameworkManager.IsCommunity = true;
32+
3033
if (Shared.Dev) {
3134
x.EnableSensitiveDataLogging();
3235
x.EnableDetailedErrors();
3336
}
3437

35-
x.UseLazyLoadingProxies();
3638
x.UseNpgsql(builder.Configuration.GetConnectionString("DefaultConnection"));
3739
});
3840

TSystems.LoveOTC/TSystems.LoveOTC.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
<PackageReference Include="Microsoft.Extensions.Hosting.Systemd" Version="8.0.0" />
4343
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.0" />
4444
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.2" />
45+
<PackageReference Include="Z.EntityFramework.Plus.EFCore" Version="8.101.2.1" />
4546
</ItemGroup>
4647

4748
<ItemGroup>

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
"update": "npx npm-check-updates -u"
1616
},
1717
"dependencies": {
18-
"@fluentui/react-components": "^9.44.4",
19-
"@fluentui/react-hooks": "^8.6.35",
18+
"@fluentui/react-components": "^9.46.0",
19+
"@fluentui/react-hooks": "^8.6.36",
2020
"@fluentui/react-icons": "^2.0.225",
2121
"@griffel/react": "^1.5.20",
2222
"@lexical/clipboard": "0.10.0",
@@ -55,6 +55,6 @@
5555
"@types/react-dom": "^18.2.18",
5656
"@vitejs/plugin-react-swc": "^3.5.0",
5757
"typescript": "^5.3.3",
58-
"vite": "^5.0.11"
58+
"vite": "^5.0.12"
5959
}
6060
}

0 commit comments

Comments
 (0)