/// <summary> /// Shows the view. /// </summary> private void ShowForm() { lReceipt.Visible = false; pnlAddPledge.Visible = true; if (CurrentPerson != null) { lName.Text = CurrentPerson.FullName; lName.Visible = true; tbFirstName.Visible = false; tbLastName.Visible = false; tbEmail.Visible = false; using (var rockContext = new RockContext()) { Guid?groupTypeGuid = GetAttributeValue("SelectGroupType").AsGuidOrNull(); if (groupTypeGuid.HasValue) { var groups = new GroupMemberService(rockContext) .Queryable().AsNoTracking() .Where(m => m.Group.GroupType.Guid == groupTypeGuid.Value && m.PersonId == CurrentPerson.Id && m.GroupMemberStatus == GroupMemberStatus.Active && m.Group.IsActive && !m.Group.IsArchived) .Select(m => new { m.GroupId, Name = m.Group.Name, GroupTypeName = m.Group.GroupType.Name }) .ToList() .Distinct() .OrderBy(g => g.Name) .ToList(); if (groups.Any()) { ddlGroup.Label = "For " + groups.First().GroupTypeName; ddlGroup.DataSource = groups; ddlGroup.DataBind(); ddlGroup.Visible = true; } else { ddlGroup.Visible = false; } } else { ddlGroup.Visible = false; } } } else { lName.Visible = false; ddlGroup.Visible = false; tbFirstName.Visible = true; tbLastName.Visible = true; tbEmail.Visible = true; tbFirstName.Text = string.Empty; tbLastName.Text = string.Empty; tbEmail.Text = string.Empty; } // Warn if Financial Account is not specified (must be set up by administrator) var financialAccount = new FinancialAccountService(new RockContext()).Get(GetAttributeValue("Account").AsGuid()); if (financialAccount == null) { nbWarningMessage.Text = "Warning: No Account is specified for this pledge. Please contact the administrator."; nbWarningMessage.Visible = true; } else { nbWarningMessage.Visible = false; } drpDateRange.DelimitedValues = GetAttributeValue("PledgeDateRange"); // only show the date range picker if the block setting for date range isn't fully specified drpDateRange.Visible = drpDateRange.LowerValue == null || drpDateRange.UpperValue == null; ddlFrequency.Items.Clear(); var frequencies = DefinedTypeCache.Get(Rock.SystemGuid.DefinedType.FINANCIAL_FREQUENCY.AsGuid()) .DefinedValues.Where(dv => dv.IsActive).OrderBy(a => a.Order).ThenBy(a => a.Value); foreach (var frequency in frequencies) { ddlFrequency.Items.Add(new ListItem(frequency.Value, frequency.Id.ToString())); } ddlFrequency.Visible = GetAttributeValue("ShowPledgeFrequency").AsBooleanOrNull() ?? false; ddlFrequency.SelectedValue = null; // if Frequency is Visible, require it if RequirePledgeFrequency ddlFrequency.Required = ddlFrequency.Visible && (GetAttributeValue("RequirePledgeFrequency").AsBooleanOrNull() ?? false); string saveButtonText = GetAttributeValue("SaveButtonText"); if (!string.IsNullOrWhiteSpace(saveButtonText)) { btnSave.Text = saveButtonText; } else { btnSave.Text = "Save"; } lNote.Text = GetAttributeValue("NoteMessage"); }