コード例 #1
0
ファイル: FinancialPledgeTest.cs プロジェクト: waldo2590/Rock
        public void FinancialPledgeDateKeyJoinsCorrectly()
        {
            var expectedRecordCount = 15;
            var year                   = 2015;
            var rockContext            = new RockContext();
            var financialPledgeService = new FinancialPledgeService(rockContext);

            var minDateValue = TestDataHelper.GetAnalyticsSourceMinDateForYear(rockContext, year);
            var maxDateValue = TestDataHelper.GetAnalyticsSourceMaxDateForYear(rockContext, year);

            for (var i = 0; i < 15; i++)
            {
                var financialPledge = BuildFinancialPledge(rockContext,
                                                           TestDataHelper.GetRandomDateInRange(minDateValue, maxDateValue),
                                                           TestDataHelper.GetRandomDateInRange(minDateValue, maxDateValue));

                financialPledgeService.Add(financialPledge);
            }

            rockContext.SaveChanges();

            var financialPledges = financialPledgeService.
                                   Queryable("AnalyticsSourceDate").
                                   Where(i => i.ForeignKey == financialPledgeForeignKey).
                                   Where(i => i.StartSourceDate.CalendarYear == year);

            Assert.AreEqual(expectedRecordCount, financialPledges.Count());

            financialPledges = financialPledgeService.
                               Queryable("AnalyticsSourceDate").
                               Where(i => i.ForeignKey == financialPledgeForeignKey).
                               Where(i => i.EndSourceDate.CalendarYear == year);

            Assert.AreEqual(expectedRecordCount, financialPledges.Count());
        }
コード例 #2
0
ファイル: CreatePledge.ascx.cs プロジェクト: shelsonjava/Rock
        /// <summary>
        /// Handles the Click event of the btnConfirmYes control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void btnConfirmYes_Click(object sender, EventArgs e)
        {
            var pledges = Session["CachedPledges"] as List <FinancialPledge>;

            if (pledges == null)
            {
                return;
            }

            RockTransactionScope.WrapTransaction(() =>
            {
                foreach (var pledge in pledges)
                {
                    if (pledge == null || !pledge.IsValid)
                    {
                        continue;
                    }

                    var pledgeService = new FinancialPledgeService();
                    pledgeService.Add(pledge, CurrentPersonId);
                    pledgeService.Save(pledge, CurrentPersonId);
                }

                Session.Remove("CachedPledges");
                ShowReceipt(pledges.Select(p => p.Id));
            });
        }
コード例 #3
0
        /// <summary>
        /// Handles the Click event of the btnSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        /// <exception cref="System.NotImplementedException"></exception>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            FinancialPledge pledge;
            var             pledgeService = new FinancialPledgeService();
            var             pledgeId      = int.Parse(hfPledgeId.Value);

            if (pledgeId == 0)
            {
                pledge = new FinancialPledge();
                pledgeService.Add(pledge, CurrentPersonId);
            }
            else
            {
                pledge = pledgeService.Get(pledgeId);
            }

            pledge.PersonId    = ppPerson.PersonId;
            pledge.AccountId   = int.Parse(fpFund.SelectedValue);
            pledge.TotalAmount = decimal.Parse(tbAmount.Text);

            pledge.StartDate = dpDateRange.LowerValue.Value;
            pledge.EndDate   = dpDateRange.UpperValue.Value;
            pledge.PledgeFrequencyValueId = int.Parse(ddlFrequencyType.SelectedValue);

            if (!pledge.IsValid)
            {
                // Controls will render the error messages
                return;
            }

            RockTransactionScope.WrapTransaction(() => pledgeService.Save(pledge, CurrentPersonId));
            NavigateToParentPage();
        }
