Exemple #1
0
        /// <summary>
        /// Shows the detail.
        /// </summary>
        /// <param name="transactionId">The transaction identifier.</param>
        public void ShowDetail(int transactionId, int?batchId)
        {
            // show or hide the add new transaction button depending if there is a batch id in the querystring
            lbAddTransaction.Visible = !string.IsNullOrWhiteSpace(PageParameter("batchId"));

            FinancialTransaction txn = null;

            bool editAllowed = UserCanEdit;

            var rockContext = new RockContext();

            if (!transactionId.Equals(0))
            {
                txn = GetTransaction(transactionId, rockContext);
                if (!editAllowed && txn != null)
                {
                    editAllowed = txn.IsAuthorized(Authorization.EDIT, CurrentPerson);
                }
            }

            if (txn == null)
            {
                txn = new FinancialTransaction {
                    Id = 0
                };
                txn.BatchId = batchId;

                // Hide processor fields when adding a new transaction
                cpPaymentGateway.Visible  = false;
                tbTransactionCode.Visible = false;

                // Set values based on previously saved txn values
                int prevBatchId = Session["NewTxnDefault_BatchId"] as int? ?? 0;
                if (prevBatchId == batchId)
                {
                    txn.TransactionDateTime    = Session["NewTxnDefault_TransactionDateTime"] as DateTime?;
                    txn.TransactionTypeValueId = Session["NewTxnDefault_TransactionType"] as int? ?? 0;
                    txn.SourceTypeValueId      = Session["NewTxnDefault_SourceType"] as int?;
                    txn.CurrencyTypeValueId    = Session["NewTxnDefault_CurrencyType"] as int?;
                    txn.CreditCardTypeValueId  = Session["NewTxnDefault_CreditCardType"] as int?;
                    int?accountId = Session["NewTxnDefault_Account"] as int?;
                    if (accountId.HasValue)
                    {
                        var txnDetail = new FinancialTransactionDetail();
                        txnDetail.AccountId = accountId.Value;
                        txn.TransactionDetails.Add(txnDetail);
                    }
                }
            }
            else
            {
                cpPaymentGateway.Visible  = true;
                tbTransactionCode.Visible = true;
            }

            hfTransactionId.Value = txn.Id.ToString();
            hfBatchId.Value       = batchId.HasValue ? batchId.Value.ToString() : string.Empty;

            bool readOnly = false;

            nbEditModeMessage.Text = string.Empty;
            if (!editAllowed)
            {
                readOnly = true;
                nbEditModeMessage.Text   = EditModeMessage.ReadOnlyEditActionNotAllowed(FinancialTransaction.FriendlyTypeName);
                lbEdit.Visible           = false;
                lbAddTransaction.Visible = false;
            }
            else
            {
                lbEdit.Visible           = true;
                lbAddTransaction.Visible = true;
            }

            if (readOnly)
            {
                ShowReadOnlyDetails(txn);
            }
            else
            {
                if (txn.Id > 0)
                {
                    ShowReadOnlyDetails(txn);
                }
                else
                {
                    ShowEditDetails(txn, rockContext);
                }
            }

            lbSave.Visible = !readOnly;
        }