Пример #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>
        protected void btnSave_Click( object sender, EventArgs e )
        {
            var rockContext = new RockContext();

            MarketingCampaign marketingCampaign;

            MarketingCampaignService marketingCampaignService = new MarketingCampaignService( rockContext );

            int marketingCampaignId = int.Parse( hfMarketingCampaignId.Value );

            if ( marketingCampaignId == 0 )
            {
                marketingCampaign = new MarketingCampaign();
                marketingCampaignService.Add( marketingCampaign );
            }
            else
            {
                marketingCampaign = marketingCampaignService.Get( marketingCampaignId );
            }

            marketingCampaign.Title = tbTitle.Text;
            if ( ppContactPerson.SelectedValue.Equals( None.Id.ToString() ) )
            {
                marketingCampaign.ContactPersonId = null;
            }
            else
            {
                marketingCampaign.ContactPersonId = ppContactPerson.PersonId;
            }

            marketingCampaign.ContactEmail = tbContactEmail.Text;
            marketingCampaign.ContactPhoneNumber = tbContactPhoneNumber.Text;
            marketingCampaign.ContactFullName = tbContactFullName.Text;

            if ( ddlEventGroup.SelectedValue.Equals( None.Id.ToString() ) )
            {
                marketingCampaign.EventGroupId = null;
            }
            else
            {
                marketingCampaign.EventGroupId = int.Parse( ddlEventGroup.SelectedValue );
            }

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

            rockContext.WrapTransaction( () =>
            {
                /* Save MarketingCampaignAudiences to db */
                if ( marketingCampaign.MarketingCampaignAudiences == null )
                {
                    marketingCampaign.MarketingCampaignAudiences = new List<MarketingCampaignAudience>();
                }

                // delete Audiences that aren't assigned in the UI anymore
                MarketingCampaignAudienceService marketingCampaignAudienceService = new MarketingCampaignAudienceService( rockContext );
                var deletedAudiences = from audienceInDB in marketingCampaign.MarketingCampaignAudiences.AsQueryable()
                                       where !( from audienceStateItem in MarketingCampaignAudiencesState
                                                select audienceStateItem.AudienceTypeValueId ).Contains( audienceInDB.AudienceTypeValueId )
                                       select audienceInDB;
                deletedAudiences.ToList().ForEach( a =>
                {
                    var aud = marketingCampaignAudienceService.Get( a.Guid );
                    marketingCampaignAudienceService.Delete( aud );
                } );

                rockContext.SaveChanges();

                // add or update the Audiences that are assigned in the UI
                foreach ( var item in MarketingCampaignAudiencesState )
                {
                    MarketingCampaignAudience marketingCampaignAudience = marketingCampaign.MarketingCampaignAudiences.FirstOrDefault( a => a.AudienceTypeValueId.Equals( item.AudienceTypeValueId ) );
                    if ( marketingCampaignAudience == null )
                    {
                        marketingCampaignAudience = new MarketingCampaignAudience();
                        marketingCampaign.MarketingCampaignAudiences.Add( marketingCampaignAudience );
                    }

                    marketingCampaignAudience.AudienceTypeValueId = item.AudienceTypeValueId;
                    marketingCampaignAudience.IsPrimary = item.IsPrimary;
                }

                /* Save MarketingCampaignCampuses to db */

                // Update MarketingCampaignCampuses with UI values
                if ( marketingCampaign.MarketingCampaignCampuses == null )
                {
                    marketingCampaign.MarketingCampaignCampuses = new List<MarketingCampaignCampus>();
                }

                // take care of deleted Campuses
                MarketingCampaignCampusService marketingCampaignCampusService = new MarketingCampaignCampusService( rockContext );
                var deletedCampuses = from mcc in marketingCampaign.MarketingCampaignCampuses.AsQueryable()
                                      where !cpCampuses.SelectedCampusIds.Contains( mcc.CampusId )
                                      select mcc;

                deletedCampuses.ToList().ForEach( a =>
                {
                    var c = marketingCampaignCampusService.Get( a.Guid );
                    marketingCampaignCampusService.Delete( c );
                } );

                rockContext.SaveChanges();

                // add or update the Campuses that are assigned in the UI
                foreach ( int campusId in cpCampuses.SelectedCampusIds )
                {
                    MarketingCampaignCampus marketingCampaignCampus = marketingCampaign.MarketingCampaignCampuses.FirstOrDefault( a => a.CampusId.Equals( campusId ) );
                    if ( marketingCampaignCampus == null )
                    {
                        marketingCampaignCampus = new MarketingCampaignCampus();
                        marketingCampaign.MarketingCampaignCampuses.Add( marketingCampaignCampus );
                    }

                    marketingCampaignCampus.CampusId = campusId;
                }

                rockContext.SaveChanges();
            } );

            var qryParams = new Dictionary<string, string>();
            qryParams["marketingCampaignId"] = marketingCampaign.Id.ToString();
            NavigateToPage( RockPage.Guid, qryParams );
        }
