private void SetDeclineReasonsField(List <Attendance> attendances)
            {
                var declinedAttendances = attendances.Where(a => a.RSVP == RSVP.No);
                var declinedReasons     = new StringBuilder("<ul class='list-unstyled m-0'>");

                foreach (var declinedAttendance in declinedAttendances)
                {
                    var declinedReason = DefinedValueCache.GetValue(declinedAttendance.DeclineReasonValueId);
                    declinedReasons.Append(string.Format("<li><small>{0}</small> {1}</li>", declinedAttendance.StartDateTime.ToShortDateTimeString(), declinedReason.EncodeHtml()));
                }
                declinedReasons.Append("</ul>");
                DeclinedReasons = declinedReasons.ToString();
            }
예제 #2
0
        public void CompleteChanges(RockContext rockContext = null)
        {
            SecurityChangeDetail securityChangeDetail = new SecurityChangeDetail
            {
                ChangeRequestId = this.Id,
                ChangeDetails   = new List <string>()
            };

            if (rockContext == null)
            {
                rockContext = new RockContext();
            }
            using (var dbContextTransaction = rockContext.Database.BeginTransaction())
            {
                try
                {
                    IEntity entity = GetEntity(EntityTypeId, EntityId, rockContext);

                    //Make changes
                    foreach (var changeRecord in ChangeRecords.Where(r => r.WasApplied != true && r.IsRejected == false))
                    {
                        var targetEntity = entity;
                        if (changeRecord.RelatedEntityTypeId.HasValue)
                        {
                            if (changeRecord.RelatedEntityId.HasValue &&
                                !(changeRecord.RelatedEntityId == 0 || changeRecord.Action == ChangeRecordAction.Create))
                            {
                                //existing entity
                                targetEntity = GetEntity(changeRecord.RelatedEntityTypeId.Value, changeRecord.RelatedEntityId.Value, rockContext);
                            }
                            else
                            {
                                //new entity
                                targetEntity = CreateNewEntity(changeRecord.RelatedEntityTypeId.Value, changeRecord.NewValue, rockContext);
                                changeRecord.RelatedEntityId = targetEntity.Id;

                                //if we add a phone number add that to the change list
                                if (targetEntity?.GetType() == typeof(PhoneNumber))
                                {
                                    var number     = targetEntity as PhoneNumber;
                                    var numberType = DefinedValueCache.GetValue(number.NumberTypeValueId.Value);
                                    securityChangeDetail.ChangeDetails.Add(string.Format("Added {0} phone number {1}", numberType, number.NumberFormatted));
                                }
                            }
                        }

                        //Some times entitities can be deleted (such as a binary file being cleaned up)
                        //And cannot update, delete or change and attribute on it anymore
                        if (targetEntity == null)
                        {
                            continue;
                        }

                        //Remove records marked as delete
                        if (changeRecord.Action == ChangeRecordAction.Delete)
                        {
                            DeleteEntity(targetEntity, rockContext);
                        }
                        else if (changeRecord.Action == ChangeRecordAction.Attribute)
                        {
                            UpdateAttribute(targetEntity, changeRecord.Property, changeRecord.NewValue, rockContext);
                        }
                        else if (changeRecord.Property.IsNotNullOrWhiteSpace())
                        {
                            PropertyInfo prop = targetEntity.GetType().GetProperty(changeRecord.Property, BindingFlags.Public | BindingFlags.Instance);

                            if (prop != null && prop.PropertyType.GetInterfaces().Any(i => i.IsInterface && i.GetInterfaces().Contains(typeof(IEntity))))
                            {
                                PropertyInfo propId    = targetEntity.GetType().GetProperty(changeRecord.Property + "Id", BindingFlags.Public | BindingFlags.Instance);
                                var          newObject = changeRecord.NewValue.FromJsonOrNull <BasicEntity>();
                                prop.SetValue(targetEntity, null, null);
                                if (newObject != null)
                                {
                                    propId.SetValue(targetEntity, newObject.Id);
                                }
                                else
                                {
                                    propId.SetValue(targetEntity, null, null);
                                }
                            }
                            else
                            {
                                SetProperty(targetEntity, prop, changeRecord.NewValue);
                            }
                        }
                        changeRecord.WasApplied = true;

                        //Check to see if the email address was changed
                        var targetEntityType = targetEntity?.GetType();
                        if (targetEntityType?.BaseType == typeof(Person) && // is a person
                            changeRecord.Property == "Email" && // and changed email
                            changeRecord.OldValue.IsNotNullOrWhiteSpace() && //old value isn't blank
                            changeRecord.NewValue.IsNotNullOrWhiteSpace()    //new value isn't blank
                            )
                        {
                            securityChangeDetail.ChangeDetails.Add(string.Format("Changed email address from {0} to {1}", changeRecord.OldValue, changeRecord.NewValue));
                            securityChangeDetail.CurrentEmail  = changeRecord.NewValue;
                            securityChangeDetail.PreviousEmail = changeRecord.OldValue;
                        }

                        //Check to see if the phone number was changed
                        if (targetEntityType?.BaseType == typeof(PhoneNumber) && //is a phonenuumber
                            changeRecord.Property == "Number"     //is a number change
                            )
                        {
                            var number     = targetEntity as PhoneNumber;
                            var numberType = DefinedValueCache.GetValue(number.NumberTypeValueId.Value);
                            securityChangeDetail.ChangeDetails.Add(string.Format("Changed {0} phone number from {1} to {2}",
                                                                                 numberType,
                                                                                 PhoneNumber.FormattedNumber(PhoneNumber.DefaultCountryCode(), changeRecord.OldValue),
                                                                                 PhoneNumber.FormattedNumber(PhoneNumber.DefaultCountryCode(), changeRecord.NewValue)));
                        }
                    }

                    //Undo Changes
                    foreach (var changeRecord in ChangeRecords.Where(r => r.WasApplied == true && r.IsRejected == true))
                    {
                        var targetEntity = entity;

                        if (changeRecord.RelatedEntityTypeId.HasValue && changeRecord.Action != ChangeRecordAction.Delete)
                        {
                            if (changeRecord.RelatedEntityId.HasValue && changeRecord.Action != ChangeRecordAction.Create)
                            {
                                //existing entity
                                targetEntity = GetEntity(changeRecord.RelatedEntityTypeId.Value, changeRecord.RelatedEntityId.Value, rockContext);
                            }
                            else
                            {
                                //This was a created entity that we must now murder in cold blood.
                                targetEntity = GetEntity(changeRecord.RelatedEntityTypeId.Value, changeRecord.RelatedEntityId.Value, rockContext);
                                DeleteEntity(targetEntity, rockContext);
                                changeRecord.WasApplied = false;
                                continue;
                            }
                        }

                        //Undelete
                        if (changeRecord.RelatedEntityTypeId.HasValue && changeRecord.Action == ChangeRecordAction.Delete)
                        {
                            targetEntity = CreateNewEntity(changeRecord.RelatedEntityTypeId.Value, changeRecord.OldValue, rockContext);
                            changeRecord.RelatedEntityId = targetEntity.Id;
                        }
                        else if (changeRecord.Action == ChangeRecordAction.Attribute)
                        {
                            UpdateAttribute(targetEntity, changeRecord.Property, changeRecord.OldValue, rockContext);
                        }
                        //Property changes
                        else if (changeRecord.Property.IsNotNullOrWhiteSpace())
                        {
                            PropertyInfo prop = targetEntity?.GetType()?.GetProperty(changeRecord.Property, BindingFlags.Public | BindingFlags.Instance);
                            if (targetEntity == null || prop == null)
                            {
                                //Entity was probably deleted after the change request
                                continue;
                            }

                            if (prop.PropertyType.GetInterfaces().Any(i => i.IsInterface && i.GetInterfaces().Contains(typeof(IEntity))))
                            {
                                PropertyInfo propId    = targetEntity.GetType().GetProperty(changeRecord.Property + "Id", BindingFlags.Public | BindingFlags.Instance);
                                var          oldObject = changeRecord.OldValue.FromJsonOrNull <BasicEntity>();
                                prop.SetValue(targetEntity, null, null);
                                if (oldObject != null)
                                {
                                    propId.SetValue(targetEntity, oldObject.Id);
                                }
                                else
                                {
                                    propId.SetValue(targetEntity, null, null);
                                }
                            }
                            else
                            {
                                SetProperty(targetEntity, prop, changeRecord.OldValue);
                            }
                        }
                        changeRecord.WasApplied = false;
                    }


                    rockContext.SaveChanges();
                    dbContextTransaction.Commit();

                    if (entity.GetType()?.BaseType == typeof(Person) && securityChangeDetail.ChangeDetails.Any())
                    {
                        var workflowGuid = GlobalAttributesCache.Get().GetValue("ChangeManagerSecurityWorkflow").AsGuidOrNull();
                        this.LaunchWorkflow(workflowGuid,
                                            "Change Request Security Notice",
                                            new Dictionary <string, string> {
                            { "ChangeDetail", securityChangeDetail.ToJson() }
                        });
                    }
                }
                catch (Exception e)
                {
                    dbContextTransaction.Rollback();
                    throw new Exception("Exception occured durring saving changes.", e);
                }
            }
        }
        /// <summary>
        /// Handles the ItemDataBound event of the rptSavedAccounts control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RepeaterItemEventArgs"/> instance containing the event data.</param>
        protected void rptSavedAccounts_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            var financialPersonSavedAccount = e.Item.DataItem as FinancialPersonSavedAccount;

            if (financialPersonSavedAccount == null)
            {
                return;
            }

            var lSavedAccountName = e.Item.FindControl("lSavedAccountName") as Literal;

            var pnlCreditCardInfo      = e.Item.FindControl("pnlSavedAccountCreditCardInfo") as Panel;
            var lOtherCurrencyTypeInfo = e.Item.FindControl("lSavedAccountOtherCurrencyTypeInfo") as Literal;

            var lSavedAccountCardTypeLast4   = e.Item.FindControl("lSavedAccountCardTypeLast4") as Literal;
            var lSavedAccountExpiration      = e.Item.FindControl("lSavedAccountExpiration") as Literal;
            var lSavedAccountInUseStatusHtml = e.Item.FindControl("lSavedAccountInUseStatusHtml") as Literal;
            var btnSavedAccountDelete        = e.Item.FindControl("btnSavedAccountDelete") as LinkButton;

            lSavedAccountName.Text = financialPersonSavedAccount.Name;
            var financialPaymentDetail = financialPersonSavedAccount.FinancialPaymentDetail;

            string creditCardType      = null;
            string accountNumberMasked = financialPaymentDetail?.AccountNumberMasked;

            if (financialPaymentDetail?.CreditCardTypeValueId != null)
            {
                creditCardType = DefinedValueCache.GetValue(financialPaymentDetail.CreditCardTypeValueId.Value);
            }

            var currencyTypeIdCreditCard = DefinedValueCache.GetId(Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_CREDIT_CARD.AsGuid());

            if (financialPaymentDetail?.CurrencyTypeValueId == currencyTypeIdCreditCard)
            {
                pnlCreditCardInfo.Visible      = true;
                lOtherCurrencyTypeInfo.Visible = false;

                if (accountNumberMasked.IsNotNullOrWhiteSpace() && accountNumberMasked.Length >= 4)
                {
                    var last4 = accountNumberMasked.Substring(accountNumberMasked.Length - 4);
                    lSavedAccountCardTypeLast4.Text = $"{creditCardType} - {last4}";
                }
                else
                {
                    lSavedAccountCardTypeLast4.Text = creditCardType;
                }

                lSavedAccountExpiration.Text = $"Exp: {financialPaymentDetail.ExpirationDate}";
            }
            else
            {
                pnlCreditCardInfo.Visible      = false;
                lOtherCurrencyTypeInfo.Visible = true;
                lOtherCurrencyTypeInfo.Text    = financialPaymentDetail?.CurrencyTypeValue?.Value;
            }

            var cardIsExpired = financialPaymentDetail.CardExpirationDate.HasValue && financialPaymentDetail.CardExpirationDate.Value < RockDateTime.Now;

            var cardInUse = new FinancialScheduledTransactionService(new RockContext()).Queryable().Where(a => a.FinancialPaymentDetailId.HasValue &&
                                                                                                          a.IsActive &&
                                                                                                          a.FinancialPaymentDetail.FinancialPersonSavedAccountId.HasValue &&
                                                                                                          a.FinancialPaymentDetail.FinancialPersonSavedAccountId.Value == financialPersonSavedAccount.Id).Any();

            btnSavedAccountDelete.Visible         = !cardInUse;
            btnSavedAccountDelete.CommandArgument = financialPersonSavedAccount.Guid.ToString();

            if (cardIsExpired)
            {
                lSavedAccountInUseStatusHtml.Text = "<span class='text-xs text-danger text-nowrap'>Expired</span>";
            }
            else
            {
                if (cardInUse)
                {
                    lSavedAccountInUseStatusHtml.Text = "<span class='text-xs text-success text-nowrap'>In Use</span>";
                }
                else
                {
                    lSavedAccountInUseStatusHtml.Text = "<span class='text-xs text-muted text-nowrap'>Not In Use</span>";
                }
            }
        }
        /// <summary>
        /// Handles the ItemDataBound event of the rptScheduledTransaction control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RepeaterItemEventArgs"/> instance containing the event data.</param>
        protected void rptScheduledTransaction_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            var financialScheduledTransaction = e.Item.DataItem as FinancialScheduledTransaction;

            if (financialScheduledTransaction == null)
            {
                return;
            }

            var financialPaymentDetail = financialScheduledTransaction.FinancialPaymentDetail;

            var btnScheduledTransactionEdit = e.Item.FindControl("btnScheduledTransactionEdit") as LinkButton;

            btnScheduledTransactionEdit.CommandArgument = financialScheduledTransaction.Guid.ToString();

            var btnScheduledTransactionInactivate = e.Item.FindControl("btnScheduledTransactionInactivate") as LinkButton;

            btnScheduledTransactionInactivate.CommandArgument = financialScheduledTransaction.Guid.ToString();


            if (financialScheduledTransaction.IsActive)
            {
                btnScheduledTransactionInactivate.Visible = true;
            }
            else
            {
                btnScheduledTransactionInactivate.Visible = false;
            }

            var lScheduledTransactionAccountName = e.Item.FindControl("lScheduledTransactionAccountName") as Literal;
            var lScheduledTransactionFrequencyAndNextPaymentDate = e.Item.FindControl("lScheduledTransactionFrequencyAndNextPaymentDate") as Literal;
            var lScheduledTransactionTotalAmount = e.Item.FindControl("lScheduledTransactionTotalAmount") as Literal;

            var lScheduledTransactionCardTypeLast4    = e.Item.FindControl("lScheduledTransactionCardTypeLast4") as Literal;
            var lScheduledTransactionExpiration       = e.Item.FindControl("lScheduledTransactionExpiration") as Literal;
            var lScheduledTransactionSavedAccountName = e.Item.FindControl("lScheduledTransactionSavedAccountName") as Literal;
            var lScheduledTransactionStatusHtml       = e.Item.FindControl("lScheduledTransactionStatusHtml") as Literal;
            var pnlCreditCardInfo      = e.Item.FindControl("pnlScheduledTransactionCreditCardInfo") as Panel;
            var lOtherCurrencyTypeInfo = e.Item.FindControl("lScheduledTransactionOtherCurrencyTypeInfo") as Literal;

            string creditCardType      = null;
            string accountNumberMasked = financialPaymentDetail?.AccountNumberMasked;

            if (financialPaymentDetail?.CreditCardTypeValueId != null)
            {
                creditCardType = DefinedValueCache.GetValue(financialPaymentDetail.CreditCardTypeValueId.Value);
            }

            var currencyTypeIdCreditCard = DefinedValueCache.GetId(Rock.SystemGuid.DefinedValue.CURRENCY_TYPE_CREDIT_CARD.AsGuid());


            if (financialPaymentDetail?.CurrencyTypeValueId == currencyTypeIdCreditCard)
            {
                pnlCreditCardInfo.Visible      = true;
                lOtherCurrencyTypeInfo.Visible = false;
                if (accountNumberMasked.IsNotNullOrWhiteSpace() && accountNumberMasked.Length >= 4)
                {
                    var last4 = accountNumberMasked.Substring(accountNumberMasked.Length - 4);
                    lScheduledTransactionCardTypeLast4.Text = $"{creditCardType} - {last4}";
                }
                else
                {
                    lScheduledTransactionCardTypeLast4.Text = creditCardType;
                }

                lScheduledTransactionExpiration.Text = $"Exp: {financialPaymentDetail.ExpirationDate}";
            }
            else
            {
                pnlCreditCardInfo.Visible      = false;
                lOtherCurrencyTypeInfo.Visible = true;
                lOtherCurrencyTypeInfo.Text    = financialPaymentDetail?.CurrencyTypeValue?.Value;
            }

            if (financialPaymentDetail?.FinancialPersonSavedAccount != null)
            {
                lScheduledTransactionSavedAccountName.Text = financialPaymentDetail?.FinancialPersonSavedAccount.Name;
            }

            var frequencyText   = DefinedValueCache.GetValue(financialScheduledTransaction.TransactionFrequencyValueId);
            var nextPaymentDate = financialScheduledTransaction.NextPaymentDate;

            if (financialScheduledTransaction.IsActive)
            {
                if (nextPaymentDate.HasValue)
                {
                    lScheduledTransactionFrequencyAndNextPaymentDate.Text = $"{frequencyText} <span class='o-30'>|</span> Next Gift {nextPaymentDate.ToShortDateString()}";
                }
                else
                {
                    lScheduledTransactionFrequencyAndNextPaymentDate.Text = $"{frequencyText}";
                }
            }
            else
            {
                lScheduledTransactionFrequencyAndNextPaymentDate.Text = $"{frequencyText}";
                lScheduledTransactionStatusHtml.Text = "<span class='text-xs text-warning text-nowrap'>Inactive</span>";
            }

            if (lScheduledTransactionAccountName != null)
            {
                var accountGuids = GetAttributeValue(AttributeKey.Accounts).SplitDelimitedValues().AsGuidList();
                var summary      = financialScheduledTransaction.ScheduledTransactionDetails
                                   .Select(d => new
                {
                    IsOther = accountGuids.Any() && !accountGuids.Contains(d.Account.Guid),
                    Order   = d.Account.Order,
                    Name    = d.Account.Name,
                })
                                   .OrderBy(d => d.IsOther)
                                   .ThenBy(d => d.Order)
                                   .Select(d => string.Format("{0}", !d.IsOther ? d.Name : "Other"))
                                   .ToList();

                if (summary.Any())
                {
                    lScheduledTransactionAccountName.Text = summary.AsDelimited(", ");
                }
            }

            if (lScheduledTransactionTotalAmount != null)
            {
                lScheduledTransactionTotalAmount.Text = financialScheduledTransaction.TotalAmount.FormatAsCurrency(financialScheduledTransaction.ForeignCurrencyCodeValueId);
            }
        }
