Пример #1
0
        private FinancialScheduledTransaction GetScheduledTransaction(bool refresh = false)
        {
            Person targetPerson = null;

            // If impersonation is allowed, and a valid person key was used, set the target to that person
            bool allowImpersonation = false;
            if ( bool.TryParse( GetAttributeValue( "Impersonation" ), out allowImpersonation ) && allowImpersonation )
            {
                string personKey = PageParameter( "Person" );
                if ( !string.IsNullOrWhiteSpace( personKey ) )
                {
                    targetPerson = new PersonService().GetByUrlEncodedKey( personKey );
                }
            }
            if ( targetPerson == null )
            {
                targetPerson = CurrentPerson;
            }

            // Verify that transaction id is valid for selected person
            if ( targetPerson != null )
            {
                int txnId = int.MinValue;
                if ( int.TryParse( PageParameter( "Txn" ), out txnId ) )
                {
                    var service = new FinancialScheduledTransactionService();
                    var scheduledTransaction = service.Queryable( "ScheduledTransactionDetails,GatewayEntityType" )
                        .Where( t =>
                            t.Id == txnId &&
                            ( t.AuthorizedPersonId == targetPerson.Id || t.AuthorizedPerson.GivingGroupId == targetPerson.GivingGroupId ) )
                        .FirstOrDefault();

                    if (scheduledTransaction != null)
                    {
                        TargetPersonId = scheduledTransaction.AuthorizedPersonId;
                        ScheduledTransactionId = scheduledTransaction.Id;

                        if ( refresh )
                        {
                            string errorMessages = string.Empty;
                            service.UpdateStatus( scheduledTransaction, CurrentPersonId, out errorMessages );
                        }

                        return scheduledTransaction;
                    }
                }
            }

            return null;
        }