Files
ERP_Distribution/Distribution/Features/ExpenseVendor/ExpenseVendorService.cs
T
Kalana B. Thilakarathna c775146b64
CI/CD - ERP Distribution / Build & Deploy Frontend (pull_request) Failing after 13m39s
CI/CD - ERP Distribution / Build & Deploy Backend (pull_request) Failing after 15m1s
10.
Implementation
A partner, not just software
HexDive Technologies' local team handles setup, data migration, training and ongoing support — in Sinhala, Tamil and English. [confirm]

1
Discovery
Map your network, products and processes.

2
Configuration
Set up depots, pricing, schemes, routes and users.

3
Migration & training
Move your data and train every team.

4
Go-live & support
Dedicated account manager and local support desk.
2026-10-22 17:47:49 +05:30

60 lines
2.4 KiB
C#

using Distribution.Infra.UoW;
namespace Distribution.Features.ExpenseVendor;
public record PagedExpenseVendorsResponse(List<ExpenseVendorResponse> Items, int Page, int PageSize, int Total);
public class ExpenseVendorService(IExpenseVendorRepository repo, IUnitOfWork uow)
{
private static ExpenseVendorResponse Map(Models.ExpenseVendor v) =>
new(v.Id, v.Name, v.ContactInfo, v.IsActive);
public async Task<PagedExpenseVendorsResponse> ListAsync(string? search, int page, int pageSize)
{
if (page < 1) page = 1;
if (pageSize < 1 || pageSize > 200) pageSize = 50;
search = string.IsNullOrWhiteSpace(search) ? null : search.Trim();
var items = await repo.ListAsync(search, page, pageSize);
var total = await repo.CountAsync(search);
return new PagedExpenseVendorsResponse(items.Select(Map).ToList(), page, pageSize, total);
}
public async Task<ExpenseVendorResponse> CreateAsync(CreateExpenseVendorRequest request, CancellationToken ct = default)
{
var name = (request.Name ?? "").Trim();
if (string.IsNullOrEmpty(name)) throw new InvalidOperationException("Name is required");
if (await repo.NameExistsAsync(name, null))
throw new InvalidOperationException("A vendor with this name already exists");
var entity = new Models.ExpenseVendor { Name = name, ContactInfo = request.ContactInfo };
await uow.BeginAsync(ct);
try { await repo.AddAsync(entity); await uow.CommitAsync(ct); }
catch { await uow.RollbackAsync(ct); throw; }
return Map(entity);
}
public async Task<ExpenseVendorResponse?> UpdateAsync(Guid id, UpdateExpenseVendorRequest request, CancellationToken ct = default)
{
var entity = await repo.GetByIdAsync(id);
if (entity is null) return null;
var name = (request.Name ?? "").Trim();
if (string.IsNullOrEmpty(name)) throw new InvalidOperationException("Name is required");
if (await repo.NameExistsAsync(name, id))
throw new InvalidOperationException("A vendor with this name already exists");
entity.Name = name;
entity.ContactInfo = request.ContactInfo;
entity.IsActive = request.IsActive;
await uow.BeginAsync(ct);
try { repo.Update(entity); await uow.CommitAsync(ct); }
catch { await uow.RollbackAsync(ct); throw; }
return Map(entity);
}
}