From 68aea8105d54c7116a6c881181c049b95125a198 Mon Sep 17 00:00:00 2001 From: DeepnaPooja Date: Tue, 8 Sep 2026 11:44:16 +0530 Subject: [PATCH] UpdateBrandRequest to include IsActive flag and update BrandService to handle inactive brands correctly --- Distribution/Features/Brand/BrandDTOs.cs | 2 +- Distribution/Features/Brand/BrandService.cs | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/Distribution/Features/Brand/BrandDTOs.cs b/Distribution/Features/Brand/BrandDTOs.cs index bcdec56..8508217 100644 --- a/Distribution/Features/Brand/BrandDTOs.cs +++ b/Distribution/Features/Brand/BrandDTOs.cs @@ -1,5 +1,5 @@ namespace Distribution.Features.Brand; public record CreateBrandRequest(string Name); -public record UpdateBrandRequest(string Name); +public record UpdateBrandRequest(string Name, bool IsActive = true); public record BrandResponse(Guid Id, string Name, bool IsActive, DateTime CreatedAt); diff --git a/Distribution/Features/Brand/BrandService.cs b/Distribution/Features/Brand/BrandService.cs index d115f9f..7dbc5cf 100644 --- a/Distribution/Features/Brand/BrandService.cs +++ b/Distribution/Features/Brand/BrandService.cs @@ -5,15 +5,16 @@ namespace Distribution.Features.Brand; public class BrandService(IBrandRepository repo, IUnitOfWork uow) { public async Task> GetAllAsync() => + // Deleted brands stay IsActive=false but remain visible showing Inactive — delete + // never removes the row, only marks it (same rule as Items/Stores/Categories). (await repo.GetAllAsync()) - .Where(b => b.IsActive) .Select(b => new BrandResponse(b.Id, b.Name, b.IsActive, b.CreatedAt)) .ToList(); public async Task GetByIdAsync(Guid id) { var brand = await repo.GetByIdAsync(id); - if (brand is null || !brand.IsActive) return null; + if (brand is null) return null; return new BrandResponse(brand.Id, brand.Name, brand.IsActive, brand.CreatedAt); } @@ -29,9 +30,10 @@ public class BrandService(IBrandRepository repo, IUnitOfWork uow) public async Task UpdateAsync(Guid id, UpdateBrandRequest request, CancellationToken ct = default) { var brand = await repo.GetByIdAsync(id); - if (brand is null || !brand.IsActive) return null; + if (brand is null) return null; if (brand.ExternalErpId.HasValue) return null; brand.Name = request.Name; + brand.IsActive = request.IsActive; await uow.BeginAsync(ct); try { repo.Update(brand); await uow.CommitAsync(ct); } catch { await uow.RollbackAsync(ct); throw; } @@ -40,10 +42,11 @@ public class BrandService(IBrandRepository repo, IUnitOfWork uow) public async Task DeleteAsync(Guid id, CancellationToken ct = default) { + // Soft-delete only — never blocked by items still referencing this brand, same rule + // as Categories. var brand = await repo.GetByIdAsync(id); if (brand is null || !brand.IsActive) return false; if (brand.ExternalErpId.HasValue) return false; - if (await repo.HasActiveItemsAsync(id)) return false; await uow.BeginAsync(ct); try { repo.Remove(brand); await uow.CommitAsync(ct); } catch { await uow.RollbackAsync(ct); throw; }