コード例 #4
0
ファイル: FinancialPledgeTest.cs プロジェクト: waldo2590/Rock
        public void FinancialPledgeDateKeySavesCorrectly()
        {
            var rockContext            = new RockContext();
            var financialPledgeService = new FinancialPledgeService(rockContext);

            var financialPledge = BuildFinancialPledge(rockContext,
                                                       Convert.ToDateTime("3/15/2010"),
                                                       Convert.ToDateTime("3/16/2010"));

            financialPledgeService.Add(financialPledge);
            rockContext.SaveChanges();

            var financialPledgeId = financialPledge.Id;

            // We're bypassing the model because the model doesn't user the FinancialPledgeDateKey from the database,
            // but it still needs to be correct for inner joins to work correctly.
            var result = rockContext.Database.
                         SqlQuery <int>($"SELECT StartDateKey FROM FinancialPledge WHERE Id = {financialPledgeId}").First();

            Assert.AreEqual(20100315, result);

            result = rockContext.Database.
                     SqlQuery <int>($"SELECT EndDateKey FROM FinancialPledge WHERE Id = {financialPledgeId}").First();
            Assert.AreEqual(20100316, result);
        }
コード例 #5
0
        /// <summary>
        /// Handles the Click event of the btnConfirmYes control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void btnConfirmYes_Click(object sender, EventArgs e)
        {
            var pledges = Session["CachedPledges"] as List <FinancialPledge>;

            if (pledges == null)
            {
                return;
            }

            var rockContext   = new RockContext();
            var pledgeService = new FinancialPledgeService(rockContext);

            foreach (var pledge in pledges)
            {
                if (pledge == null || !pledge.IsValid)
                {
                    continue;
                }

                pledgeService.Add(pledge);
            }

            rockContext.SaveChanges();

            Session.Remove("CachedPledges");
            ShowReceipt(pledges.Select(p => p.Id));
        }
コード例 #6
0
        /// <summary>
        /// Handles the Click event of the btnSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        /// <exception cref="System.NotImplementedException"></exception>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            var rockContext   = new RockContext();
            var pledgeService = new FinancialPledgeService(rockContext);
            var person        = FindPerson(rockContext);
            var pledges       = GetPledges(person).ToList();

            // Does this person already have a pledge for these accounts?
            // If so, give them the option to create a new one?
            var personPledgeAccountIds = pledgeService.Queryable()
                                         .Where(p => p.PersonId == person.Id)
                                         .Select(p => p.AccountId)
                                         .ToList();

            if (Accounts.Any(a => personPledgeAccountIds.Contains(a.Id)))
            {
                pnlConfirm.Visible = true;
                Session.Add("CachedPledges", pledges);
                return;
            }

            foreach (var pledge in pledges)
            {
                if (!pledge.IsValid)
                {
                    continue;
                }

                pledgeService.Add(pledge);
            }

            rockContext.SaveChanges();

            ShowReceipt(pledges.Select(p => p.Id));
        }
コード例 #7
0
ファイル: PledgeDetail.ascx.cs プロジェクト: waldo2590/Rock
        /// <summary>
        /// Handles the Click event of the btnSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        /// <exception cref="System.NotImplementedException"></exception>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            FinancialPledge pledge;
            var             rockContext   = new RockContext();
            var             pledgeService = new FinancialPledgeService(rockContext);
            var             pledgeId      = hfPledgeId.Value.AsInteger();

            if (pledgeId == 0)
            {
                pledge = new FinancialPledge();
                pledgeService.Add(pledge);
            }
            else
            {
                pledge = pledgeService.Get(pledgeId);
            }

            pledge.PersonAliasId = ppPerson.PersonAliasId;
            pledge.GroupId       = ddlGroup.SelectedValueAsInt();
            pledge.AccountId     = apAccount.SelectedValue.AsIntegerOrNull();
            pledge.TotalAmount   = tbAmount.Text.AsDecimal();

            pledge.StartDate = dpDateRange.LowerValue.HasValue ? dpDateRange.LowerValue.Value : DateTime.MinValue;
            pledge.EndDate   = dpDateRange.UpperValue.HasValue ? dpDateRange.UpperValue.Value : DateTime.MaxValue;

            pledge.PledgeFrequencyValueId = dvpFrequencyType.SelectedValue.AsIntegerOrNull();

            pledge.LoadAttributes(rockContext);
            Rock.Attribute.Helper.GetEditValues(phAttributes, pledge);

            if (!pledge.IsValid)
            {
                ShowInvalidResults(pledge.ValidationResults);
                return;
            }

            rockContext.SaveChanges();
            pledge.SaveAttributeValues(rockContext);

            NavigateToParentPage();
        }
