コード例 #1
0
        /// <summary>
        /// Creates the prayer request.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="person">The person.</param>
        private void CreatePrayerRequest(RockContext rockContext, Person person)
        {
            if (person != null && !tbPrayerRequests.Text.IsNullOrWhiteSpace())
            {
                PrayerRequest prayerRequest = new PrayerRequest();
                prayerRequest.RequestedByPersonAliasId = person.PrimaryAliasId;
                prayerRequest.FirstName = person.NickName;
                prayerRequest.LastName  = person.LastName;
                prayerRequest.Text      = tbPrayerRequests.Text;
                prayerRequest.Email     = person.Email;

                Category category;
                Guid     defaultCategoryGuid = GetAttributeValue("PrayerCategory").AsGuid();
                if (!defaultCategoryGuid.IsEmpty())
                {
                    category = new CategoryService(rockContext).Get(defaultCategoryGuid);
                    prayerRequest.CategoryId = category.Id;
                    prayerRequest.Category   = category;
                }

                prayerRequest.IsPublic = false;

                PrayerRequestService prayerRequestService = new PrayerRequestService(rockContext);
                prayerRequestService.Add(prayerRequest);
                prayerRequest.EnteredDateTime = RockDateTime.Now;
                rockContext.SaveChanges();
            }
        }
コード例 #2
0
        /// <summary>
        /// Saves the prayer request.
        /// </summary>
        private void SaveRequest()
        {
            PrayerRequest        prayerRequest;
            PrayerRequestService prayerRequestService = new PrayerRequestService();

            int prayerRequestId = int.Parse(hfPrayerRequestId.Value);

            // Fetch the prayer request or create a new one if needed
            if (prayerRequestId == 0)
            {
                prayerRequest = new PrayerRequest();
                prayerRequestService.Add(prayerRequest, CurrentPersonId);
                prayerRequest.EnteredDate = DateTime.Now;
            }
            else
            {
                prayerRequest = prayerRequestService.Get(prayerRequestId);
            }

            // If changing from NOT approved to approved, record who and when
            if (!(prayerRequest.IsApproved ?? false) && cbApproved.Checked)
            {
                prayerRequest.ApprovedByPersonId = CurrentPerson.Id;
                prayerRequest.ApprovedOnDate     = DateTime.Now;
                // reset the flag count only to zero ONLY if it had a value previously.
                if (prayerRequest.FlagCount.HasValue && prayerRequest.FlagCount > 0)
                {
                    prayerRequest.FlagCount = 0;
                }
            }
            // Now record all the bits...
            prayerRequest.IsApproved    = cbApproved.Checked;
            prayerRequest.IsActive      = cbIsActive.Checked;
            prayerRequest.IsUrgent      = cbIsUrgent.Checked;
            prayerRequest.AllowComments = cbAllowComments.Checked;
            prayerRequest.IsPublic      = cbIsPublic.Checked;
            prayerRequest.CategoryId    = cpCategory.SelectedValueAsInt();
            prayerRequest.FirstName     = tbFirstName.Text;
            prayerRequest.LastName      = tbLastName.Text;
            prayerRequest.Text          = tbText.Text;
            prayerRequest.Answer        = tbAnswer.Text;

            if (!Page.IsValid)
            {
                return;
            }

            if (!prayerRequest.IsValid)
            {
                // field controls render error messages
                return;
            }

            prayerRequestService.Save(prayerRequest, CurrentPersonId);

            NavigateToParentPage();
        }
コード例 #3
0
        private void submitPrayer(PersonAlias personAlias, string prayerRequest, RockContext rockContext)
        {
            var prayerService = new PrayerRequestService(rockContext);

            // Parse out
            if (prayerRequest.StartsWith("3"))
            {
                prayerRequest = prayerRequest.Substring(1, prayerRequest.Length - 1);
            }
            prayerService.Add(new PrayerRequest
            {
                EnteredDateTime        = RockDateTime.Now,
                CreatedDateTime        = RockDateTime.Now,
                ExpirationDate         = RockDateTime.Now.AddYears(1),
                Text                   = prayerRequest,
                RequestedByPersonAlias = personAlias,
                IsActive               = true,
                AllowComments          = true,
                FirstName              = personAlias.Person.FirstName,
                LastName               = personAlias.Person.LastName
            });
            rockContext.SaveChanges();
        }
