From fb8a46fbd4e4a096e7fad9c89efecc47d30db657 Mon Sep 17 00:00:00 2001
From: "gitauto-ai[bot]" <161652217+gitauto-ai[bot]@users.noreply.github.com>
Date: Thu, 31 Oct 2024 00:09:09 +0000
Subject: [PATCH 01/11] Update Src/Models/Brand.cs
---
Src/Models/Brand.cs | 6 ++++++
1 file changed, 6 insertions(+)
create mode 100644 Src/Models/Brand.cs
diff --git a/Src/Models/Brand.cs b/Src/Models/Brand.cs
new file mode 100644
index 000000000..c64bd15be
--- /dev/null
+++ b/Src/Models/Brand.cs
@@ -0,0 +1,6 @@
+using System.Collections.Generic;
+@@ -25,0 +27,4 @@
+ ///
+ /// Gets or sets the subcollections associated with the brand.
+ ///
+ public ICollection Subcollections { get; set; }
From d2031c71fcbb73ff22589ac8e04f339d2bd30fd8 Mon Sep 17 00:00:00 2001
From: "gitauto-ai[bot]" <161652217+gitauto-ai[bot]@users.noreply.github.com>
Date: Thu, 31 Oct 2024 00:09:19 +0000
Subject: [PATCH 02/11] Update Src/Models/Subcollection.cs
---
Src/Models/Subcollection.cs | 12 ++++++++++++
1 file changed, 12 insertions(+)
create mode 100644 Src/Models/Subcollection.cs
diff --git a/Src/Models/Subcollection.cs b/Src/Models/Subcollection.cs
new file mode 100644
index 000000000..f5063bb2d
--- /dev/null
+++ b/Src/Models/Subcollection.cs
@@ -0,0 +1,12 @@
+using System;
+using System.Collections.Generic;
+
+namespace Models
+{
+ public class Subcollection
+ {
+ public int Id { get; set; }
+ public string Name { get; set; }
+ public ICollection Brands { get; set; }
+ }
+}
From 6ce6dc32029987c704cc868236c5b3b3f555e7df Mon Sep 17 00:00:00 2001
From: "gitauto-ai[bot]" <161652217+gitauto-ai[bot]@users.noreply.github.com>
Date: Thu, 31 Oct 2024 00:09:31 +0000
Subject: [PATCH 03/11] Update
Src/Migrations/AddBrandSubcollectionRelationship.cs
---
.../AddBrandSubcollectionRelationship.cs | 39 +++++++++++++++++++
1 file changed, 39 insertions(+)
create mode 100644 Src/Migrations/AddBrandSubcollectionRelationship.cs
diff --git a/Src/Migrations/AddBrandSubcollectionRelationship.cs b/Src/Migrations/AddBrandSubcollectionRelationship.cs
new file mode 100644
index 000000000..0cd00a63b
--- /dev/null
+++ b/Src/Migrations/AddBrandSubcollectionRelationship.cs
@@ -0,0 +1,39 @@
+using Microsoft.EntityFrameworkCore.Migrations;
+
+namespace Migrations
+{
+ public partial class AddBrandSubcollectionRelationship : Migration
+ {
+ protected override void Up(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.CreateTable(
+ name: "BrandSubcollection",
+ columns: table => new
+ {
+ BrandId = table.Column(nullable: false),
+ SubcollectionId = table.Column(nullable: false)
+ },
+ constraints: table =>
+ {
+ table.PrimaryKey("PK_BrandSubcollection", x => new { x.BrandId, x.SubcollectionId });
+ table.ForeignKey(
+ name: "FK_BrandSubcollection_Brands_BrandId",
+ column: x => x.BrandId,
+ principalTable: "Brands",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+ table.ForeignKey(
+ name: "FK_BrandSubcollection_Subcollections_SubcollectionId",
+ column: x => x.SubcollectionId,
+ principalTable: "Subcollections",
+ principalColumn: "Id",
+ onDelete: ReferentialAction.Cascade);
+ });
+ }
+
+ protected override void Down(MigrationBuilder migrationBuilder)
+ {
+ migrationBuilder.DropTable(name: "BrandSubcollection");
+ }
+ }
+}
From 8e75b515fc7c820282fa1f6eebb79e24c3111c36 Mon Sep 17 00:00:00 2001
From: "gitauto-ai[bot]" <161652217+gitauto-ai[bot]@users.noreply.github.com>
Date: Thu, 31 Oct 2024 00:09:47 +0000
Subject: [PATCH 04/11] Update Src/Services/BrandService.cs
---
Src/Services/BrandService.cs | 40 ++++++++++++++++++++++++++++++++++++
1 file changed, 40 insertions(+)
create mode 100644 Src/Services/BrandService.cs
diff --git a/Src/Services/BrandService.cs b/Src/Services/BrandService.cs
new file mode 100644
index 000000000..688f28ce6
--- /dev/null
+++ b/Src/Services/BrandService.cs
@@ -0,0 +1,40 @@
+using System;
+using System.Linq;
+using Models;
+
+namespace Services
+{
+ public class BrandService
+ {
+ private readonly DbContext _context;
+
+ public BrandService(DbContext context)
+ {
+ _context = context;
+ }
+
+ public void AssociateSubcollection(int brandId, int subcollectionId)
+ {
+ var brand = _context.Brands.Find(brandId);
+ var subcollection = _context.Subcollections.Find(subcollectionId);
+
+ if (brand == null || subcollection == null)
+ throw new ArgumentException("Invalid brand or subcollection ID.");
+
+ brand.Subcollections.Add(subcollection);
+ _context.SaveChanges();
+ }
+
+ public void DisassociateSubcollection(int brandId, int subcollectionId)
+ {
+ var brand = _context.Brands.Find(brandId);
+ var subcollection = _context.Subcollections.Find(subcollectionId);
+
+ if (brand == null || subcollection == null)
+ throw new ArgumentException("Invalid brand or subcollection ID.");
+
+ brand.Subcollections.Remove(subcollection);
+ _context.SaveChanges();
+ }
+ }
+}
From 76c5d50adc04c73244b4a27dc87939f13d5f41de Mon Sep 17 00:00:00 2001
From: "gitauto-ai[bot]" <161652217+gitauto-ai[bot]@users.noreply.github.com>
Date: Thu, 31 Oct 2024 00:10:07 +0000
Subject: [PATCH 05/11] Update Src/Controllers/BrandController.cs
---
Src/Controllers/BrandController.cs | 45 ++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)
create mode 100644 Src/Controllers/BrandController.cs
diff --git a/Src/Controllers/BrandController.cs b/Src/Controllers/BrandController.cs
new file mode 100644
index 000000000..ecaa6d8b1
--- /dev/null
+++ b/Src/Controllers/BrandController.cs
@@ -0,0 +1,45 @@
+using Microsoft.AspNetCore.Mvc;
+using Services;
+
+namespace Controllers
+{
+ [Route("api/[controller]")]
+ [ApiController]
+ public class BrandController : ControllerBase
+ {
+ private readonly BrandService _brandService;
+
+ public BrandController(BrandService brandService)
+ {
+ _brandService = brandService;
+ }
+
+ [HttpPost("{brandId}/subcollections/{subcollectionId}")]
+ public IActionResult AssociateSubcollection(int brandId, int subcollectionId)
+ {
+ try
+ {
+ _brandService.AssociateSubcollection(brandId, subcollectionId);
+ return Ok();
+ }
+ catch (ArgumentException ex)
+ {
+ return BadRequest(ex.Message);
+ }
+ }
+
+ [HttpDelete("{brandId}/subcollections/{subcollectionId}")]
+ public IActionResult DisassociateSubcollection(int brandId, int subcollectionId)
+ {
+ try
+ {
+ _brandService.DisassociateSubcollection(brandId, subcollectionId);
+ return Ok();
+ }
+ catch (ArgumentException ex)
+ {
+ return BadRequest(ex.Message);
+ }
+ }
+ }
+}
From 6a5683a194b5ea4b49c104b7b82484255da64ab6 Mon Sep 17 00:00:00 2001
From: "gitauto-ai[bot]" <161652217+gitauto-ai[bot]@users.noreply.github.com>
Date: Thu, 31 Oct 2024 00:10:43 +0000
Subject: [PATCH 06/11] Update Src/Services/BrandService.cs
---
Src/Services/BrandService.cs | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/Src/Services/BrandService.cs b/Src/Services/BrandService.cs
index 688f28ce6..9bb9aed74 100644
--- a/Src/Services/BrandService.cs
+++ b/Src/Services/BrandService.cs
@@ -36,5 +36,17 @@ public void DisassociateSubcollection(int brandId, int subcollectionId)
brand.Subcollections.Remove(subcollection);
_context.SaveChanges();
}
+
+ public bool BrandExists(int brandId)
+ {
+ return _context.Brands.Any(b => b.Id == brandId);
+ }
+
+ public bool SubcollectionExists(int subcollectionId)
+ {
+ return _context.Subcollections.Any(s => s.Id == subcollectionId);
+ }
+ }
+
}
}
From 6f70f4b291d72c9433a49fa6bf7d3b7d7fdea5d3 Mon Sep 17 00:00:00 2001
From: codefactor-io
Date: Thu, 31 Oct 2024 00:11:34 +0000
Subject: [PATCH 07/11] [CodeFactor] Apply fixes
---
Src/Services/BrandService.cs | 1 -
1 file changed, 1 deletion(-)
diff --git a/Src/Services/BrandService.cs b/Src/Services/BrandService.cs
index 9bb9aed74..dbcc72f9d 100644
--- a/Src/Services/BrandService.cs
+++ b/Src/Services/BrandService.cs
@@ -47,6 +47,5 @@ public bool SubcollectionExists(int subcollectionId)
return _context.Subcollections.Any(s => s.Id == subcollectionId);
}
}
-
}
}
From ded0235785754998d5bc8706a55a448dc2690c83 Mon Sep 17 00:00:00 2001
From: "gitauto-ai[bot]" <161652217+gitauto-ai[bot]@users.noreply.github.com>
Date: Thu, 31 Oct 2024 00:12:27 +0000
Subject: [PATCH 08/11] Update Src/Models/Brand.cs
---
Src/Models/Brand.cs | 1 -
1 file changed, 1 deletion(-)
diff --git a/Src/Models/Brand.cs b/Src/Models/Brand.cs
index c64bd15be..155536c42 100644
--- a/Src/Models/Brand.cs
+++ b/Src/Models/Brand.cs
@@ -1,5 +1,4 @@
using System.Collections.Generic;
-@@ -25,0 +27,4 @@
///
/// Gets or sets the subcollections associated with the brand.
///
From bf4caae6e0d042be40af8ac9c0e6ee85824106fc Mon Sep 17 00:00:00 2001
From: "gitauto-ai[bot]" <161652217+gitauto-ai[bot]@users.noreply.github.com>
Date: Thu, 31 Oct 2024 00:12:36 +0000
Subject: [PATCH 09/11] Update Src/Services/BrandService.cs
---
Src/Services/BrandService.cs | 1 -
1 file changed, 1 deletion(-)
diff --git a/Src/Services/BrandService.cs b/Src/Services/BrandService.cs
index dbcc72f9d..e5f514049 100644
--- a/Src/Services/BrandService.cs
+++ b/Src/Services/BrandService.cs
@@ -47,5 +47,4 @@ public bool SubcollectionExists(int subcollectionId)
return _context.Subcollections.Any(s => s.Id == subcollectionId);
}
}
- }
}
From 4bdc5552853e270402bff46139f6a1ae3f13064d Mon Sep 17 00:00:00 2001
From: "gitauto-ai[bot]" <161652217+gitauto-ai[bot]@users.noreply.github.com>
Date: Thu, 31 Oct 2024 00:12:42 +0000
Subject: [PATCH 10/11] Update
Src/Migrations/AddBrandSubcollectionRelationship.cs
---
Src/Migrations/AddBrandSubcollectionRelationship.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Src/Migrations/AddBrandSubcollectionRelationship.cs b/Src/Migrations/AddBrandSubcollectionRelationship.cs
index 0cd00a63b..192554209 100644
--- a/Src/Migrations/AddBrandSubcollectionRelationship.cs
+++ b/Src/Migrations/AddBrandSubcollectionRelationship.cs
@@ -11,7 +11,7 @@ protected override void Up(MigrationBuilder migrationBuilder)
columns: table => new
{
BrandId = table.Column(nullable: false),
- SubcollectionId = table.Column(nullable: false)
+ SubcollectionId = table.Column(nullable: false),
},
constraints: table =>
{
From 9f8bd40560efc72153736200cdbed66ac7943ca4 Mon Sep 17 00:00:00 2001
From: "gitauto-ai[bot]" <161652217+gitauto-ai[bot]@users.noreply.github.com>
Date: Fri, 1 Nov 2024 00:12:12 +0000
Subject: [PATCH 11/11] Update Src/Services/BrandService.cs
---
Src/Services/BrandService.cs | 1 +
1 file changed, 1 insertion(+)
diff --git a/Src/Services/BrandService.cs b/Src/Services/BrandService.cs
index e5f514049..70078c41f 100644
--- a/Src/Services/BrandService.cs
+++ b/Src/Services/BrandService.cs
@@ -1,6 +1,7 @@
using System;
using System.Linq;
using Models;
+using Microsoft.EntityFrameworkCore;
namespace Services
{