Fix Isactive issue

This commit is contained in:
2026-09-09 16:30:38 +05:30
parent f9e4bb3a97
commit eb0303fa3f
3 changed files with 5 additions and 5 deletions
@@ -2,7 +2,7 @@ namespace Distribution.Features.Supplier;
public record CreateSupplierRequest(string Name, string? ContactInfo); public record CreateSupplierRequest(string Name, string? ContactInfo);
public record UpdateSupplierRequest(string Name, string? ContactInfo); public record UpdateSupplierRequest(string Name, string? ContactInfo, bool IsActive);
public record SupplierResponse( public record SupplierResponse(
Guid Id, Guid Id,
@@ -9,7 +9,7 @@ public class SupplierRepository(AppDBContext context) : ISupplierRepository
await context.Suppliers.FindAsync(id); await context.Suppliers.FindAsync(id);
public async Task<List<Models.Supplier>> GetAllAsync() => public async Task<List<Models.Supplier>> GetAllAsync() =>
await context.Suppliers.Where(s => s.IsActive).ToListAsync(); await context.Suppliers.ToListAsync();
public async Task AddAsync(Models.Supplier entity) => public async Task AddAsync(Models.Supplier entity) =>
await context.Suppliers.AddAsync(entity); await context.Suppliers.AddAsync(entity);
@@ -19,8 +19,7 @@ public class SupplierService(
public async Task<SupplierResponse?> GetByIdAsync(Guid id) public async Task<SupplierResponse?> GetByIdAsync(Guid id)
{ {
var supplier = await repo.GetByIdAsync(id); var supplier = await repo.GetByIdAsync(id);
if (supplier is null || !supplier.IsActive) return null; return supplier is null ? null : Map(supplier);
return Map(supplier);
} }
public async Task<SupplierResponse> CreateAsync(CreateSupplierRequest request, CancellationToken ct = default) public async Task<SupplierResponse> CreateAsync(CreateSupplierRequest request, CancellationToken ct = default)
@@ -41,10 +40,11 @@ public class SupplierService(
public async Task<SupplierResponse?> UpdateAsync(Guid id, UpdateSupplierRequest request, CancellationToken ct = default) public async Task<SupplierResponse?> UpdateAsync(Guid id, UpdateSupplierRequest request, CancellationToken ct = default)
{ {
var supplier = await repo.GetByIdAsync(id); var supplier = await repo.GetByIdAsync(id);
if (supplier is null || !supplier.IsActive) return null; if (supplier is null) return null;
supplier.Name = request.Name; supplier.Name = request.Name;
supplier.ContactInfo = request.ContactInfo; supplier.ContactInfo = request.ContactInfo;
supplier.IsActive = request.IsActive;
await uow.BeginAsync(ct); await uow.BeginAsync(ct);
try { repo.Update(supplier); await uow.CommitAsync(ct); } try { repo.Update(supplier); await uow.CommitAsync(ct); }