예제 #5
0
        /// <summary>
        /// Shows the read only details.
        /// </summary>
        /// <param name="campus">The <see cref="Campus"/>.</param>
        private void ShowReadOnlyDetails(Campus campus)
        {
            SetEditMode(false);

            if (campus == null)
            {
                return;
            }

            lActionTitle.Text = campus.Name.FormatAsHtmlTitle();
            SetStatusLabel(campus);

            lDescription.Text = campus.Description;

            // left column (col-md-6)
            var dl = new DescriptionList();

            if (campus.CampusStatusValueId.HasValue)
            {
                dl.Add("Status", DefinedValueCache.GetValue(campus.CampusStatusValueId));
            }

            if (!string.IsNullOrWhiteSpace(campus.ShortCode))
            {
                dl.Add("Code", campus.ShortCode);
            }

            if (!string.IsNullOrWhiteSpace(campus.TimeZoneId))
            {
                dl.Add("Time Zone", campus.TimeZoneId);
            }

            if (campus.LeaderPersonAlias != null)
            {
                dl.Add("Campus Leader", campus.LeaderPersonAlias.Person.FullName);
            }

            var serviceTimes = GetReadOnlyServiceTimes(campus);

            if (!string.IsNullOrWhiteSpace(serviceTimes))
            {
                dl.Add("Service Times", serviceTimes);
            }

            if (campus.CampusSchedules.Any())
            {
                var scheduleText = campus.CampusSchedules.Select(s => s.Schedule.Name).ToList().AsDelimited(", ");
                dl.Add("Campus Schedules", scheduleText);
            }

            if (campus.CampusTopics.Any())
            {
                dl.Add("Topics", ConstructReadOnlyTopics(campus));
            }

            lMainDetailsLeft.Text = dl.Html;

            // right column (col-md-6)
            dl = new DescriptionList();

            if (campus.CampusTypeValueId.HasValue)
            {
                dl.Add("Type", DefinedValueCache.GetValue(campus.CampusTypeValueId));
            }

            if (!string.IsNullOrWhiteSpace(campus.Url))
            {
                dl.Add("URL", campus.Url);
            }

            if (!string.IsNullOrWhiteSpace(campus.PhoneNumber))
            {
                dl.Add("Phone Number", campus.PhoneNumber);
            }

            if (campus.Location != null)
            {
                dl.Add("Location", campus.Location.Name);
            }

            lMainDetailsRight.Text = dl.Html;
        }