コード例 #4
0
        /// <summary>
        /// Handles the Click event to save the prayer request.
        /// </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)
        {
            if (!IsValid())
            {
                return;
            }

            bool isAutoApproved          = GetAttributeValue("EnableAutoApprove").AsBoolean();
            bool defaultAllowComments    = GetAttributeValue("DefaultAllowCommentsSetting").AsBoolean();
            bool isPersonMatchingEnabled = GetAttributeValue("EnablePersonMatching").AsBoolean();

            PrayerRequest prayerRequest = new PrayerRequest {
                Id = 0, IsActive = true, IsApproved = isAutoApproved, AllowComments = defaultAllowComments
            };

            var rockContext = new RockContext();

            prayerRequest.EnteredDateTime = RockDateTime.Now;

            if (isAutoApproved)
            {
                prayerRequest.ApprovedByPersonAliasId = CurrentPersonAliasId;
                prayerRequest.ApprovedOnDateTime      = RockDateTime.Now;
                var expireDays = Convert.ToDouble(GetAttributeValue("ExpireDays"));
                prayerRequest.ExpirationDate = RockDateTime.Now.AddDays(expireDays);
            }

            // Now record all the bits...
            // Make sure the Category is hydrated so it's included for any Lava processing
            Category category;
            int?     categoryId          = bddlCategory.SelectedValueAsInt();
            Guid     defaultCategoryGuid = GetAttributeValue("DefaultCategory").AsGuid();

            if (categoryId == null && !defaultCategoryGuid.IsEmpty())
            {
                category   = new CategoryService(rockContext).Get(defaultCategoryGuid);
                categoryId = category.Id;
            }
            else
            {
                category = new CategoryService(rockContext).Get(categoryId.Value);
            }

            prayerRequest.CategoryId = categoryId;
            prayerRequest.Category   = category;

            var personContext = this.ContextEntity <Person>();

            if (personContext == null)
            {
                Person person = null;
                if (isPersonMatchingEnabled)
                {
                    var personService = new PersonService(new RockContext());
                    person = personService.FindPerson(new PersonService.PersonMatchQuery(tbFirstName.Text, tbLastName.Text, tbEmail.Text, pnbPhone.Number), false, true, false);

                    if (person == null && (!string.IsNullOrWhiteSpace(tbEmail.Text) || !string.IsNullOrWhiteSpace(PhoneNumber.CleanNumber(pnbPhone.Number))))
                    {
                        var personRecordTypeId  = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.PERSON_RECORD_TYPE_PERSON.AsGuid()).Id;
                        var personStatusPending = DefinedValueCache.Get(Rock.SystemGuid.DefinedValue.PERSON_RECORD_STATUS_PENDING.AsGuid()).Id;

                        person                     = new Person();
                        person.IsSystem            = false;
                        person.RecordTypeValueId   = personRecordTypeId;
                        person.RecordStatusValueId = personStatusPending;
                        person.FirstName           = tbFirstName.Text;
                        person.LastName            = tbLastName.Text;
                        person.Gender              = Gender.Unknown;

                        if (!string.IsNullOrWhiteSpace(tbEmail.Text))
                        {
                            person.Email           = tbEmail.Text;
                            person.IsEmailActive   = true;
                            person.EmailPreference = EmailPreference.EmailAllowed;
                        }

                        PersonService.SaveNewPerson(person, rockContext, cpCampus.SelectedCampusId);

                        if (!string.IsNullOrWhiteSpace(PhoneNumber.CleanNumber(pnbPhone.Number)))
                        {
                            var mobilePhoneType = DefinedValueCache.Get(new Guid(Rock.SystemGuid.DefinedValue.PERSON_PHONE_TYPE_MOBILE));

                            var phoneNumber = new PhoneNumber {
                                NumberTypeValueId = mobilePhoneType.Id
                            };
                            phoneNumber.CountryCode = PhoneNumber.CleanNumber(pnbPhone.CountryCode);
                            phoneNumber.Number      = PhoneNumber.CleanNumber(pnbPhone.Number);
                            person.PhoneNumbers.Add(phoneNumber);
                        }
                    }
                }

                prayerRequest.FirstName = tbFirstName.Text;
                prayerRequest.LastName  = tbLastName.Text;
                prayerRequest.Email     = tbEmail.Text;
                if (person != null)
                {
                    prayerRequest.RequestedByPersonAliasId = person.PrimaryAliasId;
                }
                else
                {
                    prayerRequest.RequestedByPersonAliasId = CurrentPersonAliasId;
                }
            }
            else
            {
                prayerRequest.RequestedByPersonAliasId = personContext.PrimaryAliasId;
                prayerRequest.FirstName = string.IsNullOrEmpty(personContext.NickName) ? personContext.FirstName : personContext.NickName;
                prayerRequest.LastName  = personContext.LastName;
                prayerRequest.Email     = personContext.Email;
            }

            prayerRequest.CampusId = cpCampus.SelectedCampusId;

            prayerRequest.Text = dtbRequest.Text;

            if (this.EnableUrgentFlag)
            {
                prayerRequest.IsUrgent = cbIsUrgent.Checked;
            }
            else
            {
                prayerRequest.IsUrgent = false;
            }

            if (this.EnableCommentsFlag)
            {
                prayerRequest.AllowComments = cbAllowComments.Checked;
            }

            if (this.EnablePublicDisplayFlag)
            {
                prayerRequest.IsPublic = cbAllowPublicDisplay.Checked;
            }
            else
            {
                prayerRequest.IsPublic = this.DefaultToPublic;
            }

            if (!Page.IsValid)
            {
                return;
            }

            PrayerRequestService prayerRequestService = new PrayerRequestService(rockContext);

            prayerRequestService.Add(prayerRequest);
            prayerRequest.LoadAttributes(rockContext);
            Rock.Attribute.Helper.GetEditValues(phAttributes, prayerRequest);

            if (!prayerRequest.IsValid)
            {
                // field controls render error messages
                return;
            }

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


            StartWorkflow(prayerRequest, rockContext);

            bool isNavigateToParent = GetAttributeValue("NavigateToParentOnSave").AsBoolean();

            if (isNavigateToParent)
            {
                NavigateToParentPage();
            }
            else if (GetAttributeValue("RefreshPageOnSave").AsBoolean())
            {
                NavigateToCurrentPage(this.PageParameters().Where(a => a.Value is string).ToDictionary(k => k.Key, v => v.Value.ToString()));
            }
            else
            {
                pnlForm.Visible    = false;
                pnlReceipt.Visible = true;

                // Build success text that is Lava capable
                var mergeFields = Rock.Lava.LavaHelper.GetCommonMergeFields(this.RockPage, this.CurrentPerson);
                mergeFields.Add("PrayerRequest", prayerRequest);
                nbMessage.Text = GetAttributeValue("SaveSuccessText").ResolveMergeFields(mergeFields);

                // Resolve any dynamic url references
                string appRoot   = ResolveRockUrl("~/");
                string themeRoot = ResolveRockUrl("~~/");
                nbMessage.Text = nbMessage.Text.Replace("~~/", themeRoot).Replace("~/", appRoot);
            }
        }
