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

[Back] ProductDeletePhoto | ProductPostMovePhoto | Remove Cover - [Front] DelegateDataGrid | GuidImage | AdminProductPhotoAction | AdminProductPhotoEditCaption | AdminProductPhotoEditDelete | AdminProductPhotoEditReplace | MakeCoverCol | ProductCarousel | usePhoto | useMovePhoto | useGet #112

Merged
merged 6 commits into from
Mar 2, 2024
18 changes: 14 additions & 4 deletions SoarCraft.AwaiShop/AdminHub/Product/Delete.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,25 @@ internal partial class AdminHub {
* <remarks>
* @author Aloento
* @since 0.1.0
* @version 0.2.0
* @version 0.3.0
* </remarks>
*/
public async Task<bool> ProductDeletePhoto(uint photoId) {
var res = await this.Db.Photos
.Where(x => x.PhotoId == photoId)
var where = this.Db.Photos
.Where(x => x.PhotoId == photoId);

var objId = await where
.Select(x => x.ObjectId)
.SingleAsync();

await this.Db.Objects
.Where(x => x.Id == objId)
.ExecuteDeleteAsync();

return res > 0;
await where
.ExecuteDeleteAsync();

return true;
}

/**
Expand Down
10 changes: 7 additions & 3 deletions SoarCraft.AwaiShop/AdminHub/Product/Post.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public async Task<uint> ProductPostCreate(string name) {
* <remarks>
* @author Aloento
* @since 0.5.0
* @version 1.0.0
* @version 1.1.0
* </remarks>
*/
public async Task<bool> ProductPostMovePhoto(uint photoId, bool up) {
Expand All @@ -57,14 +57,18 @@ public async Task<bool> ProductPostMovePhoto(uint photoId, bool up) {
if (current == 1)
throw new HubException("Photo already at top");

var prev = photos[index - 1].Order;

photos[index - 1].Order = current;
photos[index].Order = (byte)(current - 1);
photos[index].Order = prev;
} else {
if (current == photos.Last().Order)
throw new HubException("Photo already at bottom");

var next = photos[index + 1].Order;

photos[index + 1].Order = current;
photos[index].Order = (byte)(current + 1);
photos[index].Order = next;
}

await this.Db.SaveChangesAsync();
Expand Down
2 changes: 0 additions & 2 deletions SoarCraft.AwaiShop/Helpers/DataSeeder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public static async Task SeedData(IApplicationBuilder host) {
Category = cate1,
Photos = [
new() {
Cover = true,
Caption = "Demo Caption",
Order = 1,
Object = new() { Data = p1 }
Expand All @@ -64,7 +63,6 @@ public static async Task SeedData(IApplicationBuilder host) {
Category = cate2,
Photos = [
new() {
Cover = true,
Caption = "Demo Caption",
Order = 1,
Object = new() { Data = p3 }
Expand Down
4 changes: 2 additions & 2 deletions SoarCraft.AwaiShop/Hub/Product/Get.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ public Task<uint[]> ProductGetComboList(uint prodId) =>
* <remarks>
* @author Aloento
* @since 0.5.0
* @version 0.2.0
* @version 0.2.1
* </remarks>
*/
public Task<uint[]> ProductGetPhotoList(uint prodId) =>
this.Db.Photos
.Where(x => x.ProductId == prodId)
.OrderBy(x => x.Order)
.Select(x => x.PhotoId)
.ToArrayAsync();

}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ protected override void Up(MigrationBuilder migrationBuilder)
columns: table => new
{
PhotoId = table.Column<long>(type: "bigint", nullable: false),
Cover = table.Column<bool>(type: "boolean", nullable: true),
Caption = table.Column<string>(type: "character varying(100)", maxLength: 100, nullable: true),
Order = table.Column<byte>(type: "smallint", nullable: false),
ObjectId = table.Column<Guid>(type: "uuid", nullable: false),
Expand Down
8 changes: 1 addition & 7 deletions SoarCraft.AwaiShop/Migrations/ShopContextModelSnapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "8.0.0")
.HasAnnotation("Proxies:ChangeTracking", false)
.HasAnnotation("Proxies:CheckEquality", false)
.HasAnnotation("Proxies:LazyLoading", true)
.HasAnnotation("ProductVersion", "8.0.2")
.HasAnnotation("Relational:MaxIdentifierLength", 63);

NpgsqlModelBuilderExtensions.UseHiLo(modelBuilder, "EntityFrameworkHiLoSequence");
Expand Down Expand Up @@ -215,9 +212,6 @@ protected override void BuildModel(ModelBuilder modelBuilder)
.HasMaxLength(100)
.HasColumnType("character varying(100)");

b.Property<bool?>("Cover")
.HasColumnType("boolean");

b.Property<Guid>("ObjectId")
.HasColumnType("uuid");

Expand Down
4 changes: 1 addition & 3 deletions SoarCraft.AwaiShop/Models/Photo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ namespace SoarCraft.AwaiShop.Models;
* <remarks>
* @author Aloento
* @since 0.1.0
* @version 0.1.0
* @version 0.2.0
* </remarks>
*/
public class Photo : Concurrency {
public uint PhotoId { get; set; }

public bool? Cover { get; set; }

[StringLength(100)]
public string? Caption { get; set; }

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@azure/msal-browser": "^3.10.0",
"@azure/msal-common": "^14.7.1",
"@azure/msal-react": "^2.0.12",
"@fluentui/react-components": "^9.46.6",
"@fluentui/react-components": "^9.46.7",
"@fluentui/react-hooks": "^8.6.36",
"@fluentui/react-icons": "^2.0.230",
"@griffel/react": "^1.5.20",
Expand Down Expand Up @@ -53,7 +53,7 @@
},
"devDependencies": {
"@types/lodash-es": "^4.17.12",
"@types/react": "^18.2.60",
"@types/react": "^18.2.61",
"@types/react-dom": "^18.2.19",
"@vitejs/plugin-react-swc": "^3.6.0",
"typescript": "^5.3.3",
Expand Down
Loading
Loading