Example #1
0
        /// <summary>
        /// Handles the Delete event of the gMarketingCampaignAds 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 gMarketingCampaignAds_Delete(object sender, RowEventArgs e)
        {
            MarketingCampaignAdService marketingCampaignAdService = new MarketingCampaignAdService();
            MarketingCampaignAd        marketingCampaignAd        = marketingCampaignAdService.Get((int)e.RowKeyValue);

            marketingCampaignAdService.Delete(marketingCampaignAd, CurrentPersonId);
            marketingCampaignAdService.Save(marketingCampaignAd, CurrentPersonId);
            BindMarketingCampaignAdsGrid();
        }
        /// <summary>
        /// Handles the Delete event of the gMarketingCampaignAds 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 gMarketingCampaignAds_Delete( object sender, RowEventArgs e )
        {
            var rockContext = new RockContext();
            MarketingCampaignAdService marketingCampaignAdService = new MarketingCampaignAdService( rockContext );

            MarketingCampaignAd marketingCampaignAd = marketingCampaignAdService.Get( e.RowKeyId );
            if ( marketingCampaignAd != null )
            {
                string errorMessage;
                if ( !marketingCampaignAdService.CanDelete( marketingCampaignAd, out errorMessage ) )
                {
                    mdGridWarning.Show( errorMessage, ModalAlertType.Information );
                    return;
                }

                marketingCampaignAdService.Delete( marketingCampaignAd );
                rockContext.SaveChanges();
            }

            BindGrid();
        }
        /// <summary>
        /// Handles the Delete event of the gMarketingCampaignAds 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 gMarketingCampaignAds_Delete( object sender, RowEventArgs e )
        {
            var rockContext = new RockContext();
            MarketingCampaignAdService marketingCampaignAdService = new MarketingCampaignAdService( rockContext );

            MarketingCampaignAd marketingCampaignAd = marketingCampaignAdService.Get( e.RowKeyId );
            if ( marketingCampaignAd != null )
            {
                string errorMessage;
                if ( !marketingCampaignAdService.CanDelete( marketingCampaignAd, out errorMessage ) )
                {
                    mdGridWarning.Show( errorMessage, ModalAlertType.Information );
                    return;
                }

                marketingCampaignAdService.Delete( marketingCampaignAd );
                rockContext.SaveChanges();
            }

            BindGrid();
        }