コード例 #5
0
        /// <summary>
        /// Handles the Click event to save the prayer request.
        /// </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)
        {
            if (!IsValid())
            {
                return;
            }

            bool isAutoApproved       = GetAttributeValue("EnableAutoApprove").AsBoolean();
            bool defaultAllowComments = GetAttributeValue("DefaultAllowCommentsSetting").AsBoolean();

            PrayerRequest prayerRequest = new PrayerRequest {
                Id = 0, IsActive = true, IsApproved = isAutoApproved, AllowComments = defaultAllowComments
            };

            var rockContext = new RockContext();
            PrayerRequestService prayerRequestService = new PrayerRequestService(rockContext);

            prayerRequestService.Add(prayerRequest);
            prayerRequest.EnteredDateTime = RockDateTime.Now;

            if (isAutoApproved)
            {
                prayerRequest.ApprovedByPersonAliasId = CurrentPersonAliasId;
                prayerRequest.ApprovedOnDateTime      = RockDateTime.Now;
                var expireDays = Convert.ToDouble(GetAttributeValue("ExpireDays"));
                prayerRequest.ExpirationDate = RockDateTime.Now.AddDays(expireDays);
            }

            // Now record all the bits...
            int? categoryId          = bddlCategory.SelectedValueAsInt();
            Guid defaultCategoryGuid = GetAttributeValue("DefaultCategory").AsGuid();

            if (categoryId == null && !defaultCategoryGuid.IsEmpty())
            {
                var category = new CategoryService(rockContext).Get(defaultCategoryGuid);
                categoryId = category.Id;
            }

            prayerRequest.CategoryId = categoryId;
            prayerRequest.RequestedByPersonAliasId = CurrentPersonAliasId;
            prayerRequest.FirstName = dtbFirstName.Text;
            prayerRequest.LastName  = dtbLastName.Text;
            prayerRequest.Email     = dtbEmail.Text;
            prayerRequest.Text      = dtbRequest.Text;

            if (this.EnableUrgentFlag)
            {
                prayerRequest.IsUrgent = cbIsUrgent.Checked;
            }
            else
            {
                prayerRequest.IsUrgent = false;
            }

            if (this.EnableCommentsFlag)
            {
                prayerRequest.AllowComments = cbAllowComments.Checked;
            }

            if (this.EnablePublicDisplayFlag)
            {
                prayerRequest.IsPublic = cbAllowPublicDisplay.Checked;
            }
            else
            {
                prayerRequest.IsPublic = false;
            }

            if (!Page.IsValid)
            {
                return;
            }

            if (!prayerRequest.IsValid)
            {
                // field controls render error messages
                return;
            }

            rockContext.SaveChanges();

            bool isNavigateToParent = GetAttributeValue("NavigateToParentOnSave").AsBoolean();

            if (isNavigateToParent)
            {
                NavigateToParentPage();
            }
            else
            {
                pnlForm.Visible    = false;
                pnlReceipt.Visible = true;
            }
        }
コード例 #6
0
        /// <summary>
        /// Saves the prayer request.
        /// </summary>
        private void SaveRequest()
        {
            var                  rockContext = new RockContext();
            PrayerRequest        prayerRequest;
            PrayerRequestService prayerRequestService = new PrayerRequestService(rockContext);

            int prayerRequestId = hfPrayerRequestId.Value.AsInteger();

            // Fetch the prayer request or create a new one if needed
            if (prayerRequestId == 0)
            {
                prayerRequest = new PrayerRequest();
                prayerRequestService.Add(prayerRequest);
                prayerRequest.EnteredDateTime = RockDateTime.Now;
            }
            else
            {
                prayerRequest = prayerRequestService.Get(prayerRequestId);
            }

            if (ppRequestor.PersonId.HasValue)
            {
                prayerRequest.RequestedByPersonAliasId = ppRequestor.PersonAliasId;
            }

            // If changing from NOT-approved to approved, record who and when
            if (!(prayerRequest.IsApproved ?? false) && hfApprovedStatus.Value.AsBoolean())
            {
                prayerRequest.ApprovedByPersonAliasId = CurrentPersonAliasId;
                prayerRequest.ApprovedOnDateTime      = RockDateTime.Now;

                // reset the flag count only to zero ONLY if it had a value previously.
                if (prayerRequest.FlagCount.HasValue && prayerRequest.FlagCount > 0)
                {
                    prayerRequest.FlagCount = 0;
                }
            }

            // If no expiration date was manually set, then use the default setting.
            if (!dpExpirationDate.SelectedDate.HasValue)
            {
                var expireDays = Convert.ToDouble(GetAttributeValue("ExpireDays"));
                prayerRequest.ExpirationDate = RockDateTime.Now.AddDays(expireDays);
            }
            else
            {
                prayerRequest.ExpirationDate = dpExpirationDate.SelectedDate;
            }

            prayerRequest.CampusId   = cpCampus.SelectedCampusId;
            prayerRequest.CategoryId = catpCategory.SelectedValueAsInt();

            // Now record all the bits...
            prayerRequest.IsApproved    = hfApprovedStatus.Value.AsBoolean();
            prayerRequest.IsActive      = cbIsActive.Checked;
            prayerRequest.IsUrgent      = cbIsUrgent.Checked;
            prayerRequest.AllowComments = cbAllowComments.Checked;
            prayerRequest.IsPublic      = cbIsPublic.Checked;
            prayerRequest.FirstName     = tbFirstName.Text;
            prayerRequest.LastName      = tbLastName.Text;
            prayerRequest.Email         = tbEmail.Text;
            prayerRequest.Text          = dtbText.Text.Trim();
            prayerRequest.Answer        = dtbAnswer.Text.Trim();

            prayerRequest.LoadAttributes(rockContext);
            Rock.Attribute.Helper.GetEditValues(phAttributes, prayerRequest);

            if (!Page.IsValid)
            {
                return;
            }

            if (!prayerRequest.IsValid)
            {
                // field controls render error messages
                return;
            }

            rockContext.SaveChanges();
            prayerRequest.SaveAttributeValues(rockContext);

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

            if (!string.IsNullOrWhiteSpace(PageParameter("PersonId")))
            {
                queryParms.Add("PersonId", PageParameter("PersonId"));
            }

            NavigateToParentPage(queryParms);
        }