コード例 #8
0
        /// <summary>
        /// Handles the Click event of the btnSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        /// <exception cref="System.NotImplementedException"></exception>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            FinancialPledge pledge;
            var             rockContext   = new RockContext();
            var             pledgeService = new FinancialPledgeService(rockContext);
            var             pledgeId      = hfPledgeId.Value.AsInteger();

            if (pledgeId == 0)
            {
                pledge = new FinancialPledge();
                pledgeService.Add(pledge);
            }
            else
            {
                pledge = pledgeService.Get(pledgeId);
            }

            if (ppPerson.PersonId.HasValue)
            {
                pledge.PersonAliasId = ppPerson.PersonAliasId;
            }

            pledge.AccountId   = apAccount.SelectedValue.AsIntegerOrNull();
            pledge.TotalAmount = tbAmount.Text.AsDecimal();

            pledge.StartDate = dpDateRange.LowerValue.HasValue ? dpDateRange.LowerValue.Value : DateTime.MinValue;
            pledge.EndDate   = dpDateRange.UpperValue.HasValue ? dpDateRange.UpperValue.Value : DateTime.MaxValue;

            pledge.PledgeFrequencyValueId = ddlFrequencyType.SelectedValue.AsIntegerOrNull();

            if (!pledge.IsValid)
            {
                // Controls will render the error messages
                return;
            }

            rockContext.SaveChanges();

            NavigateToParentPage();
        }
コード例 #9
0
ファイル: CreatePledge.ascx.cs プロジェクト: shelsonjava/Rock
        /// <summary>
        /// Handles the Click event of the btnSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        /// <exception cref="System.NotImplementedException"></exception>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            using (new UnitOfWorkScope())
            {
                RockTransactionScope.WrapTransaction(() =>
                {
                    var pledgeService = new FinancialPledgeService();
                    var person        = FindPerson();
                    var pledges       = GetPledges(person).ToList();

                    // Does this person already have a pledge for these accounts?
                    // If so, give them the option to create a new one?
                    var personPledgeAccountIds = pledgeService.Queryable()
                                                 .Where(p => p.PersonId == person.Id)
                                                 .Select(p => p.AccountId)
                                                 .ToList();

                    if (Accounts.Any(a => personPledgeAccountIds.Contains(a.Id)))
                    {
                        pnlConfirm.Visible = true;
                        Session.Add("CachedPledges", pledges);
                        return;
                    }

                    foreach (var pledge in pledges)
                    {
                        if (!pledge.IsValid)
                        {
                            continue;
                        }

                        pledgeService.Add(pledge, person.Id);
                        pledgeService.Save(pledge, person.Id);
                    }

                    ShowReceipt(pledges.Select(p => p.Id));
                });
            }
        }
