protected void btnSave_Click(object sender, EventArgs e)
        {
            RockContext         rockContext         = new RockContext();
            PublishGroupService publishGroupService = new PublishGroupService(rockContext);

            publishGroup = GetPublishGroup(rockContext, publishGroupService);

            if (publishGroup.PublishGroupStatus == PublishGroupStatus.Approved)
            {
                var tempGroup = publishGroup.Group;
                publishGroup       = ( PublishGroup )publishGroup.Clone();
                publishGroup.Guid  = Guid.NewGuid();
                publishGroup.Id    = 0;
                publishGroup.Group = tempGroup;
                publishGroupService.Add(publishGroup);
            }

            publishGroup.ImageId                   = iGroupImage.BinaryFileId;
            publishGroup.PublishGroupStatus        = PublishGroupStatus.Pending;
            publishGroup.Description               = tbDescription.Text;
            publishGroup.EndDateTime               = drPublishDates.UpperValue.Value;
            publishGroup.StartDateTime             = drPublishDates.LowerValue.Value;
            publishGroup.WeeklyDayOfWeek           = ddlDayOfWeek.SelectedValueAsEnumOrNull <DayOfWeek>();
            publishGroup.WeeklyTimeOfDay           = tTimeOfDay.SelectedTime;
            publishGroup.StartDate                 = dpStartDate.SelectedDate;
            publishGroup.MeetingLocation           = tbLocationName.Text;
            publishGroup.RequiresRegistration      = cbRequiresRegistration.Checked;
            publishGroup.RegistrationLink          = cbRequiresRegistration.Checked ? tbRegistrationLink.Text : "";
            publishGroup.AllowSpouseRegistration   = cbAllowSpouseRegistration.Checked;
            publishGroup.ChildcareAvailable        = cbChildcareAvailable.Checked;
            publishGroup.ChildcareRegistrationLink = cbChildcareAvailable.Checked ? tbChildcareRegistrationLink.Text : "";
            publishGroup.AudienceValues            = GetSelectedAudiences(rockContext);
            publishGroup.ContactPersonAliasId      = pContactPerson.PersonAliasId.Value;
            publishGroup.RequestorAliasId          = CurrentPersonAliasId.Value;
            publishGroup.ContactEmail              = tbContactEmail.Text;
            publishGroup.ContactPhoneNumber        = tbContactPhoneNumber.Text;
            publishGroup.ConfirmationFromName      = tbConfirmationFromName.Text;
            publishGroup.ConfirmationEmail         = tbConfirmationFromEmail.Text;
            publishGroup.ConfirmationSubject       = tbConfirmationSubject.Text;
            publishGroup.ConfirmationBody          = ceConfirmationBody.Text;

            if (publishGroup.Id == 0)
            {
                publishGroupService.Add(publishGroup);
            }

            if (IsUserAuthorized(Rock.Security.Authorization.EDIT))
            {
                publishGroup.PublishGroupStatus = PublishGroupStatus.Approved;
                publishGroup.Group.IsActive     = true;
                publishGroup.Group.IsPublic     = true;
                //remove all other publish groups for this computer
                publishGroupService.DeleteRange(publishGroupService.Queryable().Where(pg => pg.GroupId == publishGroup.GroupId && pg.Id != publishGroup.Id));
            }
            ;

            //Set the binary file to not be temporary
            if (publishGroup.ImageId.HasValue)
            {
                BinaryFileService binaryFileService = new BinaryFileService(rockContext);
                var binaryFile = binaryFileService.Get(publishGroup.ImageId.Value);
                if (binaryFile != null)
                {
                    binaryFile.IsTemporary = false;
                }
            }

            rockContext.SaveChanges();

            publishGroup.LoadAttributes(rockContext);

            if (publishGroup.Attributes.Any())
            {
                Rock.Attribute.Helper.GetEditValues(phAttributeEdits, publishGroup);
                publishGroup.SaveAttributeValues(rockContext);
            }

            if (IsUserAuthorized(Rock.Security.Authorization.EDIT))
            {
                publishGroup.LaunchWorkflow(GetAttributeValue("CompleteWorkflow").AsGuidOrNull());
            }
            else
            {
                publishGroup.LaunchWorkflow(GetAttributeValue("RequestWorkflow").AsGuidOrNull());
            }
            NavigateToParentPage();
        }