コード例 #7
0
        /// <summary>
        /// Executes the action.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="action">The workflow action.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="errorMessages">The error messages.</param>
        /// <returns></returns>
        public override bool Execute(RockContext rockContext, WorkflowAction action, Object entity, out List <string> errorMessages)
        {
            errorMessages = new List <string>();

            // stand up all the vars
            var      expireDays             = GetAttributeValue(action, "ExpireDays").AsDouble();
            int?     categoryId             = null;
            bool?    allowComments          = null;
            bool?    isUrgent               = null;
            bool?    isPublic               = null;
            Person   person                 = null;
            int?     requestorPersonAliasId = null;
            var      requestFirstName       = "Anonymous";
            var      requestLastName        = string.Empty;
            var      requestEmail           = string.Empty;
            int?     requestCampusId        = null;
            var      requestText            = string.Empty;
            var      isApproved             = GetAttributeValue(action, "Approved").AsBoolean();
            var      expirationDate         = RockDateTime.Now.AddDays(expireDays);
            DateTime?dateApproved           = null;
            int?     approvedPersonAliasId  = null;

            // get person
            Guid?personAttributeGuid = GetAttributeValue(action, "Person").AsGuidOrNull();

            if (personAttributeGuid.HasValue)
            {
                Guid?personAliasGuid = action.GetWorkflowAttributeValue(personAttributeGuid.Value).AsGuidOrNull();
                if (personAliasGuid.HasValue)
                {
                    var personAlias = new PersonAliasService(rockContext).Get(personAliasGuid.Value);
                    if (personAlias != null)
                    {
                        person = personAlias.Person;
                    }
                }
            }

            // get name and campus info
            if (person != null)
            {
                requestorPersonAliasId = person.PrimaryAliasId;
                requestFirstName       = (!string.IsNullOrWhiteSpace(person.NickName)) ? person.NickName : person.LastName; // in case it was a business
                requestLastName        = person.LastName;
                requestEmail           = person.Email;
                if (person.GetCampusIds().Any())
                {
                    requestCampusId = person.GetCampusIds().FirstOrDefault();
                }
            }
            else
            {
                Guid?firstNameAttributeGuid = GetAttributeValue(action, "FirstName").AsGuidOrNull();
                if (firstNameAttributeGuid.HasValue)
                {
                    var firstName = action.GetWorkflowAttributeValue(firstNameAttributeGuid.Value);
                    if (!string.IsNullOrWhiteSpace(firstName))
                    {
                        requestFirstName = firstName;
                    }
                }

                Guid?lastNameAttributeGuid = GetAttributeValue(action, "LastName").AsGuidOrNull();
                if (lastNameAttributeGuid.HasValue)
                {
                    var lastName = action.GetWorkflowAttributeValue(lastNameAttributeGuid.Value);
                    if (!string.IsNullOrWhiteSpace(lastName))
                    {
                        requestLastName = lastName;
                    }
                }

                Guid?emailAttributeGuid = GetAttributeValue(action, "Email").AsGuidOrNull();
                if (emailAttributeGuid.HasValue)
                {
                    var email = action.GetWorkflowAttributeValue(emailAttributeGuid.Value);
                    if (!string.IsNullOrWhiteSpace(email))
                    {
                        requestEmail = email;
                    }
                }

                Guid?campusAttributeGuid = GetAttributeValue(action, "Campus").AsGuidOrNull();
                if (campusAttributeGuid.HasValue)
                {
                    var campus = action.GetWorkflowAttributeValue(campusAttributeGuid.Value).AsGuidOrNull();
                    if (campus.HasValue)
                    {
                        requestCampusId = CampusCache.Get(campus.Value).Id;
                    }
                }
            }

            // get prayer request text
            Guid?requestTextAttributeGuid = GetAttributeValue(action, "Request").AsGuidOrNull();

            if (requestTextAttributeGuid.HasValue)
            {
                var requestAttributeText = action.GetWorkflowAttributeValue(requestTextAttributeGuid.Value);
                if (!string.IsNullOrWhiteSpace(requestAttributeText))
                {
                    requestText = requestAttributeText;
                }
            }

            // get category
            Guid?cateogryAttributeGuid = GetAttributeValue(action, "Category").AsGuidOrNull();

            if (cateogryAttributeGuid.HasValue)
            {
                var categoryGuid = action.GetWorkflowAttributeValue(cateogryAttributeGuid.Value).AsGuidOrNull();
                if (categoryGuid.HasValue)
                {
                    categoryId = CategoryCache.Get(categoryGuid.Value).Id;
                }
            }

            // get allow comments
            Guid?allowCommentsAttributeGuid = GetAttributeValue(action, "AllowComments").AsGuidOrNull();

            if (allowCommentsAttributeGuid.HasValue)
            {
                var commentsAllowed = action.GetWorkflowAttributeValue(allowCommentsAttributeGuid.Value).AsBooleanOrNull();
                if (commentsAllowed.HasValue)
                {
                    allowComments = commentsAllowed;
                }
            }

            // get is urgent
            Guid?isUrgentAttributeGuid = GetAttributeValue(action, "IsUrgent").AsGuidOrNull();

            if (isUrgentAttributeGuid.HasValue)
            {
                var urgent = action.GetWorkflowAttributeValue(isUrgentAttributeGuid.Value).AsBooleanOrNull();
                if (urgent.HasValue)
                {
                    isUrgent = urgent;
                }
            }

            // get is public
            Guid?isPublicAttributeGuid = GetAttributeValue(action, "IsPublic").AsGuidOrNull();

            if (isPublicAttributeGuid.HasValue)
            {
                var publicValue = action.GetWorkflowAttributeValue(isPublicAttributeGuid.Value).AsBooleanOrNull();
                if (publicValue.HasValue)
                {
                    isPublic = publicValue;
                }
            }

            // mark as approved if needed
            if (isApproved)
            {
                dateApproved          = RockDateTime.Now;
                approvedPersonAliasId = requestorPersonAliasId;
            }

            // test for possible errors and fail gracefully
            if (string.IsNullOrWhiteSpace(requestFirstName))
            {
                errorMessages.Add("A first name is required.");
                return(true);
            }

            if (string.IsNullOrWhiteSpace(requestText))
            {
                errorMessages.Add("The prayer request text is required.");
                return(true);
            }

            // create the request
            var request = new PrayerRequest
            {
                RequestedByPersonAliasId = requestorPersonAliasId,
                FirstName               = requestFirstName,
                LastName                = requestLastName,
                Email                   = requestEmail,
                CampusId                = requestCampusId,
                IsActive                = true,
                IsApproved              = isApproved,
                Text                    = requestText,
                EnteredDateTime         = RockDateTime.Now,
                ExpirationDate          = expirationDate,
                CreatedDateTime         = RockDateTime.Now,
                ApprovedOnDateTime      = dateApproved,
                CreatedByPersonAliasId  = requestorPersonAliasId,
                ApprovedByPersonAliasId = approvedPersonAliasId,
                CategoryId              = categoryId,
                AllowComments           = allowComments,
                IsUrgent                = isUrgent,
                IsPublic                = isPublic,
                Answer                  = string.Empty
            };

            // add the request
            var prayerRequestService = new PrayerRequestService(rockContext);

            prayerRequestService.Add(request);

            // save the request
            rockContext.WrapTransaction(() =>
            {
                rockContext.SaveChanges();
            });

            if (request.Guid != null)
            {
                // get the attribute to store the request guid
                var prayerRequestAttributeGuid = GetAttributeValue(action, "PrayerRequest").AsGuidOrNull();
                if (prayerRequestAttributeGuid.HasValue)
                {
                    var prayerRequestAttribute = AttributeCache.Get(prayerRequestAttributeGuid.Value, rockContext);
                    if (prayerRequestAttribute != null)
                    {
                        if (prayerRequestAttribute.FieldTypeId == FieldTypeCache.Get(Rock.SystemGuid.FieldType.TEXT.AsGuid(), rockContext).Id)
                        {
                            SetWorkflowAttributeValue(action, prayerRequestAttributeGuid.Value, request.Guid.ToString());
                        }
                    }
                }
            }

            return(true);
        }
