Fixes #21
@@ -2,7 +2,7 @@ namespace Distribution.Features.Supplier;
|
||||
|
||||
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(
|
||||
Guid Id,
|
||||
|
||||
@@ -9,7 +9,7 @@ public class SupplierRepository(AppDBContext context) : ISupplierRepository
|
||||
await context.Suppliers.FindAsync(id);
|
||||
|
||||
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) =>
|
||||
await context.Suppliers.AddAsync(entity);
|
||||
|
||||
@@ -19,8 +19,7 @@ public class SupplierService(
|
||||
public async Task<SupplierResponse?> GetByIdAsync(Guid id)
|
||||
{
|
||||
var supplier = await repo.GetByIdAsync(id);
|
||||
if (supplier is null || !supplier.IsActive) return null;
|
||||
return Map(supplier);
|
||||
return supplier is null ? null : Map(supplier);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
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.ContactInfo = request.ContactInfo;
|
||||
supplier.IsActive = request.IsActive;
|
||||
|
||||
await uow.BeginAsync(ct);
|
||||
try { repo.Update(supplier); await uow.CommitAsync(ct); }
|
||||
|
||||
Reference in New Issue
Block a user