コード例 #10
0
        /// <summary>
        /// Handles the Click event of the btnSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        /// <exception cref="System.NotImplementedException"></exception>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            var rockContext             = new RockContext();
            var financialPledgeService  = new FinancialPledgeService(rockContext);
            var financialAccountService = new FinancialAccountService(rockContext);
            var definedValueService     = new DefinedValueService(rockContext);
            var person = FindPerson(rockContext);

            FinancialPledge financialPledge = new FinancialPledge();

            financialPledge.PersonAliasId = person.PrimaryAliasId;
            financialPledge.GroupId       = ddlGroup.SelectedValueAsInt();

            var financialAccount = financialAccountService.Get(GetAttributeValue("Account").AsGuid());

            if (financialAccount != null)
            {
                financialPledge.AccountId = financialAccount.Id;
            }

            financialPledge.TotalAmount = tbTotalAmount.Value ?? 0.0m;

            var pledgeFrequencySelection = DefinedValueCache.Get(ddlFrequency.SelectedValue.AsInteger());

            if (pledgeFrequencySelection != null)
            {
                financialPledge.PledgeFrequencyValueId = pledgeFrequencySelection.Id;
            }

            financialPledge.StartDate = drpDateRange.LowerValue ?? DateTime.MinValue;
            financialPledge.EndDate   = drpDateRange.UpperValue ?? DateTime.MaxValue;

            if (sender != btnConfirm)
            {
                var duplicatePledges = financialPledgeService.Queryable()
                                       .Where(a => a.PersonAlias.PersonId == person.Id)
                                       .Where(a => a.AccountId == financialPledge.AccountId)
                                       .Where(a => a.StartDate == financialPledge.StartDate)
                                       .Where(a => a.EndDate == financialPledge.EndDate).ToList();

                if (duplicatePledges.Any())
                {
                    pnlAddPledge.Visible           = false;
                    pnlConfirm.Visible             = true;
                    nbDuplicatePledgeWarning.Text  = "The following pledges have already been entered for you:";
                    nbDuplicatePledgeWarning.Text += "<ul>";
                    foreach (var pledge in duplicatePledges.OrderBy(a => a.StartDate).ThenBy(a => a.Account.Name))
                    {
                        nbDuplicatePledgeWarning.Text += string.Format("<li>{0} {1} {2}</li>", pledge.Account, pledge.PledgeFrequencyValue, pledge.TotalAmount);
                    }

                    nbDuplicatePledgeWarning.Text += "</ul>";

                    return;
                }
            }

            if (financialPledge.IsValid)
            {
                financialPledgeService.Add(financialPledge);

                rockContext.SaveChanges();

                // populate account so that Liquid can access it
                financialPledge.Account = financialAccount;

                // populate PledgeFrequencyValue so that Liquid can access it
                financialPledge.PledgeFrequencyValue = definedValueService.Get(financialPledge.PledgeFrequencyValueId ?? 0);

                var mergeFields = Rock.Lava.LavaHelper.GetCommonMergeFields(this.RockPage, this.CurrentPerson);
                mergeFields.Add("Person", person);
                mergeFields.Add("FinancialPledge", financialPledge);
                mergeFields.Add("PledgeFrequency", pledgeFrequencySelection);
                mergeFields.Add("Account", financialAccount);
                lReceipt.Text = GetAttributeValue("ReceiptText").ResolveMergeFields(mergeFields);

                // Resolve any dynamic url references
                string appRoot   = ResolveRockUrl("~/");
                string themeRoot = ResolveRockUrl("~~/");
                lReceipt.Text = lReceipt.Text.Replace("~~/", themeRoot).Replace("~/", appRoot);

                lReceipt.Visible     = true;
                pnlAddPledge.Visible = false;
                pnlConfirm.Visible   = false;

                // if a ConfirmationEmailTemplate is configured, send an email
                var confirmationEmailTemplateGuid = GetAttributeValue("ConfirmationEmailTemplate").AsGuidOrNull();
                if (confirmationEmailTemplateGuid.HasValue)
                {
                    var emailMessage = new RockEmailMessage(confirmationEmailTemplateGuid.Value);
                    emailMessage.AddRecipient(new RockEmailMessageRecipient(person, mergeFields));
                    emailMessage.AppRoot   = ResolveRockUrl("~/");
                    emailMessage.ThemeRoot = ResolveRockUrl("~~/");
                    emailMessage.Send();
                }
            }
            else
            {
                ShowInvalidResults(financialPledge.ValidationResults);
            }
        }