コード例 #8
0
        /// <summary>
        /// Saves the prayer request.
        /// </summary>
        private void SaveRequest()
        {
            bool isAutoApproved       = GetAttributeValue("EnableAutoApprove").AsBoolean();
            bool defaultAllowComments = GetAttributeValue("DefaultAllowCommentsSetting").AsBoolean();

            PrayerRequest prayerRequest = new PrayerRequest {
                Id = 0, IsActive = true, IsApproved = isAutoApproved, AllowComments = defaultAllowComments
            };

            PrayerRequestService prayerRequestService = new PrayerRequestService();

            prayerRequestService.Add(prayerRequest, CurrentPersonId);
            prayerRequest.EnteredDate = DateTime.Now;

            // If changing from NOT approved to approved, record who and when
            if (isAutoApproved)
            {
                prayerRequest.ApprovedByPersonId = CurrentPerson.Id;
                prayerRequest.ApprovedOnDate     = DateTime.Now;
            }

            // Now record all the bits...
            prayerRequest.CategoryId = rblCategory.SelectedValueAsInt();
            prayerRequest.FirstName  = tbFirstName.Text;
            prayerRequest.LastName   = tbLastName.Text;
            prayerRequest.Text       = txtRequest.Text;

            if (enableUrgentFlag)
            {
                prayerRequest.IsUrgent = cbIsUrgent.Checked;
            }

            if (enableCommentsFlag)
            {
                prayerRequest.AllowComments = cbAllowComments.Checked;
            }

            if (enablePublicDisplayFlag)
            {
                prayerRequest.IsPublic = cbAllowPublicDisplay.Checked;
            }

            if (!Page.IsValid)
            {
                return;
            }

            if (!prayerRequest.IsValid)
            {
                // field controls render error messages
                return;
            }

            prayerRequestService.Save(prayerRequest, CurrentPersonId);

            bool isNavigateToParent = GetAttributeValue("NavigateToParentOnSave").AsBoolean();

            if (isNavigateToParent)
            {
                NavigateToParentPage();
            }
            else
            {
                pnlForm.Visible    = false;
                pnlReceipt.Visible = true;
            }
        }
コード例 #9
0
        /// <summary>
        /// Saves the prayer request.
        /// </summary>
        private void SaveRequest()
        {
            var                  rockContext = new RockContext();
            PrayerRequest        prayerRequest;
            PrayerRequestService prayerRequestService = new PrayerRequestService(rockContext);

            int prayerRequestId = int.Parse(hfPrayerRequestId.Value);

            // Fetch the prayer request or create a new one if needed
            if (prayerRequestId == 0)
            {
                prayerRequest = new PrayerRequest();
                prayerRequestService.Add(prayerRequest);
                prayerRequest.EnteredDateTime = RockDateTime.Now;
            }
            else
            {
                prayerRequest = prayerRequestService.Get(prayerRequestId);
            }

            // If changing from NOT-approved to approved, record who and when
            if (!(prayerRequest.IsApproved ?? false) && cbApproved.Checked)
            {
                prayerRequest.ApprovedByPersonId = CurrentPerson.Id;
                prayerRequest.ApprovedOnDateTime = RockDateTime.Now;

                // reset the flag count only to zero ONLY if it had a value previously.
                if (prayerRequest.FlagCount.HasValue && prayerRequest.FlagCount > 0)
                {
                    prayerRequest.FlagCount = 0;
                }
            }

            // If no expiration date was manually set, then use the default setting.
            if (!dpExpirationDate.SelectedDate.HasValue)
            {
                var expireDays = Convert.ToDouble(GetAttributeValue("ExpireDays"));
                prayerRequest.ExpirationDate = RockDateTime.Now.AddDays(expireDays);
            }
            else
            {
                prayerRequest.ExpirationDate = dpExpirationDate.SelectedDate;
            }

            // If no category was selected, then use the default category if there is one.
            int? categoryId          = catpCategory.SelectedValueAsInt();
            Guid defaultCategoryGuid = GetAttributeValue("DefaultCategory").AsGuid();

            if (categoryId == null && !defaultCategoryGuid.IsEmpty())
            {
                var category = new CategoryService(rockContext).Get(defaultCategoryGuid);
                categoryId = category.Id;
            }

            prayerRequest.CategoryId = categoryId;

            // Now record all the bits...
            prayerRequest.IsApproved    = cbApproved.Checked;
            prayerRequest.IsActive      = cbIsActive.Checked;
            prayerRequest.IsUrgent      = cbIsUrgent.Checked;
            prayerRequest.AllowComments = cbAllowComments.Checked;
            prayerRequest.IsPublic      = cbIsPublic.Checked;
            prayerRequest.FirstName     = dtbFirstName.Text;
            prayerRequest.LastName      = dtbLastName.Text;
            prayerRequest.Text          = dtbText.Text.Trim();
            prayerRequest.Answer        = dtbAnswer.Text.Trim();

            if (!Page.IsValid)
            {
                return;
            }

            if (!prayerRequest.IsValid)
            {
                // field controls render error messages
                return;
            }

            rockContext.SaveChanges();

            NavigateToParentPage();
        }
