Ejemplo n.º 1
0
        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);
                    }
                }
            }
        }
Ejemplo n.º 2
0
 public PhysicalContractsController(IMediator mediator, IPhysicalContractQueries physicalContractQueries)
 {
     _mediator = mediator;
     _physicalContractQueries = physicalContractQueries;
 }