Ejemplo n.º 1
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();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Handles the Delete event of the gPledges control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RowEventArgs"/> instance containing the event data.</param>
        protected void gPledges_Delete(object sender, RowEventArgs e)
        {
            RockTransactionScope.WrapTransaction(() =>
            {
                var pledgeService = new FinancialPledgeService();
                var pledge        = pledgeService.Get((int)e.RowKeyValue);
                string errorMessage;

                if (pledge == null)
                {
                    return;
                }

                if (!pledgeService.CanDelete(pledge, out errorMessage))
                {
                    mdGridWarning.Show(errorMessage, ModalAlertType.Information);
                    return;
                }

                pledgeService.Delete(pledge, CurrentPersonId);
                pledgeService.Save(pledge, CurrentPersonId);
            });

            BindGrid();
        }
        /// <summary>
        /// Event when the user clicks to delete the pledge
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void rptPledges_Delete(object sender, CommandEventArgs e)
        {
            var pledgeGuid    = e.CommandArgument.ToStringSafe().AsGuid();
            var rockContext   = new RockContext();
            var pledgeService = new FinancialPledgeService(rockContext);
            var pledge        = pledgeService.Get(pledgeGuid);

            string errorMessage;

            if (pledge == null)
            {
                return;
            }

            if (!pledgeService.CanDelete(pledge, out errorMessage))
            {
                mdWarningAlert.Show(errorMessage, ModalAlertType.Information);
                return;
            }

            pledgeService.Delete(pledge);
            rockContext.SaveChanges();

            ShowDetail();
        }
        /// <summary>
        /// Event when the user clicks to edit the pledge
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void rptPledges_Edit(object sender, CommandEventArgs e)
        {
            var pledgeGuid    = e.CommandArgument.ToStringSafe().AsGuid();
            var rockContext   = new RockContext();
            var pledgeService = new FinancialPledgeService(rockContext);
            var pledge        = pledgeService.Get(pledgeGuid);

            if (pledge != null)
            {
                var queryParams = new Dictionary <string, string>();
                queryParams.AddOrReplace(PageParameterKey.PledgeId, pledge.Id.ToString());
                queryParams.AddOrReplace(PageParameterKey.PersonActionIdentifier, Person.GetPersonActionIdentifier("pledge"));
                NavigateToLinkedPage(AttributeKey.PledgeDetailPage, queryParams);
            }
        }