コード例 #10
0
        /// <summary>
        /// Saves the prayer request.
        /// </summary>
        /// <param name="parameters">The parameters.</param>
        /// <returns>The response to send back to the client.</returns>
        private CallbackResponse SaveRequest(Dictionary <string, object> parameters)
        {
            using (var rockContext = new RockContext())
            {
                var           prayerRequestService = new PrayerRequestService(rockContext);
                PrayerRequest prayerRequest;
                var           requestGuid = RequestContext.GetPageParameter(PageParameterKeys.RequestGuid).AsGuidOrNull();

                if (requestGuid.HasValue)
                {
                    prayerRequest = prayerRequestService.Get(requestGuid.Value);

                    if (prayerRequest == null || !BlockCache.IsAuthorized(Authorization.EDIT, RequestContext.CurrentPerson))
                    {
                        return(new CallbackResponse
                        {
                            Error = "You are not authorized to edit prayer requests."
                        });
                    }
                }
                else
                {
                    int?categoryId = null;

                    if (DefaultCategory.HasValue)
                    {
                        categoryId = CategoryCache.Get(DefaultCategory.Value).Id;
                    }

                    prayerRequest = new PrayerRequest
                    {
                        Id              = 0,
                        IsActive        = true,
                        IsApproved      = EnableAutoApprove,
                        AllowComments   = false,
                        EnteredDateTime = RockDateTime.Now,
                        CategoryId      = categoryId
                    };
                    prayerRequestService.Add(prayerRequest);

                    if (EnableAutoApprove)
                    {
                        prayerRequest.ApprovedByPersonAliasId = RequestContext.CurrentPerson?.PrimaryAliasId;
                        prayerRequest.ApprovedOnDateTime      = RockDateTime.Now;
                        prayerRequest.ExpirationDate          = RockDateTime.Now.AddDays(ExpiresAfterDays);
                    }
                }

                prayerRequest.FirstName = ( string )parameters["firstName"];
                prayerRequest.LastName  = ( string )parameters["lastName"];
                prayerRequest.Email     = ( string )parameters["email"];
                prayerRequest.Text      = ( string )parameters["request"];

                if (ShowCampus)
                {
                    if (parameters.ContainsKey("campus"))
                    {
                        var campusGuid = (( string )parameters["campus"]).AsGuidOrNull();

                        if (campusGuid.HasValue)
                        {
                            prayerRequest.CampusId = CampusCache.Get(campusGuid.Value).Id;
                        }
                    }
                    else
                    {
                        prayerRequest.CampusId = CampusCache.All().FirstOrDefault(a => a.IsActive ?? false)?.Id;
                    }
                }

                if (ShowCategory && parameters.ContainsKey("category"))
                {
                    var categoryGuid = (( string )parameters["category"]).AsGuidOrNull();

                    if (categoryGuid.HasValue)
                    {
                        prayerRequest.CategoryId = CategoryCache.Get(categoryGuid.Value).Id;
                    }
                    else if (prayerRequest.Id > 0)
                    {
                        prayerRequest.CategoryId = null;
                    }
                }

                if (ShowPublicDisplayFlag)
                {
                    prayerRequest.IsPublic = ( bool )parameters["allowPublication"];
                }

                if (ShowUrgentFlag)
                {
                    prayerRequest.IsUrgent = ( bool )parameters["urgent"];
                }

                if (RequestContext.CurrentPerson != null)
                {
                    //
                    // If there is a logged in person and the names still match, meaning they are not
                    // entering a prayer request for somebody else, then set the requested by property.
                    //
                    var person = RequestContext.CurrentPerson;
                    if (prayerRequest.FirstName == person.FirstName && prayerRequest.LastName == person.LastName)
                    {
                        prayerRequest.RequestedByPersonAliasId = person.PrimaryAliasId;
                    }
                }
                else
                {
                    //
                    // If there is not a logged in person, try to match to an existing person.
                    //
                    var person = MatchPerson(prayerRequest, rockContext);

                    if (person != null)
                    {
                        prayerRequest.RequestedByPersonAliasId = person.PrimaryAliasId;
                    }
                }

                //
                // Save all changes to database.
                //
                rockContext.SaveChanges();

                StartWorkflow(prayerRequest, rockContext);
            }

            if (CompletionAction == 0)
            {
                return(new CallbackResponse
                {
                    Content = CompletionXaml ?? string.Empty
                });
            }
            else if (CompletionAction == 1)
            {
                return(new CallbackResponse
                {
                    Command = "PopPage",
                    CommandParameter = "true"
                });
            }
            else
            {
                return(new CallbackResponse
                {
                    Content = AttributeDefaults.CompletionXaml
                });
            }
        }
コード例 #11
0
        public override MobileBlockResponse HandleRequest(string request, Dictionary <string, string> Body)
        {
            body = Body;
            RockContext          rockContext          = new RockContext();
            PrayerRequestService prayerRequestService = new PrayerRequestService(rockContext);
            PrayerRequest        prayerRequest        = new PrayerRequest();

            prayerRequest.EnteredDateTime          = RockDateTime.Now;
            prayerRequest.FirstName                = GetItem("firstName");
            prayerRequest.LastName                 = GetItem("lastName");
            prayerRequest.Text                     = GetItem("request");
            prayerRequest.RequestedByPersonAliasId = CurrentPersonAliasId;

            if (!string.IsNullOrWhiteSpace(GetItem("campus")))
            {
                prayerRequest.CampusId = GetItem("campus").AsInteger();
            }

            bool isAutoApproved = GetAttributeValue("EnableAutoApprove").AsBoolean();

            if (isAutoApproved)
            {
                prayerRequest.ApprovedByPersonAliasId = CurrentPersonAliasId;
                prayerRequest.ApprovedOnDateTime      = RockDateTime.Now;
                var expireDays = GetAttributeValue("ExpireDays").AsDouble();
                prayerRequest.ExpirationDate = RockDateTime.Now.AddDays(expireDays);
            }

            //Category
            if (GetItem("category").AsInteger() != 0)
            {
                prayerRequest.CategoryId = GetItem("category").AsInteger();
            }
            else
            {
                Guid defaultCategoryGuid = GetAttributeValue("DefaultCategory").AsGuid();
                var  defaultCategory     = CategoryCache.Read(defaultCategoryGuid);
                if (defaultCategory != null)
                {
                    prayerRequest.CategoryId = defaultCategory.Id;
                }
            }

            if (GetItem("urgent").AsBoolean())
            {
                prayerRequest.IsUrgent = true;
            }
            else
            {
                prayerRequest.IsUrgent = false;
            }

            if (GetItem("allowComments").AsBoolean())
            {
                prayerRequest.AllowComments = true;
            }
            else
            {
                prayerRequest.AllowComments = false;
            }

            if (GetItem("allowPublication").AsBoolean())
            {
                prayerRequest.IsPublic = true;
            }
            else
            {
                prayerRequest.IsPublic = false;
            }
            prayerRequestService.Add(prayerRequest);
            rockContext.SaveChanges();

            Guid?workflowTypeGuid = GetAttributeValue("Workflow").AsGuidOrNull();

            if (workflowTypeGuid.HasValue)
            {
                prayerRequest.LaunchWorkflow(workflowTypeGuid, prayerRequest.Name);
            }

            AvalancheUtilities.SetActionItems(GetAttributeValue("ActionItem"),
                                              CustomAttributes,
                                              CurrentPerson,
                                              AvalancheUtilities.GetMergeFields(CurrentPerson));

            var response = new FormResponse
            {
                Success = true,
                Message = GetAttributeValue("SaveSuccessText")
            };

            if (CustomAttributes.ContainsKey("ActionType") && CustomAttributes["ActionType"] != "0")
            {
                response.ActionType = CustomAttributes["ActionType"];
            }

            if (CustomAttributes.ContainsKey("Resource"))
            {
                response.Resource = CustomAttributes["Resource"];
            }

            if (CustomAttributes.ContainsKey("Parameter"))
            {
                response.Parameter = CustomAttributes["Parameter"];
            }


            return(new MobileBlockResponse()
            {
                Request = request,
                Response = JsonConvert.SerializeObject(response),
                TTL = 0
            });
        }