Example #2
0
        /// <summary>Saves the specified publish group status.</summary>
        /// <param name="publishGroupStatus">The publish group status.</param>
        private void Save(PublishGroupStatus publishGroupStatus)
        {
            RockContext         rockContext         = new RockContext();
            PublishGroupService publishGroupService = new PublishGroupService(rockContext);
            PublishGroup        publishGroup        = GetPublishGroup(rockContext, publishGroupService);

            var slug = tbSlug.Text.ToLower().RemoveAllNonAlphaNumericCharacters();

            tbSlug.Text = slug;

            //Test for already taken Slugs
            var isDuplicateSlug = publishGroupService.Queryable()
                                  .Where(pg => pg.Slug == slug && pg.Id != publishGroup.Id && pg.GroupId != publishGroup.Group.Id)
                                  .Any();

            if (isDuplicateSlug)
            {
                nbSlug.Visible = true;
                return;
            }
            else
            {
                nbSlug.Visible    = false;
                publishGroup.Slug = slug;
            }


            bool isApprover = false;

            if (IsUserAuthorized(Rock.Security.Authorization.EDIT))
            {
                isApprover = true;
            }

            if (isApprover)
            {
                publishGroupStatus = ddlStatus.SelectedValueAsEnum <PublishGroupStatus>();
            }
            else if (publishGroupStatus != PublishGroupStatus.Draft)
            {
                if (ddlRegistration.SelectedValue == "4" ||
                    (ddlChildcareOptions.SelectedValue == "2" && ddlChildcareNeedRegistration.SelectedValue == "2"))     //Childcare required && Registration needed.
                {
                    publishGroupStatus = PublishGroupStatus.PendingIT;
                }
            }

            if (publishGroup.PublishGroupStatus == PublishGroupStatus.Approved)
            {
                var tempGroup = publishGroup.Group;
                publishGroup       = ( PublishGroup )publishGroup.Clone();
                publishGroup.Guid  = Guid.NewGuid();
                publishGroup.Id    = 0;
                publishGroup.Group = tempGroup;
                publishGroupService.Add(publishGroup);
            }

            publishGroup.Name                             = tbName.Text;
            publishGroup.ImageId                          = iGroupImage.BinaryFileId;
            publishGroup.PublishGroupStatus               = publishGroupStatus;
            publishGroup.Description                      = tbDescription.Text;
            publishGroup.EndDateTime                      = drPublishDates.UpperValue.Value;
            publishGroup.StartDateTime                    = drPublishDates.LowerValue.Value;
            publishGroup.WeeklyDayOfWeek                  = ddlDayOfWeek.SelectedValueAsEnumOrNull <DayOfWeek>();
            publishGroup.WeeklyTimeOfDay                  = tTimeOfDay.SelectedTime;
            publishGroup.CustomSchedule                   = tbCustomSchedule.Text;
            publishGroup.StartDate                        = dpStartDate.SelectedDate;
            publishGroup.MeetingLocation                  = tbLocationName.Text;
            publishGroup.IsHidden                         = cbIsHidden.Checked;
            publishGroup.RegistrationRequirement          = ( RegistrationRequirement )ddlRegistration.SelectedValue.AsInteger();
            publishGroup.RequiresRegistration             = ddlRegistration.SelectedValue.AsInteger() > 0; //This is obsolete but left in for backward compatability
            publishGroup.RegistrationLink                 = publishGroup.RegistrationRequirement == RegistrationRequirement.CustomRegistration ? tbRegistrationLink.Text : "";
            publishGroup.RegistrationDescription          = tbRegistrationDetails.Text;
            publishGroup.ChildcareRegistrationDescription = ddlChildcareNeedRegistration.SelectedValue == "2" ? tbChildcareRegistrationDetails.Text : "";
            publishGroup.AllowSpouseRegistration          = cbAllowSpouseRegistration.Checked;
            publishGroup.ChildcareOptions                 = ( ChildcareOptions )ddlChildcareOptions.SelectedValue.AsInteger();
            publishGroup.ChildcareAvailable               = ddlChildcareOptions.SelectedValue.AsInteger() > 0;
            publishGroup.ChildcareRegistrationLink        = publishGroup.ChildcareAvailable ? tbChildcareRegistrationLink.Text : "";
            publishGroup.AudienceValues                   = GetSelectedAudiences(rockContext);
            publishGroup.ContactPersonAliasId             = pContactPerson.PersonAliasId.Value;
            publishGroup.RequestorAliasId                 = CurrentPersonAliasId.Value;
            publishGroup.ContactEmail                     = tbContactEmail.Text;
            publishGroup.ContactPhoneNumber               = tbContactPhoneNumber.Text;
            publishGroup.ConfirmationFromName             = tbConfirmationFromName.Text;
            publishGroup.ConfirmationEmail                = tbConfirmationFromEmail.Text;
            publishGroup.ConfirmationSubject              = tbConfirmationSubject.Text;
            publishGroup.ConfirmationBody                 = ceConfirmationBody.Text;

            if (publishGroup.Id == 0)
            {
                publishGroupService.Add(publishGroup);
            }

            if (isApprover && publishGroupStatus == PublishGroupStatus.Approved)
            {
                publishGroup.Group.IsActive = true;
                publishGroup.Group.IsPublic = true;
                //remove all other publish groups for this computer
                publishGroupService.DeleteRange(publishGroupService.Queryable().Where(pg => pg.GroupId == publishGroup.GroupId && pg.Id != publishGroup.Id));
            }
            ;

            //Set the binary file to not be temporary
            if (publishGroup.ImageId.HasValue)
            {
                BinaryFileService binaryFileService = new BinaryFileService(rockContext);
                var binaryFile = binaryFileService.Get(publishGroup.ImageId.Value);
                if (binaryFile != null)
                {
                    binaryFile.IsTemporary = false;
                }
            }

            rockContext.SaveChanges();

            publishGroup.LoadAttributes(rockContext);

            if (publishGroup.Attributes.Any())
            {
                Rock.Attribute.Helper.GetEditValues(phAttributeEdits, publishGroup);
                publishGroup.SaveAttributeValues(rockContext);
            }

            if (publishGroup.PublishGroupStatus != PublishGroupStatus.Draft)
            {
                publishGroup.LaunchWorkflow(GetAttributeValue(AttributeKeys.Workflow).AsGuidOrNull());
            }

            NavigateToParentPage(new Dictionary <string, string> {
                { "GroupId", publishGroup.GroupId.ToString() }
            });
        }