/// <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 )
        {
            if ( Page.IsValid )
            {
                RockContext rockContext = new RockContext();
                BenevolenceRequestService benevolenceRequestService = new BenevolenceRequestService( rockContext );
                BenevolenceResultService benevolenceResultService = new BenevolenceResultService( rockContext );

                BenevolenceRequest benevolenceRequest = null;
                int benevolenceRequestId = PageParameter( "BenevolenceRequestId" ).AsInteger();

                if ( !benevolenceRequestId.Equals( 0 ) )
                {
                    benevolenceRequest = benevolenceRequestService.Get( benevolenceRequestId );
                }

                if ( benevolenceRequest == null )
                {
                    benevolenceRequest = new BenevolenceRequest { Id = 0 };
                }

                benevolenceRequest.FirstName = dtbFirstName.Text;
                benevolenceRequest.LastName = dtbLastName.Text;
                benevolenceRequest.Email = ebEmail.Text;
                benevolenceRequest.RequestText = dtbRequestText.Text;
                benevolenceRequest.ResultSummary = dtbSummary.Text;
                benevolenceRequest.GovernmentId = dtbGovernmentId.Text;

                if ( lapAddress.Location != null )
                {
                    benevolenceRequest.LocationId = lapAddress.Location.Id;
                }

                benevolenceRequest.RequestedByPersonAliasId = ppPerson.PersonAliasId;
                benevolenceRequest.CaseWorkerPersonAliasId = ddlCaseWorker.SelectedItem.Value.AsIntegerOrNull();
                benevolenceRequest.RequestStatusValueId = ddlRequestStatus.SelectedItem.Value.AsIntegerOrNull();
                benevolenceRequest.ConnectionStatusValueId = ddlConnectionStatus.SelectedItem.Value.AsIntegerOrNull();

                if ( dpRequestDate.SelectedDate.HasValue )
                {
                    benevolenceRequest.RequestDateTime = dpRequestDate.SelectedDate.Value;
                }

                benevolenceRequest.HomePhoneNumber = pnbHomePhone.Number;
                benevolenceRequest.CellPhoneNumber = pnbCellPhone.Number;
                benevolenceRequest.WorkPhoneNumber = pnbWorkPhone.Number;

                List<BenevolenceResultInfo> resultList = BenevolenceResultsState;
                BenevolenceResult benevolenceResult = null;

                foreach ( BenevolenceResult result in benevolenceRequest.BenevolenceResults.ToList() )
                {
                    if ( resultList.FirstOrDefault( r => r.ResultId == result.Id ) == null )
                    {
                        benevolenceRequest.BenevolenceResults.Remove( result );
                        benevolenceResultService.Delete( result );
                    }
                }

                foreach ( BenevolenceResultInfo benevolenceResultInfo in resultList )
                {
                    if ( benevolenceResultInfo.ResultId == null )
                    {
                        benevolenceResult = new BenevolenceResult();
                        benevolenceResult.Amount = benevolenceResultInfo.Amount;
                        benevolenceResult.ResultSummary = benevolenceResultInfo.ResultSummary;
                        benevolenceResult.ResultTypeValueId = benevolenceResultInfo.ResultTypeValueId;
                        benevolenceResult.BenevolenceRequestId = benevolenceRequest.Id;
                        benevolenceRequest.BenevolenceResults.Add( benevolenceResult );
                    }
                }

                if ( benevolenceRequest.IsValid )
                {
                    if ( benevolenceRequest.Id.Equals( 0 ) )
                    {
                        benevolenceRequestService.Add( benevolenceRequest );
                    }

                    rockContext.SaveChanges();
                    NavigateToParentPage();
                }
            }
        }
        /// <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 )
        {
            if ( Page.IsValid )
            {
                RockContext rockContext = new RockContext();
                BenevolenceRequestService benevolenceRequestService = new BenevolenceRequestService( rockContext );
                BenevolenceResultService benevolenceResultService = new BenevolenceResultService( rockContext );

                BenevolenceRequest benevolenceRequest = null;
                int benevolenceRequestId = PageParameter( "BenevolenceRequestId" ).AsInteger();

                if ( !benevolenceRequestId.Equals( 0 ) )
                {
                    benevolenceRequest = benevolenceRequestService.Get( benevolenceRequestId );
                }

                if ( benevolenceRequest == null )
                {
                    benevolenceRequest = new BenevolenceRequest { Id = 0 };
                }

                benevolenceRequest.FirstName = dtbFirstName.Text;
                benevolenceRequest.LastName = dtbLastName.Text;
                benevolenceRequest.Email = ebEmail.Text;
                benevolenceRequest.RequestText = dtbRequestText.Text;
                benevolenceRequest.ResultSummary = dtbSummary.Text;
                benevolenceRequest.CampusId = cpCampus.SelectedCampusId;
                benevolenceRequest.ProvidedNextSteps = dtbProvidedNextSteps.Text;
                benevolenceRequest.GovernmentId = dtbGovernmentId.Text;

                if ( lapAddress.Location != null )
                {
                    benevolenceRequest.LocationId = lapAddress.Location.Id;
                }

                benevolenceRequest.RequestedByPersonAliasId = ppPerson.PersonAliasId;
                benevolenceRequest.CaseWorkerPersonAliasId = ddlCaseWorker.SelectedValue.AsIntegerOrNull();
                benevolenceRequest.RequestStatusValueId = ddlRequestStatus.SelectedValue.AsIntegerOrNull();
                benevolenceRequest.ConnectionStatusValueId = ddlConnectionStatus.SelectedValue.AsIntegerOrNull();

                if ( dpRequestDate.SelectedDate.HasValue )
                {
                    benevolenceRequest.RequestDateTime = dpRequestDate.SelectedDate.Value;
                }

                benevolenceRequest.HomePhoneNumber = pnbHomePhone.Number;
                benevolenceRequest.CellPhoneNumber = pnbCellPhone.Number;
                benevolenceRequest.WorkPhoneNumber = pnbWorkPhone.Number;

                List<BenevolenceResultInfo> resultListUI = BenevolenceResultsState;
                var resultListDB = benevolenceRequest.BenevolenceResults.ToList();

                // remove any Benevolence Results that were removed in the UI
                foreach ( BenevolenceResult resultDB in resultListDB )
                {
                    if ( !resultListUI.Any( r => r.ResultId == resultDB.Id ) )
                    {
                        benevolenceRequest.BenevolenceResults.Remove( resultDB );
                        benevolenceResultService.Delete( resultDB );
                    }
                }

                // add any Benevolence Results that were added in the UI
                foreach ( BenevolenceResultInfo resultUI in resultListUI )
                {
                    var resultDB = resultListDB.FirstOrDefault( r => r.Guid == resultUI.TempGuid );
                    if ( resultDB == null )
                    {
                        resultDB = new BenevolenceResult();
                        resultDB.BenevolenceRequestId = benevolenceRequest.Id;
                        resultDB.Guid = resultUI.TempGuid;
                        benevolenceRequest.BenevolenceResults.Add( resultDB );
                    }

                    resultDB.Amount = resultUI.Amount;
                    resultDB.ResultSummary = resultUI.ResultSummary;
                    resultDB.ResultTypeValueId = resultUI.ResultTypeValueId;
                }

                if ( benevolenceRequest.IsValid )
                {
                    if ( benevolenceRequest.Id.Equals( 0 ) )
                    {
                        benevolenceRequestService.Add( benevolenceRequest );
                    }

                    // get attributes
                    benevolenceRequest.LoadAttributes();
                    Rock.Attribute.Helper.GetEditValues( phAttributes, benevolenceRequest );

                    rockContext.WrapTransaction( () =>
                    {
                        rockContext.SaveChanges();
                        benevolenceRequest.SaveAttributeValues( rockContext );
                    } );

                    // update related documents
                    var documentsService = new BenevolenceRequestDocumentService( rockContext );

                    // delete any images that were removed
                    var orphanedBinaryFileIds = new List<int>();
                    var documentsInDb = documentsService.Queryable().Where( b => b.BenevolenceRequestId == benevolenceRequest.Id ).ToList();

                    foreach ( var document in documentsInDb.Where( i => !DocumentsState.Contains( i.BinaryFileId ) ) )
                    {
                        orphanedBinaryFileIds.Add( document.BinaryFileId );
                        documentsService.Delete( document );
                    }

                    // save documents
                    int documentOrder = 0;
                    foreach ( var binaryFileId in DocumentsState )
                    {
                        // Add or Update the activity type
                        var document = documentsInDb.FirstOrDefault( i => i.BinaryFileId == binaryFileId );
                        if ( document == null )
                        {
                            document = new BenevolenceRequestDocument();
                            document.BenevolenceRequestId = benevolenceRequest.Id;
                            benevolenceRequest.Documents.Add( document );
                        }
                        document.BinaryFileId = binaryFileId;
                        document.Order = documentOrder;
                        documentOrder++;
                    }
                    rockContext.SaveChanges();

                    // redirect back to parent
                    var personId = this.PageParameter( "PersonId" ).AsIntegerOrNull();
                    var qryParams = new Dictionary<string, string>();
                    if ( personId.HasValue )
                    {
                        qryParams.Add( "PersonId", personId.ToString() );
                    }

                    NavigateToParentPage( qryParams );
                }
            }
        }
