Beispiel #1
0
        public ServiceResult ApplyTransaction(Transaction transaction)
        {
            if (_Portfolio == null)
            {
                return(ServiceResult <TransactionsResponse> .NotFound());
            }

            ServiceResult result;

            if (transaction is RestApi.Transactions.Aquisition aquisition)
            {
                _Portfolio.AquireShares(aquisition.Stock, aquisition.TransactionDate, aquisition.Units, aquisition.AveragePrice, aquisition.TransactionCosts, aquisition.CreateCashTransaction, aquisition.Comment, aquisition.Id);
            }
            else if (transaction is RestApi.Transactions.CashTransaction cashTransaction)
            {
                _Portfolio.MakeCashTransaction(cashTransaction.TransactionDate, cashTransaction.CashTransactionType.ToDomain(), cashTransaction.Amount, cashTransaction.Comment, cashTransaction.Id);
            }
            else if (transaction is RestApi.Transactions.CostBaseAdjustment costBaseAdjustment)
            {
                _Portfolio.AdjustCostBase(costBaseAdjustment.Stock, costBaseAdjustment.TransactionDate, costBaseAdjustment.Percentage, costBaseAdjustment.Comment, costBaseAdjustment.Id);
            }
            else if (transaction is RestApi.Transactions.Disposal disposal)
            {
                _Portfolio.DisposeOfShares(disposal.Stock, disposal.TransactionDate, disposal.Units, disposal.AveragePrice, disposal.TransactionCosts, disposal.CgtMethod.ToDomain(), disposal.CreateCashTransaction, disposal.Comment, disposal.Id);
            }
            else if (transaction is RestApi.Transactions.IncomeReceived income)
            {
                _Portfolio.IncomeReceived(income.Stock, income.RecordDate, income.TransactionDate, income.FrankedAmount, income.UnfrankedAmount, income.FrankingCredits, income.Interest, income.TaxDeferred, income.DrpCashBalance, income.CreateCashTransaction, income.Comment, income.Id);
            }
            else if (transaction is RestApi.Transactions.OpeningBalance openingBalance)
            {
                _Portfolio.AddOpeningBalance(openingBalance.Stock, openingBalance.TransactionDate, openingBalance.AquisitionDate, openingBalance.Units, openingBalance.CostBase, openingBalance.Comment, openingBalance.Id);
            }
            else if (transaction is RestApi.Transactions.ReturnOfCapital returnOfCapital)
            {
                _Portfolio.ReturnOfCapitalReceived(returnOfCapital.Stock, returnOfCapital.TransactionDate, returnOfCapital.RecordDate, returnOfCapital.Amount, returnOfCapital.CreateCashTransaction, returnOfCapital.Comment, returnOfCapital.Id);
            }
            else if (transaction is RestApi.Transactions.UnitCountAdjustment unitCountAdjustment)
            {
                _Portfolio.AdjustUnitCount(unitCountAdjustment.Stock, unitCountAdjustment.TransactionDate, unitCountAdjustment.OriginalUnits, unitCountAdjustment.NewUnits, unitCountAdjustment.Comment, unitCountAdjustment.Id);
            }
            else
            {
                result = ServiceResult.Error("Unkown Transaction type");
            }

            _Repository.Update((Portfolio)_Portfolio);

            return(ServiceResult.Ok());
        }