Пример #2
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>
        protected void btnSave_Click( object sender, EventArgs e )
        {
            MarketingCampaign marketingCampaign;
            MarketingCampaignService marketingCampaignService = new MarketingCampaignService();

            int marketingCampaignId = int.Parse( hfMarketingCampaignId.Value );

            if ( marketingCampaignId == 0 )
            {
                marketingCampaign = new MarketingCampaign();
                marketingCampaignService.Add( marketingCampaign, CurrentPersonId );
            }
            else
            {
                marketingCampaign = marketingCampaignService.Get( marketingCampaignId );
            }

            marketingCampaign.Title = tbTitle.Text;
            if ( ddlContactPerson.SelectedValue.Equals( None.Id.ToString() ) )
            {
                marketingCampaign.ContactPersonId = null;
            }
            else
            {
                marketingCampaign.ContactPersonId = int.Parse( ddlContactPerson.SelectedValue );
            }

            marketingCampaign.ContactEmail = tbContactEmail.Text;
            marketingCampaign.ContactPhoneNumber = tbContactPhoneNumber.Text;
            marketingCampaign.ContactFullName = tbContactFullName.Text;

            if ( ddlEventGroup.SelectedValue.Equals( None.Id.ToString() ) )
            {
                marketingCampaign.EventGroupId = null;
            }
            else
            {
                marketingCampaign.EventGroupId = int.Parse( ddlEventGroup.SelectedValue );
            }

            // check for duplicates
            if ( marketingCampaignService.Queryable().Count( a => a.Title.Equals( marketingCampaign.Title, StringComparison.OrdinalIgnoreCase ) && !a.Id.Equals( marketingCampaign.Id ) ) > 0 )
            {
                tbTitle.ShowErrorMessage( WarningMessage.DuplicateFoundMessage( "title", MarketingCampaign.FriendlyTypeName ) );
                return;
            }

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

            RockTransactionScope.WrapTransaction( () =>
            {
                #region Save MarketingCampaignAudiences to db

                // Update MarketingCampaignAudiences with UI values
                if ( marketingCampaign.MarketingCampaignAudiences == null )
                {
                    marketingCampaign.MarketingCampaignAudiences = new List<MarketingCampaignAudience>();
                }

                // delete Audiences that aren't assigned in the UI anymore
                MarketingCampaignAudienceService marketingCampaignAudienceService = new MarketingCampaignAudienceService();
                var deletedAudiences = from audienceInDB in marketingCampaign.MarketingCampaignAudiences.AsQueryable()
                                       where !( from audienceStateItem in MarketingCampaignAudiencesState
                                                select audienceStateItem.AudienceTypeValueId ).Contains( audienceInDB.AudienceTypeValueId )
                                       select audienceInDB;
                deletedAudiences.ToList().ForEach( a =>
                {
                    var aud = marketingCampaignAudienceService.Get( a.Guid );
                    marketingCampaignAudienceService.Delete( aud, CurrentPersonId );
                    marketingCampaignAudienceService.Save( aud, CurrentPersonId );
                } );

                // add or update the Audiences that are assigned in the UI
                foreach ( var item in MarketingCampaignAudiencesState )
                {
                    MarketingCampaignAudience marketingCampaignAudience = marketingCampaign.MarketingCampaignAudiences.FirstOrDefault( a => a.AudienceTypeValueId.Equals( item.AudienceTypeValueId ) );
                    if ( marketingCampaignAudience == null )
                    {
                        marketingCampaignAudience = new MarketingCampaignAudience();
                        marketingCampaign.MarketingCampaignAudiences.Add( marketingCampaignAudience );
                    }

                    marketingCampaignAudience.AudienceTypeValueId = item.AudienceTypeValueId;
                    marketingCampaignAudience.IsPrimary = item.IsPrimary;
                }

                #endregion

                #region Save MarketingCampaignCampuses to db

                // Update MarketingCampaignCampuses with UI values
                if ( marketingCampaign.MarketingCampaignCampuses == null )
                {
                    marketingCampaign.MarketingCampaignCampuses = new List<MarketingCampaignCampus>();
                }

                // take care of deleted Campuses
                MarketingCampaignCampusService marketingCampaignCampusService = new MarketingCampaignCampusService();
                var deletedCampuses = from mcc in marketingCampaign.MarketingCampaignCampuses.AsQueryable()
                                      where !( cpCampuses.SelectedCampusIds ).Contains( mcc.CampusId )
                                      select mcc;

                deletedCampuses.ToList().ForEach( a =>
                {
                    var c = marketingCampaignCampusService.Get( a.Guid );
                    marketingCampaignCampusService.Delete( c, CurrentPersonId );
                    marketingCampaignCampusService.Save( c, CurrentPersonId );
                } );

                // add or update the Campuses that are assigned in the UI
                foreach ( int campusId in cpCampuses.SelectedCampusIds )
                {
                    MarketingCampaignCampus marketingCampaignCampus = marketingCampaign.MarketingCampaignCampuses.FirstOrDefault( a => a.CampusId.Equals( campusId ) );
                    if ( marketingCampaignCampus == null )
                    {
                        marketingCampaignCampus = new MarketingCampaignCampus();
                        marketingCampaign.MarketingCampaignCampuses.Add( marketingCampaignCampus );
                    }

                    marketingCampaignCampus.CampusId = campusId;
                }

                #endregion

                marketingCampaignService.Save( marketingCampaign, CurrentPersonId );
            } );

            hfMarketingCampaignId.Value = marketingCampaign.Id.ToString();

            // refresh from db using new service context since the above child items were saved outside of the marketingCampaign object
            marketingCampaign = MarketingCampaign.Read( marketingCampaign.Id );
            UpdateReadonlyDetails( marketingCampaign );

            SetEditMode( false );
            pnlDetails.Visible = true;
            pnlList.Visible = false;
        }