Ejemplo n.º 5
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);
            }

            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();
        }
        /// <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();
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Handles the Delete event of the gPledges control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RowEventArgs"/> instance containing the event data.</param>
        protected void gPledges_Delete(object sender, RowEventArgs e)
        {
            var    rockContext   = new RockContext();
            var    pledgeService = new FinancialPledgeService(rockContext);
            var    pledge        = pledgeService.Get(e.RowKeyId);
            string errorMessage;

            if (pledge == null)
            {
                return;
            }

            if (!pledgeService.CanDelete(pledge, out errorMessage))
            {
                mdGridWarning.Show(errorMessage, ModalAlertType.Information);
                return;
            }

            pledgeService.Delete(pledge);
            rockContext.SaveChanges();

            BindGrid();
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Handles the Click event of the lbSave 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 lbSave_Click(object sender, EventArgs e)
        {
            var rockContext = new RockContext();

            rockContext.WrapTransaction(() =>
            {
                if (contextEntity is Person)
                {
                    var personService = new PersonService(rockContext);
                    var changes       = new History.HistoryChangeList();
                    var _person       = personService.Get(contextEntity.Id);

                    History.EvaluateChange(changes, "Foreign Key", _person.ForeignKey, tbForeignKey.Text);
                    _person.ForeignKey = tbForeignKey.Text;

                    History.EvaluateChange(changes, "Foreign Guid", _person.ForeignGuid.ToString(), tbForeignGuid.Text);
                    _person.ForeignGuid = tbForeignGuid.Text.AsType <Guid?>();

                    History.EvaluateChange(changes, "Foreign Id", _person.ForeignId.ToString(), tbForeignId.Text);
                    _person.ForeignId = tbForeignId.Text.AsType <int?>();

                    if (rockContext.SaveChanges() > 0)
                    {
                        if (changes.Any())
                        {
                            HistoryService.SaveChanges(
                                rockContext,
                                typeof(Person),
                                Rock.SystemGuid.Category.HISTORY_PERSON_DEMOGRAPHIC_CHANGES.AsGuid(),
                                _person.Id,
                                changes);
                        }
                    }
                }
                else if (contextEntity is FinancialAccount)
                {
                    var accountService = new FinancialAccountService(rockContext);
                    var _account       = accountService.Get(contextEntity.Id);

                    _account.ForeignKey  = tbForeignKey.Text;
                    _account.ForeignGuid = tbForeignGuid.Text.AsType <Guid?>();
                    _account.ForeignId   = tbForeignId.Text.AsType <int?>();

                    rockContext.SaveChanges();
                }
                else if (contextEntity is FinancialBatch)
                {
                    var batchService = new FinancialBatchService(rockContext);
                    var changes      = new History.HistoryChangeList();
                    var _batch       = batchService.Get(contextEntity.Id);

                    History.EvaluateChange(changes, "Foreign Key", _batch.ForeignKey, tbForeignKey.Text);
                    _batch.ForeignKey = tbForeignKey.Text;

                    History.EvaluateChange(changes, "Foreign Guid", _batch.ForeignGuid.ToString(), tbForeignGuid.Text);
                    _batch.ForeignGuid = tbForeignGuid.Text.AsType <Guid?>();

                    History.EvaluateChange(changes, "Foreign Id", _batch.ForeignId.ToString(), tbForeignId.Text);
                    _batch.ForeignId = tbForeignId.Text.AsType <int?>();

                    if (rockContext.SaveChanges() > 0)
                    {
                        if (changes.Any())
                        {
                            HistoryService.SaveChanges(
                                rockContext,
                                typeof(FinancialBatch),
                                Rock.SystemGuid.Category.HISTORY_FINANCIAL_BATCH.AsGuid(),
                                _batch.Id,
                                changes);
                        }
                    }
                }
                else if (contextEntity is FinancialPledge)
                {
                    var pledgeService = new FinancialPledgeService(rockContext);
                    var _pledge       = pledgeService.Get(contextEntity.Id);

                    _pledge.ForeignKey  = tbForeignKey.Text;
                    _pledge.ForeignGuid = tbForeignGuid.Text.AsType <Guid?>();
                    _pledge.ForeignId   = tbForeignId.Text.AsType <int?>();

                    rockContext.SaveChanges();
                }
                else if (contextEntity is FinancialTransaction)
                {
                    var transactionService = new FinancialTransactionService(rockContext);
                    var changes            = new History.HistoryChangeList();
                    var _transaction       = transactionService.Get(contextEntity.Id);

                    History.EvaluateChange(changes, "Foreign Key", _transaction.ForeignKey, tbForeignKey.Text);
                    _transaction.ForeignKey = tbForeignKey.Text;

                    History.EvaluateChange(changes, "Foreign Guid", _transaction.ForeignGuid.ToString(), tbForeignGuid.Text);
                    _transaction.ForeignGuid = tbForeignGuid.Text.AsType <Guid?>();

                    History.EvaluateChange(changes, "Foreign Id", _transaction.ForeignId.ToString(), tbForeignId.Text);
                    _transaction.ForeignId = tbForeignId.Text.AsType <int?>();

                    if (rockContext.SaveChanges() > 0)
                    {
                        if (changes.Any())
                        {
                            HistoryService.SaveChanges(
                                rockContext,
                                typeof(FinancialTransaction),
                                Rock.SystemGuid.Category.HISTORY_FINANCIAL_TRANSACTION.AsGuid(),
                                _transaction.Id,
                                changes);
                        }
                    }
                }
                else if (contextEntity is FinancialScheduledTransaction)
                {
                    var transactionScheduledService = new FinancialScheduledTransactionService(rockContext);
                    var _scheduledTransaction       = transactionScheduledService.Get(contextEntity.Id);

                    _scheduledTransaction.ForeignKey  = tbForeignKey.Text;
                    _scheduledTransaction.ForeignGuid = tbForeignGuid.Text.AsType <Guid?>();
                    _scheduledTransaction.ForeignId   = tbForeignId.Text.AsType <int?>();

                    rockContext.SaveChanges();
                }
                else if (contextEntity is Group)
                {
                    var groupService = new GroupService(rockContext);
                    var _group       = groupService.Get(contextEntity.Id);

                    _group.ForeignKey  = tbForeignKey.Text;
                    _group.ForeignGuid = tbForeignGuid.Text.AsType <Guid?>();
                    _group.ForeignId   = tbForeignId.Text.AsType <int?>();

                    rockContext.SaveChanges();
                }
                else if (contextEntity is GroupMember)
                {
                    var groupMemberService = new GroupMemberService(rockContext);
                    var changes            = new History.HistoryChangeList();
                    var _groupMember       = groupMemberService.Get(contextEntity.Id);

                    History.EvaluateChange(changes, "Foreign Key", _groupMember.ForeignKey, tbForeignKey.Text);
                    _groupMember.ForeignKey = tbForeignKey.Text;

                    History.EvaluateChange(changes, "Foreign Guid", _groupMember.ForeignGuid.ToString(), tbForeignGuid.Text);
                    _groupMember.ForeignGuid = tbForeignGuid.Text.AsType <Guid?>();

                    History.EvaluateChange(changes, "Foreign Id", _groupMember.ForeignId.ToString(), tbForeignId.Text);
                    _groupMember.ForeignId = tbForeignId.Text.AsType <int?>();

                    if (rockContext.SaveChanges() > 0)
                    {
                        if (changes.Any())
                        {
                            HistoryService.SaveChanges(
                                rockContext,
                                typeof(GroupMember),
                                Rock.SystemGuid.Category.HISTORY_PERSON_GROUP_MEMBERSHIP.AsGuid(),
                                _groupMember.Id,
                                changes);
                        }
                    }
                }
                else if (contextEntity is Metric)
                {
                    var metricService = new MetricService(rockContext);
                    var _metric       = metricService.Get(contextEntity.Id);

                    _metric.ForeignKey  = tbForeignKey.Text;
                    _metric.ForeignGuid = tbForeignGuid.Text.AsType <Guid?>();
                    _metric.ForeignId   = tbForeignId.Text.AsType <int?>();

                    rockContext.SaveChanges();
                }
                else if (contextEntity is Location)
                {
                    var locationService = new LocationService(rockContext);
                    var _location       = locationService.Get(contextEntity.Id);

                    _location.ForeignKey  = tbForeignKey.Text;
                    _location.ForeignGuid = tbForeignGuid.Text.AsType <Guid?>();
                    _location.ForeignId   = tbForeignId.Text.AsType <int?>();

                    rockContext.SaveChanges();
                }
                else if (contextEntity is PrayerRequest)
                {
                    var prayerRequestService = new PrayerRequestService(rockContext);
                    var _request             = prayerRequestService.Get(contextEntity.Id);

                    _request.ForeignKey  = tbForeignKey.Text;
                    _request.ForeignGuid = tbForeignGuid.Text.AsType <Guid?>();
                    _request.ForeignId   = tbForeignId.Text.AsType <int?>();

                    rockContext.SaveChanges();
                }
                else if (contextEntity is ContentChannel)
                {
                    var contentChannelService = new ContentChannelService(rockContext);
                    var _channel = contentChannelService.Get(contextEntity.Id);

                    _channel.ForeignKey  = tbForeignKey.Text;
                    _channel.ForeignGuid = tbForeignGuid.Text.AsType <Guid?>();
                    _channel.ForeignId   = tbForeignId.Text.AsType <int?>();

                    rockContext.SaveChanges();
                }
                else if (contextEntity is ContentChannelItem)
                {
                    var contentChannelItemService = new ContentChannelItemService(rockContext);
                    var _item = contentChannelItemService.Get(contextEntity.Id);

                    _item.ForeignKey  = tbForeignKey.Text;
                    _item.ForeignGuid = tbForeignGuid.Text.AsType <Guid?>();
                    _item.ForeignId   = tbForeignId.Text.AsType <int?>();

                    rockContext.SaveChanges();
                }
            });

            Page.Response.Redirect(Page.Request.Url.ToString(), true);
        }