コード例 #12
0
        /// <summary>
        /// Executes the specified workflow.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="action">The action.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="errorMessages">The error messages.</param>
        /// <returns></returns>
        public override bool Execute(RockContext rockContext, WorkflowAction action, Object entity, out List <string> errorMessages)
        {
            errorMessages = new List <string>();

            // determine the person
            Person person          = null;
            var    personAliasGuid = GetAttributeValue(action, "Person", true).AsGuidOrNull();

            {
                person = new PersonAliasService(rockContext).Queryable()
                         .Where(a => a.Guid.Equals(personAliasGuid.Value))
                         .Select(a => a.Person)
                         .FirstOrDefault();
            }
            if (person == null || !person.PrimaryAliasId.HasValue)
            {
                errorMessages.Add("The Person for the prayer request could not be determined or found!");
            }

            // determine the contents of prayer request
            var requestText = GetAttributeValue(action, "PrayerRequestText", true);

            if (requestText.IsNullOrWhiteSpace())
            {
                errorMessages.Add("The contents of the prayer request could not be determined or found!");
            }

            // determine if public
            bool isPublic = GetAttributeValue(action, "Public", true).AsBoolean();

            // determine the campus
            CampusCache campus = CampusCache.Read(GetAttributeValue(action, "Campus", true).AsGuid());

            // Add request
            if (!errorMessages.Any())
            {
                var requestService = new PrayerRequestService(rockContext);

                PrayerRequest prayerRequest = new PrayerRequest {
                    Id = 0, IsActive = true, IsApproved = false, AllowComments = false
                };
                requestService.Add(prayerRequest);
                prayerRequest.EnteredDateTime          = RockDateTime.Now;
                prayerRequest.RequestedByPersonAliasId = person.PrimaryAliasId;
                prayerRequest.FirstName = person.NickName;
                prayerRequest.LastName  = person.LastName;
                prayerRequest.Email     = person.Email;
                prayerRequest.Text      = requestText;
                prayerRequest.IsPublic  = isPublic;
                prayerRequest.CampusId  = campus != null ? campus.Id : (int?)null;

                var categoryGuid = GetAttributeValue(action, "Category").AsGuidOrNull();
                if (categoryGuid.HasValue)
                {
                    prayerRequest.CategoryId = new CategoryService(rockContext).Get(categoryGuid.Value)?.Id;
                }

                rockContext.SaveChanges();

                if (prayerRequest.Id > 0)
                {
                    string resultValue = prayerRequest.Id.ToString();
                    var    attribute   = SetWorkflowAttributeValue(action, "ResultAttribute", resultValue);
                    if (attribute != null)
                    {
                        action.AddLogEntry(string.Format("Set '{0}' attribute to '{1}'.", attribute.Name, resultValue));
                    }
                }
            }

            errorMessages.ForEach(m => action.AddLogEntry(m, true));

            return(!errorMessages.Any());
        }