예제 #3
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)
        {
            if (Page.IsValid)
            {
                RockContext rockContext = new RockContext();
                BenevolenceRequestService benevolenceRequestService = new BenevolenceRequestService(rockContext);
                BenevolenceResultService  benevolenceResultService  = new BenevolenceResultService(rockContext);

                BenevolenceRequest benevolenceRequest = null;
                int benevolenceRequestId = PageParameter("BenevolenceRequestId").AsInteger();

                if (!benevolenceRequestId.Equals(0))
                {
                    benevolenceRequest = benevolenceRequestService.Get(benevolenceRequestId);
                }

                if (benevolenceRequest == null)
                {
                    benevolenceRequest = new BenevolenceRequest {
                        Id = 0
                    };
                }

                benevolenceRequest.FirstName         = dtbFirstName.Text;
                benevolenceRequest.LastName          = dtbLastName.Text;
                benevolenceRequest.Email             = ebEmail.Text;
                benevolenceRequest.RequestText       = dtbRequestText.Text;
                benevolenceRequest.ResultSummary     = dtbSummary.Text;
                benevolenceRequest.CampusId          = cpCampus.SelectedCampusId;
                benevolenceRequest.ProvidedNextSteps = dtbProvidedNextSteps.Text;
                benevolenceRequest.GovernmentId      = dtbGovernmentId.Text;

                if (lapAddress.Location != null)
                {
                    benevolenceRequest.LocationId = lapAddress.Location.Id;
                }

                benevolenceRequest.RequestedByPersonAliasId = ppPerson.PersonAliasId;
                benevolenceRequest.CaseWorkerPersonAliasId  = ddlCaseWorker.SelectedValue.AsIntegerOrNull();
                benevolenceRequest.RequestStatusValueId     = ddlRequestStatus.SelectedValue.AsIntegerOrNull();
                benevolenceRequest.ConnectionStatusValueId  = ddlConnectionStatus.SelectedValue.AsIntegerOrNull();

                if (dpRequestDate.SelectedDate.HasValue)
                {
                    benevolenceRequest.RequestDateTime = dpRequestDate.SelectedDate.Value;
                }

                benevolenceRequest.HomePhoneNumber = pnbHomePhone.Number;
                benevolenceRequest.CellPhoneNumber = pnbCellPhone.Number;
                benevolenceRequest.WorkPhoneNumber = pnbWorkPhone.Number;

                List <BenevolenceResultInfo> resultListUI = BenevolenceResultsState;
                var resultListDB = benevolenceRequest.BenevolenceResults.ToList();

                // remove any Benevolence Results that were removed in the UI
                foreach (BenevolenceResult resultDB in resultListDB)
                {
                    if (!resultListUI.Any(r => r.ResultId == resultDB.Id))
                    {
                        benevolenceRequest.BenevolenceResults.Remove(resultDB);
                        benevolenceResultService.Delete(resultDB);
                    }
                }

                // add any Benevolence Results that were added in the UI
                foreach (BenevolenceResultInfo resultUI in resultListUI)
                {
                    var resultDB = resultListDB.FirstOrDefault(r => r.Guid == resultUI.TempGuid);
                    if (resultDB == null)
                    {
                        resultDB = new BenevolenceResult();
                        resultDB.BenevolenceRequestId = benevolenceRequest.Id;
                        resultDB.Guid = resultUI.TempGuid;
                        benevolenceRequest.BenevolenceResults.Add(resultDB);
                    }

                    resultDB.Amount            = resultUI.Amount;
                    resultDB.ResultSummary     = resultUI.ResultSummary;
                    resultDB.ResultTypeValueId = resultUI.ResultTypeValueId;
                }

                if (benevolenceRequest.IsValid)
                {
                    if (benevolenceRequest.Id.Equals(0))
                    {
                        benevolenceRequestService.Add(benevolenceRequest);
                    }

                    // get attributes
                    benevolenceRequest.LoadAttributes();
                    Rock.Attribute.Helper.GetEditValues(phAttributes, benevolenceRequest);

                    rockContext.WrapTransaction(() =>
                    {
                        rockContext.SaveChanges();
                        benevolenceRequest.SaveAttributeValues(rockContext);
                    });

                    // update related documents
                    var documentsService = new BenevolenceRequestDocumentService(rockContext);

                    // delete any images that were removed
                    var orphanedBinaryFileIds = new List <int>();
                    var documentsInDb         = documentsService.Queryable().Where(b => b.BenevolenceRequestId == benevolenceRequest.Id).ToList();

                    foreach (var document in documentsInDb.Where(i => !DocumentsState.Contains(i.BinaryFileId)))
                    {
                        orphanedBinaryFileIds.Add(document.BinaryFileId);
                        documentsService.Delete(document);
                    }

                    // save documents
                    int documentOrder = 0;
                    foreach (var binaryFileId in DocumentsState)
                    {
                        // Add or Update the activity type
                        var document = documentsInDb.FirstOrDefault(i => i.BinaryFileId == binaryFileId);
                        if (document == null)
                        {
                            document = new BenevolenceRequestDocument();
                            document.BenevolenceRequestId = benevolenceRequest.Id;
                            benevolenceRequest.Documents.Add(document);
                        }
                        document.BinaryFileId = binaryFileId;
                        document.Order        = documentOrder;
                        documentOrder++;
                    }
                    rockContext.SaveChanges();

                    // redirect back to parent
                    var personId  = this.PageParameter("PersonId").AsIntegerOrNull();
                    var qryParams = new Dictionary <string, string>();
                    if (personId.HasValue)
                    {
                        qryParams.Add("PersonId", personId.ToString());
                    }

                    NavigateToParentPage(qryParams);
                }
            }
        }
