public async Task <IActionResult> SettleFxDeal(string company, [Range(1, long.MaxValue)] long fxDealId) { var fxDealInfo = await _fxDealQueries.GetFxDealByIdAsync(fxDealId, company); if (fxDealInfo != null && fxDealInfo.MaturityDate <= DateTime.UtcNow && fxDealInfo.FxDealStatusId != (int)FxDealStatus.Settled) { List <FxDealDto> fxDeals = new List <FxDealDto>(); fxDeals.Add(fxDealInfo); var command = new FxDealDocumentCreationCommand { FxDealIds = fxDeals, IsReversal = false, Company = company }; var commandResult = await _mediator.Send(command); return(Ok(commandResult)); } else if (fxDealInfo == null) { throw new Exception("No such fxdeal to settle."); } else { return(Ok()); } }
public async Task <IActionResult> ReverseFxDeal(string company, [Range(1, long.MaxValue)] long fxDealId) { var fxDealInfo = await _fxDealQueries.GetFxDealByIdAsync(fxDealId, company); if (fxDealInfo != null && fxDealInfo.FxDealStatusId == (int)FxDealStatus.Settled) { if (fxDealInfo.FxSettlementSettlementDocumentPostingStatusId != (int)PostingStatus.Posted || fxDealInfo.FxSettlementDealDocumentPostingStatusId != (int)PostingStatus.Posted) { throw new Exception("The FX deal has already matured but the settlement documents have not been posted yet. Please post the documents before deleting the deal."); } else { List <FxDealDto> fxDeals = new List <FxDealDto>(); fxDeals.Add(fxDealInfo); var fxdealToReverseSettle = new FxDealDocumentCreationCommand { FxDealIds = fxDeals, IsReversal = true, Company = company }; var commandResult = await _mediator.Send(fxdealToReverseSettle); return(Ok(commandResult)); } } else { throw new Exception("Invalid FX deal for reversal."); } }
public async Task <ActionResult <CollectionViewModel <FxDealSectionDto> > > SettleFxDealsDueForSettlement(string company) { IEnumerable <FxDealDto> fxDealsDueForSettlement = await _fxDealQueries.GetFxDealsDueForSettlementAsync(company); if (fxDealsDueForSettlement.Count() > 0) { var command = new FxDealDocumentCreationCommand { FxDealIds = fxDealsDueForSettlement, IsReversal = false, Company = company }; await _mediator.Send(command); } return(NoContent()); }