Example #4
0
        /// <summary>
        /// Handles the Delete event of the gMarketingCampaignAds 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 gMarketingCampaignAds_Delete(object sender, RowEventArgs e)
        {
            RockTransactionScope.WrapTransaction(() =>
            {
                MarketingCampaignAdService marketingCampaignAdService = new MarketingCampaignAdService();
                MarketingCampaignAd marketingCampaignAd = marketingCampaignAdService.Get(e.RowKeyId);
                if (marketingCampaignAd != null)
                {
                    string errorMessage;
                    if (!marketingCampaignAdService.CanDelete(marketingCampaignAd, out errorMessage))
                    {
                        mdGridWarning.Show(errorMessage, ModalAlertType.Information);
                        return;
                    }

                    marketingCampaignAdService.Delete(marketingCampaignAd, CurrentPersonId);
                    marketingCampaignAdService.Save(marketingCampaignAd, CurrentPersonId);
                }
            });

            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 )
        {
            int marketingCampaignAdId = int.Parse( hfMarketingCampaignAdId.Value );

            var rockContext = new RockContext();
            MarketingCampaignAdService marketingCampaignAdService = new MarketingCampaignAdService( rockContext );

            MarketingCampaignAd marketingCampaignAd;
            if ( marketingCampaignAdId.Equals( 0 ) )
            {
                marketingCampaignAd = new MarketingCampaignAd { Id = 0 };
                marketingCampaignAd.MarketingCampaignId = hfMarketingCampaignId.ValueAsInt();
            }
            else
            {
                marketingCampaignAd = marketingCampaignAdService.Get( marketingCampaignAdId );
            }

            if ( string.IsNullOrWhiteSpace( ddlMarketingCampaignAdType.SelectedValue ) )
            {
                ddlMarketingCampaignAdType.ShowErrorMessage( WarningMessage.CannotBeBlank( ddlMarketingCampaignAdType.Label ) );
                return;
            }

            marketingCampaignAd.MarketingCampaignId = int.Parse( hfMarketingCampaignId.Value );
            marketingCampaignAd.MarketingCampaignAdTypeId = int.Parse( ddlMarketingCampaignAdType.SelectedValue );
            marketingCampaignAd.Priority = tbPriority.Text.AsInteger() ?? 0;
            marketingCampaignAd.MarketingCampaignAdStatus = (MarketingCampaignAdStatus)int.Parse( hfApprovalStatus.Value );
            if ( !string.IsNullOrWhiteSpace( hfApprovalStatusPersonId.Value ) )
            {
                marketingCampaignAd.MarketingCampaignStatusPersonId = int.Parse( hfApprovalStatusPersonId.Value );
            }
            else
            {
                marketingCampaignAd.MarketingCampaignStatusPersonId = null;
            }

            if (drpAdDateRange.Visible)
            {
                marketingCampaignAd.StartDate = drpAdDateRange.LowerValue ?? DateTime.MinValue;
                marketingCampaignAd.EndDate = drpAdDateRange.UpperValue ?? DateTime.MaxValue;
            }

            if (dpAdSingleDate.Visible)
            {
                marketingCampaignAd.StartDate = dpAdSingleDate.SelectedDate ?? DateTime.MinValue;
                marketingCampaignAd.EndDate = marketingCampaignAd.StartDate;
            }

            marketingCampaignAd.Url = tbUrl.Text;

            LoadAdAttributes( marketingCampaignAd, false, false );
            Rock.Attribute.Helper.GetEditValues( phAttributes, marketingCampaignAd );

            if ( !Page.IsValid )
            {
                return;
            }

            if ( !marketingCampaignAd.IsValid )
            {
                return;
            }

            RockTransactionScope.WrapTransaction( () =>
            {
                if ( marketingCampaignAd.Id.Equals( 0 ) )
                {
                    marketingCampaignAdService.Add( marketingCampaignAd );
                }

                rockContext.SaveChanges();

                marketingCampaignAd.SaveAttributeValues( rockContext );
            } );

            Dictionary<string, string> qryString = new Dictionary<string, string>();
            qryString["marketingCampaignId"] = hfMarketingCampaignId.Value;
            NavigateToParentPage( qryString );
        }
        /// <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)
        {
            int marketingCampaignAdId = int.Parse(hfMarketingCampaignAdId.Value);
            MarketingCampaignAdService marketingCampaignAdService = new MarketingCampaignAdService();

            MarketingCampaignAd marketingCampaignAd;

            if (marketingCampaignAdId.Equals(0))
            {
                marketingCampaignAd = new MarketingCampaignAd {
                    Id = 0
                };
                marketingCampaignAd.MarketingCampaignId = hfMarketingCampaignId.ValueAsInt();
            }
            else
            {
                marketingCampaignAd = marketingCampaignAdService.Get(marketingCampaignAdId);
            }

            if (string.IsNullOrWhiteSpace(ddlMarketingCampaignAdType.SelectedValue))
            {
                ddlMarketingCampaignAdType.ShowErrorMessage(WarningMessage.CannotBeBlank(ddlMarketingCampaignAdType.Label));
                return;
            }

            marketingCampaignAd.MarketingCampaignId       = int.Parse(hfMarketingCampaignId.Value);
            marketingCampaignAd.MarketingCampaignAdTypeId = int.Parse(ddlMarketingCampaignAdType.SelectedValue);
            marketingCampaignAd.Priority = tbPriority.Text.AsInteger() ?? 0;
            marketingCampaignAd.MarketingCampaignAdStatus = (MarketingCampaignAdStatus)int.Parse(hfMarketingCampaignAdStatus.Value);
            if (!string.IsNullOrWhiteSpace(hfMarketingCampaignAdStatusPersonId.Value))
            {
                marketingCampaignAd.MarketingCampaignStatusPersonId = int.Parse(hfMarketingCampaignAdStatusPersonId.Value);
            }
            else
            {
                marketingCampaignAd.MarketingCampaignStatusPersonId = null;
            }

            if (tbAdDateRangeStartDate.SelectedDate == null)
            {
                tbAdDateRangeStartDate.ShowErrorMessage(Rock.Constants.WarningMessage.CannotBeBlank("StartDate"));
                return;
            }

            marketingCampaignAd.StartDate = tbAdDateRangeStartDate.SelectedDate ?? DateTime.MinValue;

            if (tbAdDateRangeEndDate.Visible)
            {
                if (tbAdDateRangeEndDate.SelectedDate == null)
                {
                    tbAdDateRangeEndDate.ShowErrorMessage(Rock.Constants.WarningMessage.CannotBeBlank("EndDate"));
                    return;
                }

                marketingCampaignAd.EndDate = tbAdDateRangeEndDate.SelectedDate ?? DateTime.MaxValue;
            }
            else
            {
                marketingCampaignAd.EndDate = marketingCampaignAd.StartDate;
            }

            if (marketingCampaignAd.EndDate < marketingCampaignAd.StartDate)
            {
                tbAdDateRangeStartDate.ShowErrorMessage(WarningMessage.DateRangeEndDateBeforeStartDate());
            }

            marketingCampaignAd.Url = tbUrl.Text;

            LoadAdAttributes(marketingCampaignAd, false, false);
            Rock.Attribute.Helper.GetEditValues(phAttributes, marketingCampaignAd);

            if (!Page.IsValid)
            {
                return;
            }

            if (!marketingCampaignAd.IsValid)
            {
                return;
            }

            RockTransactionScope.WrapTransaction(() =>
            {
                if (marketingCampaignAd.Id.Equals(0))
                {
                    marketingCampaignAdService.Add(marketingCampaignAd, CurrentPersonId);
                }

                marketingCampaignAdService.Save(marketingCampaignAd, CurrentPersonId);
                Rock.Attribute.Helper.SaveAttributeValues(marketingCampaignAd, CurrentPersonId);
            });

            Dictionary <string, string> qryString = new Dictionary <string, string>();

            qryString["marketingCampaignId"] = hfMarketingCampaignId.Value;
            NavigateToParentPage(qryString);
        }
        /// <summary>
        /// Handles the Delete event of the gMarketingCampaignAds 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 gMarketingCampaignAds_Delete( object sender, RowEventArgs e )
        {
            MarketingCampaignAdService marketingCampaignAdService = new MarketingCampaignAdService();
            MarketingCampaignAd marketingCampaignAd = marketingCampaignAdService.Get( (int)e.RowKeyValue );

            marketingCampaignAdService.Delete( marketingCampaignAd, CurrentPersonId );
            marketingCampaignAdService.Save( marketingCampaignAd, CurrentPersonId );
            BindMarketingCampaignAdsGrid();
        }
        /// <summary>
        /// Handles the Click event of the btnSaveAd 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 btnSaveAd_Click( object sender, EventArgs e )
        {
            int marketingCampaignAdId = int.Parse( hfMarketingCampaignAdId.Value );
            MarketingCampaignAdService marketingCampaignAdService = new MarketingCampaignAdService();

            MarketingCampaignAd marketingCampaignAd;
            if ( marketingCampaignAdId.Equals( 0 ) )
            {
                marketingCampaignAd = new MarketingCampaignAd { Id = 0 };
            }
            else
            {
                marketingCampaignAd = marketingCampaignAdService.Get( marketingCampaignAdId );
            }

            marketingCampaignAd.MarketingCampaignId = int.Parse( hfMarketingCampaignId.Value );
            marketingCampaignAd.MarketingCampaignAdTypeId = int.Parse( ddlMarketingCampaignAdType.SelectedValue );
            marketingCampaignAd.Priority = tbPriority.TextAsInteger() ?? 0;
            marketingCampaignAd.MarketingCampaignAdStatus = (MarketingCampaignAdStatus)int.Parse( hfMarketingCampaignAdStatus.Value );
            if ( !string.IsNullOrWhiteSpace( hfMarketingCampaignAdStatusPersonId.Value ) )
            {
                marketingCampaignAd.MarketingCampaignStatusPersonId = int.Parse( hfMarketingCampaignAdStatusPersonId.Value );
            }
            else
            {
                marketingCampaignAd.MarketingCampaignStatusPersonId = null;
            }

            if ( tbAdDateRangeStartDate.SelectedDate == null )
            {
                tbAdDateRangeStartDate.ShowErrorMessage( Rock.Constants.WarningMessage.CannotBeBlank( "StartDate" ) );
                return;
            }

            marketingCampaignAd.StartDate = tbAdDateRangeStartDate.SelectedDate ?? DateTime.MinValue;

            if ( tbAdDateRangeEndDate.Visible )
            {
                if ( tbAdDateRangeEndDate.SelectedDate == null )
                {
                    tbAdDateRangeEndDate.ShowErrorMessage( Rock.Constants.WarningMessage.CannotBeBlank( "EndDate" ) );
                    return;
                }

                marketingCampaignAd.EndDate = tbAdDateRangeEndDate.SelectedDate ?? DateTime.MaxValue;
            }
            else
            {
                marketingCampaignAd.EndDate = marketingCampaignAd.StartDate;
            }

            if ( marketingCampaignAd.EndDate < marketingCampaignAd.StartDate )
            {
                tbAdDateRangeStartDate.ShowErrorMessage( WarningMessage.DateRangeEndDateBeforeStartDate() );
            }

            marketingCampaignAd.Url = tbUrl.Text;

            LoadAdAttributes( marketingCampaignAd, false, false );
            Rock.Attribute.Helper.GetEditValues( phAttributes, marketingCampaignAd );
            Rock.Attribute.Helper.SetErrorIndicators( phAttributes, marketingCampaignAd );

            if ( !Page.IsValid )
            {
                return;
            }

            if ( !marketingCampaignAd.IsValid )
            {
                return;
            }

            RockTransactionScope.WrapTransaction( () =>
                {
                    if ( marketingCampaignAd.Id.Equals( 0 ) )
                    {
                        marketingCampaignAdService.Add( marketingCampaignAd, CurrentPersonId );
                    }

                    marketingCampaignAdService.Save( marketingCampaignAd, CurrentPersonId );
                    Rock.Attribute.Helper.SaveAttributeValues( marketingCampaignAd, CurrentPersonId );
                } );

            pnlMarketingCampaignAdEditor.Visible = false;
            pnlDetails.Visible = true;
            pnlList.Visible = false;

            BindMarketingCampaignAdsGrid();
        }