Inheritance: Rock.Data.DbContext
        /// <summary>
        /// Handles the Delete event of the gAgencies 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 gAgencies_Delete( object sender, RowEventArgs e )
        {
            var dataContext = new SampleProjectContext();
            var service = new ReferralAgencyService( dataContext );
            var referralAgency = service.Get( (int)e.RowKeyValue );
            if ( referralAgency != null )
            {
                string errorMessage;
                if ( !service.CanDelete( referralAgency, out errorMessage ) )
                {
                    mdGridWarning.Show( errorMessage, ModalAlertType.Information );
                    return;
                }

                service.Delete( referralAgency );
                dataContext.SaveChanges();
            }

            BindGrid();
        }
        /// <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>
        protected void btnSave_Click( object sender, EventArgs e )
        {
            ReferralAgency referralAgency;
            var dataContext = new SampleProjectContext();
            var service = new ReferralAgencyService( dataContext );

            int campusId = int.Parse( hfReferralAgencyId.Value );

            if ( campusId == 0 )
            {
                referralAgency = new ReferralAgency();
                service.Add( referralAgency );
            }
            else
            {
                referralAgency = service.Get( campusId );
            }

            referralAgency.Name = tbName.Text;
            referralAgency.Description = tbDescription.Text;
            referralAgency.CampusId = cpCampus.SelectedCampusId;
            referralAgency.AgencyTypeValueId = ddlAgencyType.SelectedValueAsId();
            referralAgency.ContactName = tbContactName.Text;
            referralAgency.PhoneNumber = tbPhoneNumber.Text;
            referralAgency.Website = tbWebsite.Text;

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

            dataContext.SaveChanges();

            NavigateToParentPage();
        }