[Add] MasterData Services.
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
using System.Data;
|
||||
using AMREZ.EOP.Abstractions.Applications.UseCases.MasterData.Brand;
|
||||
using AMREZ.EOP.Abstractions.Infrastructures.Common;
|
||||
using AMREZ.EOP.Abstractions.Infrastructures.Repositories;
|
||||
using AMREZ.EOP.Contracts.DTOs.MasterData.Brand;
|
||||
|
||||
namespace AMREZ.EOP.Application.UseCases.MasterData.Brand;
|
||||
|
||||
public sealed class UpdateBrandUseCase : IUpdateBrandUseCase
|
||||
{
|
||||
private readonly IBrandRepository _repo;
|
||||
private readonly IUnitOfWork _uow;
|
||||
|
||||
public UpdateBrandUseCase(IBrandRepository repo, IUnitOfWork uow) { _repo = repo; _uow = uow; }
|
||||
|
||||
public async Task<BrandResponse?> ExecuteAsync(Guid id, BrandUpdateRequest req, CancellationToken ct = default)
|
||||
{
|
||||
await _uow.BeginAsync(null, IsolationLevel.ReadCommitted, ct);
|
||||
try
|
||||
{
|
||||
var e = await _repo.GetAsync(id, ct);
|
||||
if (e is null) { await _uow.RollbackAsync(ct); return null; }
|
||||
|
||||
e.Name = req.Name.Trim();
|
||||
e.NameI18n = req.NameI18n;
|
||||
e.Meta = req.Meta;
|
||||
e.IsActive = req.IsActive;
|
||||
|
||||
await _repo.UpdateAsync(e, ct);
|
||||
await _uow.CommitAsync(ct);
|
||||
|
||||
return new BrandResponse(e.Id, e.Scope, e.Code, e.Name, e.NameI18n, e.OverridesGlobalId, e.IsActive, e.IsSystem, e.Meta);
|
||||
}
|
||||
catch
|
||||
{
|
||||
await _uow.RollbackAsync(ct);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user