コード例 #11
0
        /// <summary>
        /// Handles the Click event of the btnSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        /// <exception cref="System.NotImplementedException"></exception>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            var rockContext             = new RockContext();
            var financialPledgeService  = new FinancialPledgeService(rockContext);
            var financialAccountService = new FinancialAccountService(rockContext);
            var definedValueService     = new DefinedValueService(rockContext);
            var person = FindPerson(rockContext);

            FinancialPledge financialPledge = new FinancialPledge();

            financialPledge.PersonAliasId = person.PrimaryAliasId;
            var financialAccount = financialAccountService.Get(GetAttributeValue("Account").AsGuid());

            if (financialAccount != null)
            {
                financialPledge.AccountId = financialAccount.Id;
            }

            financialPledge.TotalAmount = tbTotalAmount.Text.AsDecimal();

            var pledgeFrequencySelection = DefinedValueCache.Read(bddlFrequency.SelectedValue.AsInteger());

            if (pledgeFrequencySelection != null)
            {
                financialPledge.PledgeFrequencyValueId = pledgeFrequencySelection.Id;
            }

            financialPledge.StartDate = drpDateRange.LowerValue ?? DateTime.MinValue;
            financialPledge.EndDate   = drpDateRange.UpperValue ?? DateTime.MaxValue;

            if (sender != btnConfirm)
            {
                var duplicatePledges = financialPledgeService.Queryable()
                                       .Where(a => a.PersonAlias.PersonId == person.Id)
                                       .Where(a => a.AccountId == financialPledge.AccountId)
                                       .Where(a => a.StartDate == financialPledge.StartDate)
                                       .Where(a => a.EndDate == financialPledge.EndDate).ToList();

                if (duplicatePledges.Any())
                {
                    pnlAddPledge.Visible           = false;
                    pnlConfirm.Visible             = true;
                    nbDuplicatePledgeWarning.Text  = "The following pledges have already been entered for you:";
                    nbDuplicatePledgeWarning.Text += "<ul>";
                    foreach (var pledge in duplicatePledges.OrderBy(a => a.StartDate).ThenBy(a => a.Account.Name))
                    {
                        nbDuplicatePledgeWarning.Text += string.Format("<li>{0} {1} {2}</li>", pledge.Account, pledge.PledgeFrequencyValue, pledge.TotalAmount);
                    }

                    nbDuplicatePledgeWarning.Text += "</ul>";

                    return;
                }
            }

            financialPledgeService.Add(financialPledge);

            rockContext.SaveChanges();

            // populate account so that Liquid can access it
            financialPledge.Account = financialAccount;

            // populate PledgeFrequencyValue so that Liquid can access it
            financialPledge.PledgeFrequencyValue = definedValueService.Get(financialPledge.PledgeFrequencyValueId ?? 0);

            var mergeObjects = Rock.Web.Cache.GlobalAttributesCache.GetMergeFields(this.CurrentPerson);

            mergeObjects.Add("Person", person);
            mergeObjects.Add("FinancialPledge", financialPledge);
            mergeObjects.Add("PledgeFrequency", pledgeFrequencySelection);
            mergeObjects.Add("Account", financialAccount);
            lReceipt.Text = GetAttributeValue("ReceiptText").ResolveMergeFields(mergeObjects);

            // Resolve any dynamic url references
            string appRoot   = ResolveRockUrl("~/");
            string themeRoot = ResolveRockUrl("~~/");

            lReceipt.Text = lReceipt.Text.Replace("~~/", themeRoot).Replace("~/", appRoot);

            // show liquid help for debug
            if (GetAttributeValue("EnableDebug").AsBoolean() && IsUserAuthorized(Authorization.EDIT))
            {
                lReceipt.Text += mergeObjects.lavaDebugInfo();
            }

            lReceipt.Visible     = true;
            pnlAddPledge.Visible = false;
            pnlConfirm.Visible   = false;

            // if a ConfirmationEmailTemplate is configured, send an email
            var confirmationEmailTemplateGuid = GetAttributeValue("ConfirmationEmailTemplate").AsGuidOrNull();

            if (confirmationEmailTemplateGuid.HasValue)
            {
                var recipients = new List <Rock.Communication.RecipientData>();

                // add person and the mergeObjects (same mergeobjects as receipt)
                recipients.Add(new Rock.Communication.RecipientData(person.Email, mergeObjects));

                Rock.Communication.Email.Send(confirmationEmailTemplateGuid.Value, recipients, ResolveRockUrl("~/"), ResolveRockUrl("~~/"));
            }
        }