コード例 #13
0
        /// <summary>
        /// Handles the Click event to save the prayer request.
        /// </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)
        {
            if (!IsValid())
            {
                return;
            }

            bool isAutoApproved       = GetAttributeValue("EnableAutoApprove").AsBoolean();
            bool defaultAllowComments = GetAttributeValue("DefaultAllowCommentsSetting").AsBoolean();

            PrayerRequest prayerRequest = new PrayerRequest {
                Id = 0, IsActive = true, IsApproved = isAutoApproved, AllowComments = defaultAllowComments
            };

            var rockContext = new RockContext();
            PrayerRequestService prayerRequestService = new PrayerRequestService(rockContext);

            prayerRequestService.Add(prayerRequest);
            prayerRequest.EnteredDateTime = RockDateTime.Now;

            if (isAutoApproved)
            {
                prayerRequest.ApprovedByPersonAliasId = CurrentPersonAliasId;
                prayerRequest.ApprovedOnDateTime      = RockDateTime.Now;
                var expireDays = Convert.ToDouble(GetAttributeValue("ExpireDays"));
                prayerRequest.ExpirationDate = RockDateTime.Now.AddDays(expireDays);
            }

            // Now record all the bits...
            // Make sure the Category is hydrated so it's included for any Lava processing
            Category category;
            int?     categoryId          = bddlCategory.SelectedValueAsInt();
            Guid     defaultCategoryGuid = GetAttributeValue("DefaultCategory").AsGuid();

            if (categoryId == null && !defaultCategoryGuid.IsEmpty())
            {
                category   = new CategoryService(rockContext).Get(defaultCategoryGuid);
                categoryId = category.Id;
            }
            else
            {
                category = new CategoryService(rockContext).Get(categoryId.Value);
            }

            prayerRequest.CategoryId = categoryId;
            prayerRequest.Category   = category;

            var personContext = this.ContextEntity <Person>();

            if (personContext == null)
            {
                prayerRequest.RequestedByPersonAliasId = CurrentPersonAliasId;
                prayerRequest.FirstName = tbFirstName.Text;
                prayerRequest.LastName  = tbLastName.Text;
                prayerRequest.Email     = tbEmail.Text;
            }
            else
            {
                prayerRequest.RequestedByPersonAliasId = personContext.PrimaryAliasId;
                prayerRequest.FirstName = string.IsNullOrEmpty(personContext.NickName) ? personContext.FirstName : personContext.NickName;
                prayerRequest.LastName  = personContext.LastName;
                prayerRequest.Email     = personContext.Email;
            }

            prayerRequest.Text = dtbRequest.Text;

            if (this.EnableUrgentFlag)
            {
                prayerRequest.IsUrgent = cbIsUrgent.Checked;
            }
            else
            {
                prayerRequest.IsUrgent = false;
            }

            if (this.EnableCommentsFlag)
            {
                prayerRequest.AllowComments = cbAllowComments.Checked;
            }

            if (this.EnablePublicDisplayFlag)
            {
                prayerRequest.IsPublic = cbAllowPublicDisplay.Checked;
            }
            else
            {
                prayerRequest.IsPublic = false;
            }

            if (!Page.IsValid)
            {
                return;
            }

            if (!prayerRequest.IsValid)
            {
                // field controls render error messages
                return;
            }

            rockContext.SaveChanges();

            StartWorkflow(prayerRequest, rockContext);

            bool isNavigateToParent = GetAttributeValue("NavigateToParentOnSave").AsBoolean();

            if (isNavigateToParent)
            {
                NavigateToParentPage();
            }
            else if (GetAttributeValue("RefreshPageOnSave").AsBoolean())
            {
                NavigateToCurrentPage(this.PageParameters().Where(a => a.Value is string).ToDictionary(k => k.Key, v => v.Value.ToString()));
            }
            else
            {
                pnlForm.Visible    = false;
                pnlReceipt.Visible = true;

                // Build success text that is Lava capable
                var mergeFields = Rock.Lava.LavaHelper.GetCommonMergeFields(this.RockPage, this.CurrentPerson);
                mergeFields.Add("PrayerRequest", prayerRequest);
                nbMessage.Text = GetAttributeValue("SaveSuccessText").ResolveMergeFields(mergeFields);

                // Resolve any dynamic url references
                string appRoot   = ResolveRockUrl("~/");
                string themeRoot = ResolveRockUrl("~~/");
                nbMessage.Text = nbMessage.Text.Replace("~~/", themeRoot).Replace("~/", appRoot);

                // show liquid help for debug
                if (GetAttributeValue("EnableDebug").AsBoolean() && IsUserAuthorized(Authorization.EDIT))
                {
                    nbMessage.Text += mergeFields.lavaDebugInfo();
                }
            }
        }
コード例 #14
0
ファイル: PrayerRequestAdd.cs プロジェクト: waldo2590/Rock
        /// <summary>
        /// Executes the specified workflow.
        /// </summary>
        /// <param name="rockContext">The rock context.</param>
        /// <param name="action">The action.</param>
        /// <param name="entity">The entity.</param>
        /// <param name="errorMessages">The error messages.</param>
        /// <returns></returns>
        public override bool Execute(RockContext rockContext, WorkflowAction action, object entity, out List <string> errorMessages)
        {
            errorMessages = new List <string>();

            // Initialize instance properties
            _action      = action;
            _rockContext = rockContext;
            _mergeFields = GetMergeFields(action);

            // Create the prayer request
            var prayerRequestService = new PrayerRequestService(rockContext);
            var isApproved           = GetBoolean(AttributeKey.IsApproved);
            var now      = RockDateTime.Now;
            var category = GetCategory();

            var prayerRequest = new PrayerRequest
            {
                AllowComments      = GetBooleanFromSelectedAttribute(AttributeKey.AreCommentsAllowed),
                ApprovedOnDateTime = isApproved == true ? now : ( DateTime? )null,
                IsApproved         = isApproved,
                CampusId           = GetCampusId(),
                CategoryId         = category?.Id,
                EnteredDateTime    = now,
                ExpirationDate     = GetExpirationDate(now),
                IsActive           = true,
                IsPublic           = GetBooleanFromSelectedAttribute(AttributeKey.IsPublic),
                IsUrgent           = GetBooleanFromSelectedAttribute(AttributeKey.IsUrgent),
                Text = GetResolvedLava(AttributeKey.Request)
            };

            // Set the requestor fields dependent on the attributes set
            var requestor = GetRequestor();

            if (requestor == null)
            {
                prayerRequest.Email     = GetTextFromSelectedAttribute(AttributeKey.Email);
                prayerRequest.FirstName = GetTextFromSelectedAttribute(AttributeKey.FirstName);
                prayerRequest.LastName  = GetTextFromSelectedAttribute(AttributeKey.LastName);
            }
            else
            {
                prayerRequest.Email     = requestor.Email;
                prayerRequest.FirstName = requestor.FirstName;
                prayerRequest.LastName  = requestor.LastName;
                prayerRequest.RequestedByPersonAliasId = requestor.PrimaryAliasId;
            }

            // Validate the prayer request requirements for this action
            if (category == null)
            {
                errorMessages.Add("The category is required");
            }
            else if (category.EntityTypeId != EntityTypeCache.GetId <PrayerRequest>())
            {
                errorMessages.Add("The category must be for prayer requests");
            }

            if (prayerRequest.Text.IsNullOrWhiteSpace())
            {
                errorMessages.Add("The request text is required");
            }

            if (prayerRequest.FirstName.IsNullOrWhiteSpace())
            {
                errorMessages.Add("The first name is required");
            }

            if (prayerRequest.LastName.IsNullOrWhiteSpace())
            {
                errorMessages.Add("The last name is required");
            }

            if (errorMessages.Any())
            {
                return(false);
            }

            // Validate the model requirements
            if (!prayerRequest.IsValid)
            {
                errorMessages.AddRange(prayerRequest.ValidationResults.Select(vr => vr.ErrorMessage));
                return(false);
            }

            // Save the prayer request to the database
            prayerRequestService.Add(prayerRequest);
            rockContext.SaveChanges();

            // If request attribute was specified, set the attribute's value
            SetWorkflowAttributeValue(action, AttributeKey.PrayerRequestAttribute, prayerRequest.Guid);

            return(true);
        }