Skip to content
Merged
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
58 changes: 58 additions & 0 deletions EstateManagement/Controllers/MerchantController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
using MakeMerchantDepositRequestDTO = DataTransferObjects.Requests.MakeMerchantDepositRequest;
using EstateManagement.Common;
using System.Security.Claims;
using BusinessLogic.Requests;
using Common.Examples;
using DataTransferObjects;
using Microsoft.AspNetCore.Authorization;
Expand Down Expand Up @@ -165,6 +166,63 @@ public async Task<IActionResult> CreateMerchant([FromRoute] Guid estateId,
});
}

/// <summary>
/// Creates the merchant.
/// </summary>
/// <param name="estateId">The estate identifier.</param>
/// <param name="createMerchantRequest">The create merchant request.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns></returns>
[HttpPatch]
[Route("")]
//[SwaggerResponse(200, "Created", typeof(CreateMerchantResponse))]
//[SwaggerResponseExample(201, typeof(CreateMerchantResponseExample))]
public async Task<IActionResult> SetSettlementSchedule([FromRoute] Guid estateId,
[FromRoute] Guid merchantId,
[FromBody] SetSettlementScheduleRequest setSettlementScheduleRequest,
CancellationToken cancellationToken)
{
// Get the Estate Id claim from the user
Claim estateIdClaim = ClaimsHelper.GetUserClaim(this.User, "EstateId", estateId.ToString());

String estateRoleName = Environment.GetEnvironmentVariable("EstateRoleName");
if (ClaimsHelper.IsUserRolesValid(this.User, new[] { String.IsNullOrEmpty(estateRoleName) ? "Estate" : estateRoleName }) == false)
{
return this.Forbid();
}

if (ClaimsHelper.ValidateRouteParameter(estateId, estateIdClaim) == false)
{
return this.Forbid();
}

// Convert the schedule
Models.SettlementSchedule settlementScheduleModel = Models.SettlementSchedule.NotSet;
switch (setSettlementScheduleRequest.SettlementSchedule)
{
case SettlementSchedule.Immediate:
settlementScheduleModel = Models.SettlementSchedule.Immediate;
break;
case SettlementSchedule.Weekly:
settlementScheduleModel = Models.SettlementSchedule.Weekly;
break;
case SettlementSchedule.Monthly:
settlementScheduleModel = Models.SettlementSchedule.Monthly;
break;
default:
settlementScheduleModel = Models.SettlementSchedule.Immediate;
break;
}

SetMerchantSettlementScheduleRequest command = SetMerchantSettlementScheduleRequest.Create(estateId, merchantId, settlementScheduleModel);

// Route the command
await this.Mediator.Send(command, cancellationToken);

// return the result
return this.Ok();
}

/// <summary>
/// Gets the merchants.
/// </summary>
Expand Down