Пример #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>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            MarketingCampaign        marketingCampaign;
            MarketingCampaignService marketingCampaignService = new MarketingCampaignService();

            int marketingCampaignId = int.Parse(hfMarketingCampaignId.Value);

            if (marketingCampaignId == 0)
            {
                marketingCampaign = new MarketingCampaign();
                marketingCampaignService.Add(marketingCampaign, CurrentPersonId);
            }
            else
            {
                marketingCampaign = marketingCampaignService.Get(marketingCampaignId);
            }

            marketingCampaign.Title = tbTitle.Text;
            if (ppContactPerson.SelectedValue.Equals(None.Id.ToString()))
            {
                marketingCampaign.ContactPersonId = null;
            }
            else
            {
                marketingCampaign.ContactPersonId = ppContactPerson.PersonId;
            }

            marketingCampaign.ContactEmail       = tbContactEmail.Text;
            marketingCampaign.ContactPhoneNumber = tbContactPhoneNumber.Text;
            marketingCampaign.ContactFullName    = tbContactFullName.Text;

            if (ddlEventGroup.SelectedValue.Equals(None.Id.ToString()))
            {
                marketingCampaign.EventGroupId = null;
            }
            else
            {
                marketingCampaign.EventGroupId = int.Parse(ddlEventGroup.SelectedValue);
            }

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

            RockTransactionScope.WrapTransaction(() =>
            {
                /* Save MarketingCampaignAudiences to db */
                if (marketingCampaign.MarketingCampaignAudiences == null)
                {
                    marketingCampaign.MarketingCampaignAudiences = new List <MarketingCampaignAudience>();
                }

                // delete Audiences that aren't assigned in the UI anymore
                MarketingCampaignAudienceService marketingCampaignAudienceService = new MarketingCampaignAudienceService();
                var deletedAudiences = from audienceInDB in marketingCampaign.MarketingCampaignAudiences.AsQueryable()
                                       where !(from audienceStateItem in MarketingCampaignAudiencesState
                                               select audienceStateItem.AudienceTypeValueId).Contains(audienceInDB.AudienceTypeValueId)
                                       select audienceInDB;
                deletedAudiences.ToList().ForEach(a =>
                {
                    var aud = marketingCampaignAudienceService.Get(a.Guid);
                    marketingCampaignAudienceService.Delete(aud, CurrentPersonId);
                    marketingCampaignAudienceService.Save(aud, CurrentPersonId);
                });

                // add or update the Audiences that are assigned in the UI
                foreach (var item in MarketingCampaignAudiencesState)
                {
                    MarketingCampaignAudience marketingCampaignAudience = marketingCampaign.MarketingCampaignAudiences.FirstOrDefault(a => a.AudienceTypeValueId.Equals(item.AudienceTypeValueId));
                    if (marketingCampaignAudience == null)
                    {
                        marketingCampaignAudience = new MarketingCampaignAudience();
                        marketingCampaign.MarketingCampaignAudiences.Add(marketingCampaignAudience);
                    }

                    marketingCampaignAudience.AudienceTypeValueId = item.AudienceTypeValueId;
                    marketingCampaignAudience.IsPrimary           = item.IsPrimary;
                }

                /* Save MarketingCampaignCampuses to db */

                // Update MarketingCampaignCampuses with UI values
                if (marketingCampaign.MarketingCampaignCampuses == null)
                {
                    marketingCampaign.MarketingCampaignCampuses = new List <MarketingCampaignCampus>();
                }

                // take care of deleted Campuses
                MarketingCampaignCampusService marketingCampaignCampusService = new MarketingCampaignCampusService();
                var deletedCampuses = from mcc in marketingCampaign.MarketingCampaignCampuses.AsQueryable()
                                      where !cpCampuses.SelectedCampusIds.Contains(mcc.CampusId)
                                      select mcc;

                deletedCampuses.ToList().ForEach(a =>
                {
                    var c = marketingCampaignCampusService.Get(a.Guid);
                    marketingCampaignCampusService.Delete(c, CurrentPersonId);
                    marketingCampaignCampusService.Save(c, CurrentPersonId);
                });

                // add or update the Campuses that are assigned in the UI
                foreach (int campusId in cpCampuses.SelectedCampusIds)
                {
                    MarketingCampaignCampus marketingCampaignCampus = marketingCampaign.MarketingCampaignCampuses.FirstOrDefault(a => a.CampusId.Equals(campusId));
                    if (marketingCampaignCampus == null)
                    {
                        marketingCampaignCampus = new MarketingCampaignCampus();
                        marketingCampaign.MarketingCampaignCampuses.Add(marketingCampaignCampus);
                    }

                    marketingCampaignCampus.CampusId = campusId;
                }

                marketingCampaignService.Save(marketingCampaign, CurrentPersonId);
            });


            var qryParams = new Dictionary <string, string>();

            qryParams["marketingCampaignId"] = marketingCampaign.Id.ToString();
            NavigateToPage(RockPage.Guid, qryParams);
        }