예제 #6
0
        /// <summary>
        /// Handles the DisplayFilterValue event of the gfBatchFilter control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="Rock.Web.UI.Controls.GridFilter.DisplayFilterValueArgs"/> instance containing the event data.</param>
        protected void gfBatchFilter_DisplayFilterValue(object sender, Rock.Web.UI.Controls.GridFilter.DisplayFilterValueArgs e)
        {
            if (AvailableAttributes != null)
            {
                var attribute = AvailableAttributes.FirstOrDefault(a => "Attribute_" + a.Key == e.Key);
                if (attribute != null)
                {
                    try
                    {
                        var values = JsonConvert.DeserializeObject <List <string> >(e.Value);
                        e.Value = attribute.FieldType.Field.FormatFilterValues(attribute.QualifierValues, values);
                        return;
                    }
                    catch
                    {
                        // intentionally ignore
                    }
                }
            }

            switch (e.Key)
            {
            case "Row Limit":
            {
                // row limit filter was removed, so hide it just in case
                e.Value = null;
                break;
            }

            case "Date Range":
            {
                e.Value = DateRangePicker.FormatDelimitedValues(e.Value);
                break;
            }

            case "Status":
            {
                var status = e.Value.ConvertToEnumOrNull <BatchStatus>();
                if (status.HasValue)
                {
                    e.Value = status.ConvertToString();
                }
                else
                {
                    e.Value = string.Empty;
                }

                break;
            }

            case "Contains Transaction Type":
            {
                var transactionTypeValueId = e.Value.AsIntegerOrNull();
                if (transactionTypeValueId.HasValue)
                {
                    var transactionTypeValue = DefinedValueCache.Get(transactionTypeValueId.Value);
                    e.Value = transactionTypeValue != null?transactionTypeValue.ToString() : string.Empty;
                }
                else
                {
                    e.Value = string.Empty;
                }

                break;
            }

            case "Campus":
            {
                var campus = CampusCache.Get(e.Value.AsInteger());
                if (campus != null)
                {
                    e.Value = campus.Name;
                }
                else
                {
                    e.Value = string.Empty;
                }

                break;
            }

            case "Contains Source Type":
            {
                var sourceTypeValueId = e.Value.AsIntegerOrNull();
                if (sourceTypeValueId.HasValue)
                {
                    e.Value = DefinedValueCache.GetValue(sourceTypeValueId.Value);
                }
                else
                {
                    e.Value = string.Empty;
                }

                break;
            }
            }
        }