protected async Task <Guid> RetrieveAccountingGroupAndApplySaleStrategy(Guid userId, Guid pointOfSaleId, decimal saleCost) { var pointOfSale = await _posSvc.GetPointOfSale(pointOfSaleId); if (pointOfSale is null) { throw new BaristaException("invalid_point_of_sale", $"The point of sale with ID '{pointOfSaleId}' was not found."); } var accountingGroup = await _agSvc.GetAccountingGroup(pointOfSale.ParentAccountingGroupId); if (accountingGroup is null) { throw new BaristaException("invalid_accounting_group", $"The accounting group with ID '{pointOfSale.ParentAccountingGroupId}' to which PoS '{pointOfSaleId}' belongs was not found."); } var saleStrategyId = pointOfSale.SaleStrategyId ?? accountingGroup.SaleStrategyId; var saleStrategyApplicationResult = await _busPublisher.SendRequest <IApplySaleStrategy, IOperationResult>( new ApplySaleStrategy(userId, saleStrategyId, saleCost) ); if (!saleStrategyApplicationResult.Successful) { throw new BaristaException("sale_strategy_application_failed", $"The sale strategy with ID '{saleStrategyId}' rejected the purchase: {saleStrategyApplicationResult.ErrorCode}"); } return(accountingGroup.Id); }
public async Task <ActionResult <AccountingGroup> > GetAccountingGroup(Guid id) => Single(await _accountingGroupsService.GetAccountingGroup(id));