internal static async Task ValidateSplitContract(CreateSplitCommand command, IPhysicalContractQueries physicalContractQueries, IUserService userService) { // splited quantities should be less than or equal to parent contract quantity decimal totalSplitedQuantity = 0; foreach (var child in command.ChildSections) { totalSplitedQuantity = totalSplitedQuantity + child.Quantity; } if (command.Quantity < totalSplitedQuantity) { throw new AtlasBusinessException($"The total splited quantity {totalSplitedQuantity} should be less than or equal to parent contrat quantity {command.Quantity}."); } // trader foreach (var child in command.ChildSections) { if (child.ContractId > 0) { var physicalContract = await physicalContractQueries.GetPhysicalContractByIdAsync(command.CompanyId, child.ContractId, null); var trader = await userService.GetUserByIdAsync(physicalContract.TraderId.Value); if (trader == null) { throw new NotFoundException("User", physicalContract.TraderId); } } } }
public PhysicalContractsController(IMediator mediator, IPhysicalContractQueries physicalContractQueries) { _mediator = mediator; _physicalContractQueries = physicalContractQueries; }