Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
try {
var estateId = await this.GetEstateId();

var command = new ContractCommands.AddTransactionFeeForProductToContractCommand(
var command = new ContractCommands.AddTransactionFeeToProductCommand(
CorrelationIdHelper.New(),
estateId,
ContractId,
Expand Down Expand Up @@ -225,32 +225,45 @@

private async Task RemoveProduct(Guid productId)
{
if (contractModel == null || contractModel.Products == null) return;
//if (contractModel == null || contractModel.Products == null) return;

Check notice on line 228 in EstateManagementUI.BlazorServer/Components/Pages/Contracts/Edit.razor.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

EstateManagementUI.BlazorServer/Components/Pages/Contracts/Edit.razor.cs#L228

Remove this commented out code.

var product = contractModel.Products.FirstOrDefault(p => p.ContractProductId == productId);
if (product != null)
{
//var product = contractModel.Products.FirstOrDefault(p => p.ContractProductId == productId);
//if (product != null)
//{
// Note: Backend API for product removal not yet implemented
// For now, show a message to the user
errorMessage = "Product removal is not yet supported by the backend API. This feature will be available once the backend endpoint is implemented.";
}
//}

Check notice on line 236 in EstateManagementUI.BlazorServer/Components/Pages/Contracts/Edit.razor.cs

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

EstateManagementUI.BlazorServer/Components/Pages/Contracts/Edit.razor.cs#L236

Remove this commented out code.
}

private async Task RemoveFee(Guid productId, Guid feeId)
{
if (contractModel == null || contractModel.Products == null) return;
var estateId = await this.GetEstateId();

var command = new ContractCommands.RemoveTransactionFeeFromProductCommand(
CorrelationIdHelper.New(),
estateId,
ContractId,
productId, feeId
);

var product = contractModel.Products.FirstOrDefault(p => p.ContractProductId == productId);
if (product?.TransactionFees != null)
var result = await Mediator.Send(command);

if (result.IsSuccess)
{
var fee = product.TransactionFees.FirstOrDefault(f => f.TransactionFeeId == feeId);
if (fee != null)
{
// Note: Backend API for fee removal not yet implemented
// For now, show a message to the user
errorMessage = "Transaction fee removal is not yet supported by the backend API. This feature will be available once the backend endpoint is implemented.";
}
successMessage = "Transaction fee removed successfully";

// Small delay so user sees confirmation (adjust duration as needed)
await Task.Delay(2500);

await LoadContract();
}
else
{
feeErrorMessage = result.Message ?? "Failed to remove transaction fee";
}

StateHasChanged();
}

private void BackToView()
Expand Down
22 changes: 19 additions & 3 deletions EstateManagmentUI.BusinessLogic/Client/ContractMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ Task<Result> CreateContract(ContractCommands.CreateContractCommand request,
CancellationToken cancellationToken);
Task<Result> AddProductToContract(ContractCommands.AddProductToContractCommand request,
CancellationToken cancellationToken);
Task<Result> AddTransactionFeeForProductToContract(ContractCommands.AddTransactionFeeForProductToContractCommand request,
Task<Result> AddTransactionFeeToProduct(ContractCommands.AddTransactionFeeToProductCommand request,
CancellationToken cancellationToken);
Task<Result> RemoveTransactionFeeFromProduct(ContractCommands.RemoveTransactionFeeFromProductCommand request,
CancellationToken cancellationToken);

}

public partial class ApiClient : IApiClient {
Expand Down Expand Up @@ -127,8 +130,8 @@ public async Task<Result> AddProductToContract(ContractCommands.AddProductToCont
return Result.Success();
}

public async Task<Result> AddTransactionFeeForProductToContract(ContractCommands.AddTransactionFeeForProductToContractCommand request,
CancellationToken cancellationToken) {
public async Task<Result> AddTransactionFeeToProduct(ContractCommands.AddTransactionFeeToProductCommand request,
CancellationToken cancellationToken) {
var token = await this.GetToken(cancellationToken);
if (token.IsFailed)
return ResultHelpers.CreateFailure(token);
Expand All @@ -143,5 +146,18 @@ public async Task<Result> AddTransactionFeeForProductToContract(ContractCommands

return Result.Success();
}
public async Task<Result> RemoveTransactionFeeFromProduct(ContractCommands.RemoveTransactionFeeFromProductCommand request,
CancellationToken cancellationToken)
{
var token = await this.GetToken(cancellationToken);
if (token.IsFailed)
return ResultHelpers.CreateFailure(token);

var apiResult = await this.TransactionProcessorClient.DisableTransactionFeeForProduct(token.Data, request.EstateId, request.ContractId, request.ProductId, request.FeeId, cancellationToken);
if (apiResult.IsFailed)
return ResultHelpers.CreateFailure(apiResult);

return Result.Success();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ public class ContractRequestHandler : IRequestHandler<ContractQueries.GetContrac
IRequestHandler<ContractQueries.GetContractQuery, Result<ContractModel>>,
IRequestHandler<ContractCommands.CreateContractCommand, Result>,
IRequestHandler<ContractCommands.AddProductToContractCommand, Result>,
IRequestHandler<ContractCommands.AddTransactionFeeForProductToContractCommand, Result>,
IRequestHandler<ContractCommands.AddTransactionFeeToProductCommand, Result>,
IRequestHandler<ContractCommands.RemoveTransactionFeeFromProductCommand, Result>,
IRequestHandler<ContractQueries.GetRecentContractsQuery, Result<List<RecentContractModel>>>,
IRequestHandler<ContractQueries.GetContractsForDropDownQuery, Result<List<ContractDropDownModel>>>
{
Expand Down Expand Up @@ -206,9 +207,15 @@ public async Task<Result> Handle(ContractCommands.AddProductToContractCommand re
return await this.ApiClient.AddProductToContract(request, cancellationToken);
}

public async Task<Result> Handle(ContractCommands.AddTransactionFeeForProductToContractCommand request,
public async Task<Result> Handle(ContractCommands.AddTransactionFeeToProductCommand request,
CancellationToken cancellationToken) {
return await this.ApiClient.AddTransactionFeeForProductToContract(request, cancellationToken);
return await this.ApiClient.AddTransactionFeeToProduct(request, cancellationToken);
}

public async Task<Result> Handle(ContractCommands.RemoveTransactionFeeFromProductCommand request,
CancellationToken cancellationToken)
{
return await this.ApiClient.RemoveTransactionFeeFromProduct(request, cancellationToken);
}

public async Task<Result<List<RecentContractModel>>> Handle(ContractQueries.GetRecentContractsQuery request,
Expand Down
3 changes: 2 additions & 1 deletion EstateManagmentUI.BusinessLogic/Requests/Requests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ public record CreateOperatorCommand(CorrelationId CorrelationId, Guid EstateId,
public static class ContractCommands {
public record CreateContractCommand(CorrelationId CorrelationId, Guid EstateId, string Description, Guid OperatorId) : IRequest<Result>;
public record AddProductToContractCommand(CorrelationId CorrelationId, Guid EstateId, Guid ContractId, string ProductName, string DisplayText, decimal? Value) : IRequest<Result>;
public record AddTransactionFeeForProductToContractCommand(CorrelationId CorrelationId, Guid EstateId, Guid ContractId, Guid ProductId, string Description, decimal Value, String CalculationType, String FeeType) : IRequest<Result>;
public record AddTransactionFeeToProductCommand(CorrelationId CorrelationId, Guid EstateId, Guid ContractId, Guid ProductId, string Description, decimal Value, String CalculationType, String FeeType) : IRequest<Result>;
public record RemoveTransactionFeeFromProductCommand(CorrelationId CorrelationId, Guid EstateId, Guid ContractId, Guid ProductId, Guid FeeId) : IRequest<Result>;
}

public static class Commands
Expand Down
24 changes: 22 additions & 2 deletions EstateManagmentUI.BusinessLogic/Services/TestMediatorService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public Task<TResponse> Send<TResponse>(IRequest<TResponse> request, Cancellation
OperatorCommands.UpdateOperatorCommand cmd => Task.FromResult((TResponse)(object)this.ExecuteUpdateOperator(cmd)),
ContractCommands.CreateContractCommand cmd => Task.FromResult((TResponse)(object)this.ExecuteCreateContract(cmd)),
ContractCommands.AddProductToContractCommand cmd => Task.FromResult((TResponse)(object)this.ExecuteAddProductToContract(cmd)),
ContractCommands.AddTransactionFeeForProductToContractCommand cmd => Task.FromResult((TResponse)(object)this.ExecuteAddTransactionFee(cmd)),
ContractCommands.AddTransactionFeeToProductCommand cmd => Task.FromResult((TResponse)(object)this.ExecuteAddTransactionFee(cmd)),
MerchantCommands.AssignContractToMerchantCommand cmd => Task.FromResult((TResponse)(object)this.ExecuteAssignContractToMerchant(cmd)),
MerchantCommands.RemoveContractFromMerchantCommand cmd => Task.FromResult((TResponse)(object)this.ExecuteRemoveContractFromMerchant(cmd)),
MerchantCommands.AddOperatorToMerchantCommand cmd => Task.FromResult((TResponse)(object)this.ExecuteAddOperatorToMerchant(cmd)),
Expand Down Expand Up @@ -237,7 +237,7 @@ private Result ExecuteAddProductToContract(ContractCommands.AddProductToContract
return Result.Success();
}

private Result ExecuteAddTransactionFee(ContractCommands.AddTransactionFeeForProductToContractCommand cmd)
private Result ExecuteAddTransactionFee(ContractCommands.AddTransactionFeeToProductCommand cmd)
{
var contract = this._testDataStore.GetContract(cmd.EstateId, cmd.ContractId);
if (contract == null)
Expand All @@ -261,6 +261,26 @@ private Result ExecuteAddTransactionFee(ContractCommands.AddTransactionFeeForPro
return Result.Success();
}

private Result ExecuteAddTransactionFee(ContractCommands.RemoveTransactionFeeFromProductCommand cmd)
{
var contract = this._testDataStore.GetContract(cmd.EstateId, cmd.ContractId);
if (contract == null)
return Result.Failure($"Contract {cmd.ContractId} not found");

var product = contract.Products?.FirstOrDefault(p => p.ContractProductId == cmd.ProductId);
if (product == null)
return Result.Failure($"Product {cmd.ProductId} not found in contract");

if (product.TransactionFees == null)
product.TransactionFees = new List<ContractProductTransactionFeeModel>();

var fee = product.TransactionFees.Single(f => f.TransactionFeeId == cmd.FeeId);
product.TransactionFees.Remove(fee);

this._testDataStore.UpdateContract(cmd.EstateId, contract);
return Result.Success();
}

private Result ExecuteAssignContractToMerchant(MerchantCommands.AssignContractToMerchantCommand cmd)
{
var merchant = this._testDataStore.GetMerchant(cmd.EstateId, cmd.MerchantId);
Expand Down
Loading