Пример #4
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>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            MarketingCampaign        marketingCampaign;
            MarketingCampaignService marketingCampaignService = new MarketingCampaignService();

            int marketingCampaignId = int.Parse(hfMarketingCampaignId.Value);

            if (marketingCampaignId == 0)
            {
                marketingCampaign = new MarketingCampaign();
                marketingCampaignService.Add(marketingCampaign, CurrentPersonId);
            }
            else
            {
                marketingCampaign = marketingCampaignService.Get(marketingCampaignId);
            }

            marketingCampaign.Title = tbTitle.Text;
            if (ddlContactPerson.SelectedValue.Equals(None.Id.ToString()))
            {
                marketingCampaign.ContactPersonId = null;
            }
            else
            {
                marketingCampaign.ContactPersonId = int.Parse(ddlContactPerson.SelectedValue);
            }

            marketingCampaign.ContactEmail       = tbContactEmail.Text;
            marketingCampaign.ContactPhoneNumber = tbContactPhoneNumber.Text;
            marketingCampaign.ContactFullName    = tbContactFullName.Text;

            if (ddlEventGroup.SelectedValue.Equals(None.Id.ToString()))
            {
                marketingCampaign.EventGroupId = null;
            }
            else
            {
                marketingCampaign.EventGroupId = int.Parse(ddlEventGroup.SelectedValue);
            }

            // check for duplicates
            if (marketingCampaignService.Queryable().Count(a => a.Title.Equals(marketingCampaign.Title, StringComparison.OrdinalIgnoreCase) && !a.Id.Equals(marketingCampaign.Id)) > 0)
            {
                tbTitle.ShowErrorMessage(WarningMessage.DuplicateFoundMessage("title", MarketingCampaign.FriendlyTypeName));
                return;
            }

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

            RockTransactionScope.WrapTransaction(() =>
            {
                #region Save MarketingCampaignAudiences to db

                // Update MarketingCampaignAudiences with UI values
                if (marketingCampaign.MarketingCampaignAudiences == null)
                {
                    marketingCampaign.MarketingCampaignAudiences = new List <MarketingCampaignAudience>();
                }

                // delete Audiences that aren't assigned in the UI anymore
                MarketingCampaignAudienceService marketingCampaignAudienceService = new MarketingCampaignAudienceService();
                var deletedAudiences = from audienceInDB in marketingCampaign.MarketingCampaignAudiences.AsQueryable()
                                       where !(from audienceStateItem in MarketingCampaignAudiencesState
                                               select audienceStateItem.AudienceTypeValueId).Contains(audienceInDB.AudienceTypeValueId)
                                       select audienceInDB;
                deletedAudiences.ToList().ForEach(a =>
                {
                    var aud = marketingCampaignAudienceService.Get(a.Guid);
                    marketingCampaignAudienceService.Delete(aud, CurrentPersonId);
                    marketingCampaignAudienceService.Save(aud, CurrentPersonId);
                });

                // add or update the Audiences that are assigned in the UI
                foreach (var item in MarketingCampaignAudiencesState)
                {
                    MarketingCampaignAudience marketingCampaignAudience = marketingCampaign.MarketingCampaignAudiences.FirstOrDefault(a => a.AudienceTypeValueId.Equals(item.AudienceTypeValueId));
                    if (marketingCampaignAudience == null)
                    {
                        marketingCampaignAudience = new MarketingCampaignAudience();
                        marketingCampaign.MarketingCampaignAudiences.Add(marketingCampaignAudience);
                    }

                    marketingCampaignAudience.AudienceTypeValueId = item.AudienceTypeValueId;
                    marketingCampaignAudience.IsPrimary           = item.IsPrimary;
                }

                #endregion

                #region Save MarketingCampaignCampuses to db

                // Update MarketingCampaignCampuses with UI values
                if (marketingCampaign.MarketingCampaignCampuses == null)
                {
                    marketingCampaign.MarketingCampaignCampuses = new List <MarketingCampaignCampus>();
                }

                // take care of deleted Campuses
                MarketingCampaignCampusService marketingCampaignCampusService = new MarketingCampaignCampusService();
                var deletedCampuses = from mcc in marketingCampaign.MarketingCampaignCampuses.AsQueryable()
                                      where !(cpCampuses.SelectedCampusIds).Contains(mcc.CampusId)
                                      select mcc;

                deletedCampuses.ToList().ForEach(a =>
                {
                    var c = marketingCampaignCampusService.Get(a.Guid);
                    marketingCampaignCampusService.Delete(c, CurrentPersonId);
                    marketingCampaignCampusService.Save(c, CurrentPersonId);
                });

                // add or update the Campuses that are assigned in the UI
                foreach (int campusId in cpCampuses.SelectedCampusIds)
                {
                    MarketingCampaignCampus marketingCampaignCampus = marketingCampaign.MarketingCampaignCampuses.FirstOrDefault(a => a.CampusId.Equals(campusId));
                    if (marketingCampaignCampus == null)
                    {
                        marketingCampaignCampus = new MarketingCampaignCampus();
                        marketingCampaign.MarketingCampaignCampuses.Add(marketingCampaignCampus);
                    }

                    marketingCampaignCampus.CampusId = campusId;
                }

                #endregion

                marketingCampaignService.Save(marketingCampaign, CurrentPersonId);
            });

            hfMarketingCampaignId.Value = marketingCampaign.Id.ToString();

            // refresh from db using new service context since the above child items were saved outside of the marketingCampaign object
            marketingCampaign = MarketingCampaign.Read(marketingCampaign.Id);
            UpdateReadonlyDetails(marketingCampaign);

            SetEditMode(false);
            pnlDetails.Visible = true;
            pnlList.Visible    = false;
        }