예제 #4
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)
        {
            if (Page.IsValid)
            {
                RockContext rockContext = new RockContext();
                BenevolenceRequestService benevolenceRequestService = new BenevolenceRequestService(rockContext);
                BenevolenceResultService  benevolenceResultService  = new BenevolenceResultService(rockContext);

                BenevolenceRequest benevolenceRequest = null;
                int benevolenceRequestId = PageParameter("BenevolenceRequestId").AsInteger();

                if (!benevolenceRequestId.Equals(0))
                {
                    benevolenceRequest = benevolenceRequestService.Get(benevolenceRequestId);
                }

                if (benevolenceRequest == null)
                {
                    benevolenceRequest = new BenevolenceRequest {
                        Id = 0
                    };
                }

                benevolenceRequest.FirstName     = dtbFirstName.Text;
                benevolenceRequest.LastName      = dtbLastName.Text;
                benevolenceRequest.Email         = ebEmail.Text;
                benevolenceRequest.RequestText   = dtbRequestText.Text;
                benevolenceRequest.ResultSummary = dtbSummary.Text;
                benevolenceRequest.GovernmentId  = dtbGovernmentId.Text;

                if (lapAddress.Location != null)
                {
                    benevolenceRequest.LocationId = lapAddress.Location.Id;
                }

                benevolenceRequest.RequestedByPersonAliasId = ppPerson.PersonAliasId;
                benevolenceRequest.CaseWorkerPersonAliasId  = ddlCaseWorker.SelectedItem.Value.AsIntegerOrNull();
                benevolenceRequest.RequestStatusValueId     = ddlRequestStatus.SelectedItem.Value.AsIntegerOrNull();
                benevolenceRequest.ConnectionStatusValueId  = ddlConnectionStatus.SelectedItem.Value.AsIntegerOrNull();

                if (dpRequestDate.SelectedDate.HasValue)
                {
                    benevolenceRequest.RequestDateTime = dpRequestDate.SelectedDate.Value;
                }

                benevolenceRequest.HomePhoneNumber = pnbHomePhone.Number;
                benevolenceRequest.CellPhoneNumber = pnbCellPhone.Number;
                benevolenceRequest.WorkPhoneNumber = pnbWorkPhone.Number;

                List <BenevolenceResultInfo> resultList        = BenevolenceResultsState;
                BenevolenceResult            benevolenceResult = null;

                foreach (BenevolenceResult result in benevolenceRequest.BenevolenceResults.ToList())
                {
                    if (resultList.FirstOrDefault(r => r.ResultId == result.Id) == null)
                    {
                        benevolenceRequest.BenevolenceResults.Remove(result);
                        benevolenceResultService.Delete(result);
                    }
                }

                foreach (BenevolenceResultInfo benevolenceResultInfo in resultList)
                {
                    if (benevolenceResultInfo.ResultId == null)
                    {
                        benevolenceResult                      = new BenevolenceResult();
                        benevolenceResult.Amount               = benevolenceResultInfo.Amount;
                        benevolenceResult.ResultSummary        = benevolenceResultInfo.ResultSummary;
                        benevolenceResult.ResultTypeValueId    = benevolenceResultInfo.ResultTypeValueId;
                        benevolenceResult.BenevolenceRequestId = benevolenceRequest.Id;
                        benevolenceRequest.BenevolenceResults.Add(benevolenceResult);
                    }
                }

                if (benevolenceRequest.IsValid)
                {
                    if (benevolenceRequest.Id.Equals(0))
                    {
                        benevolenceRequestService.Add(benevolenceRequest);
                    }

                    rockContext.SaveChanges();
                    NavigateToParentPage();
                }
            }
        }
        /// <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 )
        {
            if ( Page.IsValid )
            {
                RockContext rockContext = new RockContext();
                BenevolenceRequestService benevolenceRequestService = new BenevolenceRequestService( rockContext );
                BenevolenceResultService benevolenceResultService = new BenevolenceResultService( rockContext );

                BenevolenceRequest benevolenceRequest = null;
                int benevolenceRequestId = PageParameter( "BenevolenceRequestId" ).AsInteger();

                if ( !benevolenceRequestId.Equals( 0 ) )
                {
                    benevolenceRequest = benevolenceRequestService.Get( benevolenceRequestId );
                }

                if ( benevolenceRequest == null )
                {
                    benevolenceRequest = new BenevolenceRequest { Id = 0 };
                }

                benevolenceRequest.FirstName = dtbFirstName.Text;
                benevolenceRequest.LastName = dtbLastName.Text;
                benevolenceRequest.Email = ebEmail.Text;
                benevolenceRequest.RequestText = dtbRequestText.Text;
                benevolenceRequest.ResultSummary = dtbSummary.Text;
                benevolenceRequest.GovernmentId = dtbGovernmentId.Text;

                if ( lapAddress.Location != null )
                {
                    benevolenceRequest.LocationId = lapAddress.Location.Id;
                }

                benevolenceRequest.RequestedByPersonAliasId = ppPerson.PersonAliasId;
                benevolenceRequest.CaseWorkerPersonAliasId = ddlCaseWorker.SelectedValue.AsIntegerOrNull();
                benevolenceRequest.RequestStatusValueId = ddlRequestStatus.SelectedValue.AsIntegerOrNull();
                benevolenceRequest.ConnectionStatusValueId = ddlConnectionStatus.SelectedValue.AsIntegerOrNull();

                if ( dpRequestDate.SelectedDate.HasValue )
                {
                    benevolenceRequest.RequestDateTime = dpRequestDate.SelectedDate.Value;
                }

                benevolenceRequest.HomePhoneNumber = pnbHomePhone.Number;
                benevolenceRequest.CellPhoneNumber = pnbCellPhone.Number;
                benevolenceRequest.WorkPhoneNumber = pnbWorkPhone.Number;

                List<BenevolenceResultInfo> resultListUI = BenevolenceResultsState;
                var resultListDB = benevolenceRequest.BenevolenceResults.ToList();

                // remove any Benevolence Results that were removed in the UI
                foreach ( BenevolenceResult resultDB in resultListDB )
                {
                    if ( !resultListUI.Any( r => r.ResultId == resultDB.Id ) )
                    {
                        benevolenceRequest.BenevolenceResults.Remove( resultDB );
                        benevolenceResultService.Delete( resultDB );
                    }
                }

                // add any Benevolence Results that were added in the UI
                foreach ( BenevolenceResultInfo resultUI in resultListUI )
                {
                    var resultDB = resultListDB.FirstOrDefault( r => r.Guid == resultUI.TempGuid );
                    if ( resultDB == null )
                    {
                        resultDB = new BenevolenceResult();
                        resultDB.BenevolenceRequestId = benevolenceRequest.Id;
                        resultDB.Guid = resultUI.TempGuid;
                        benevolenceRequest.BenevolenceResults.Add( resultDB );
                    }

                    resultDB.Amount = resultUI.Amount;
                    resultDB.ResultSummary = resultUI.ResultSummary;
                    resultDB.ResultTypeValueId = resultUI.ResultTypeValueId;
                }

                if ( benevolenceRequest.IsValid )
                {
                    if ( benevolenceRequest.Id.Equals( 0 ) )
                    {
                        benevolenceRequestService.Add( benevolenceRequest );
                    }

                    rockContext.SaveChanges();

                    var personId = this.PageParameter( "PersonId" ).AsIntegerOrNull();
                    var qryParams = new Dictionary<string, string>();
                    if ( personId.HasValue )
                    {
                        qryParams.Add( "PersonId", personId.ToString() );
                    }

                    NavigateToParentPage( qryParams );
                }
            }
        }
예제 #6
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)
        {
            if (Page.IsValid)
            {
                RockContext rockContext = new RockContext();
                BenevolenceRequestService benevolenceRequestService = new BenevolenceRequestService(rockContext);
                BenevolenceResultService  benevolenceResultService  = new BenevolenceResultService(rockContext);

                BenevolenceRequest benevolenceRequest = null;
                int benevolenceRequestId = PageParameter("BenevolenceRequestId").AsInteger();

                if (!benevolenceRequestId.Equals(0))
                {
                    benevolenceRequest = benevolenceRequestService.Get(benevolenceRequestId);
                }

                if (benevolenceRequest == null)
                {
                    benevolenceRequest = new BenevolenceRequest {
                        Id = 0
                    };
                }

                benevolenceRequest.FirstName     = dtbFirstName.Text;
                benevolenceRequest.LastName      = dtbLastName.Text;
                benevolenceRequest.Email         = ebEmail.Text;
                benevolenceRequest.RequestText   = dtbRequestText.Text;
                benevolenceRequest.ResultSummary = dtbSummary.Text;
                benevolenceRequest.GovernmentId  = dtbGovernmentId.Text;

                if (lapAddress.Location != null)
                {
                    benevolenceRequest.LocationId = lapAddress.Location.Id;
                }

                benevolenceRequest.RequestedByPersonAliasId = ppPerson.PersonAliasId;
                benevolenceRequest.CaseWorkerPersonAliasId  = ddlCaseWorker.SelectedValue.AsIntegerOrNull();
                benevolenceRequest.RequestStatusValueId     = ddlRequestStatus.SelectedValue.AsIntegerOrNull();
                benevolenceRequest.ConnectionStatusValueId  = ddlConnectionStatus.SelectedValue.AsIntegerOrNull();

                if (dpRequestDate.SelectedDate.HasValue)
                {
                    benevolenceRequest.RequestDateTime = dpRequestDate.SelectedDate.Value;
                }

                benevolenceRequest.HomePhoneNumber = pnbHomePhone.Number;
                benevolenceRequest.CellPhoneNumber = pnbCellPhone.Number;
                benevolenceRequest.WorkPhoneNumber = pnbWorkPhone.Number;

                List <BenevolenceResultInfo> resultListUI = BenevolenceResultsState;
                var resultListDB = benevolenceRequest.BenevolenceResults.ToList();

                // remove any Benevolence Results that were removed in the UI
                foreach (BenevolenceResult resultDB in resultListDB)
                {
                    if (!resultListUI.Any(r => r.ResultId == resultDB.Id))
                    {
                        benevolenceRequest.BenevolenceResults.Remove(resultDB);
                        benevolenceResultService.Delete(resultDB);
                    }
                }

                // add any Benevolence Results that were added in the UI
                foreach (BenevolenceResultInfo resultUI in resultListUI)
                {
                    var resultDB = resultListDB.FirstOrDefault(r => r.Guid == resultUI.TempGuid);
                    if (resultDB == null)
                    {
                        resultDB = new BenevolenceResult();
                        resultDB.BenevolenceRequestId = benevolenceRequest.Id;
                        resultDB.Guid = resultUI.TempGuid;
                        benevolenceRequest.BenevolenceResults.Add(resultDB);
                    }

                    resultDB.Amount            = resultUI.Amount;
                    resultDB.ResultSummary     = resultUI.ResultSummary;
                    resultDB.ResultTypeValueId = resultUI.ResultTypeValueId;
                }

                if (benevolenceRequest.IsValid)
                {
                    if (benevolenceRequest.Id.Equals(0))
                    {
                        benevolenceRequestService.Add(benevolenceRequest);
                    }

                    rockContext.SaveChanges();

                    var personId  = this.PageParameter("PersonId").AsIntegerOrNull();
                    var qryParams = new Dictionary <string, string>();
                    if (personId.HasValue)
                    {
                        qryParams.Add("PersonId", personId.ToString());
                    }

                    NavigateToParentPage(qryParams);
                }
            }
        }