/// <summary> /// Displays the details for a single, given prayer request. /// </summary> /// <param name="prayerRequest"></param> /// <param name="service"></param> private void ShowPrayerRequest( PrayerRequest prayerRequest, PrayerRequestService service ) { pnlPrayer.Visible = true; pPrayerAnswer.Visible = false; prayerRequest.PrayerCount = ( prayerRequest.PrayerCount ?? 0 ) + 1; hlblPrayerCountTotal.Text = prayerRequest.PrayerCount.ToString() + " team prayers"; hlblUrgent.Visible = prayerRequest.IsUrgent ?? false; lTitle.Text = prayerRequest.FullName.FormatAsHtmlTitle(); //lPrayerText.Text = prayerRequest.Text.EncodeHtmlThenConvertCrLfToHtmlBr(); lPrayerText.Text = ScrubHtmlAndConvertCrLfToBr( prayerRequest.Text ); hlblCategory.Text = prayerRequest.Category.Name; // Show their answer if there is one on the request. if ( !string.IsNullOrWhiteSpace( prayerRequest.Answer ) ) { pPrayerAnswer.Visible = true; lPrayerAnswerText.Text = prayerRequest.Answer.EncodeHtmlThenConvertCrLfToHtmlBr(); } // put the request's id in the hidden field in case it needs to be flagged. hfIdValue.SetValue( prayerRequest.Id ); lPersonIconHtml.Text = GetPhotoUrl( prayerRequest.RequestedByPerson ); pnlComments.Visible = prayerRequest.AllowComments ?? false; if ( rptComments.Visible ) { ShowComments( prayerRequest ); } // save because the prayer count was just modified. service.Save( prayerRequest, this.CurrentPersonId ); }
/// <summary> /// Handles the SaveClick event of the mdFlag control and flags the prayer request and moves to the next. /// </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 mdFlag_SaveClick( object sender, EventArgs e ) { int prayerRequestId = hfIdValue.ValueAsInt(); var service = new PrayerRequestService(); PrayerRequest request = service.Get( prayerRequestId ); if ( request != null ) { request.FlagCount = ( request.FlagCount ?? 0 ) + 1; if ( request.FlagCount >= _flagLimit ) { request.IsApproved = false; } service.Save( request, this.CurrentPersonId ); } mdFlag.Hide(); lbNext_Click( sender, e ); }
/// <summary> /// Handles the Delete event of the gPrayerRequests control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param> protected void gPrayerRequests_Delete( object sender, RowEventArgs e ) { RockTransactionScope.WrapTransaction( () => { PrayerRequestService prayerRequestService = new PrayerRequestService(); PrayerRequest prayerRequest = prayerRequestService.Get( (int)e.RowKeyValue ); if ( prayerRequest != null ) { DeleteAllRelatedNotes( prayerRequest ); string errorMessage; if ( !prayerRequestService.CanDelete( prayerRequest, out errorMessage ) ) { maGridWarning.Show( errorMessage, ModalAlertType.Information ); return; } prayerRequestService.Delete( prayerRequest, CurrentPersonId ); prayerRequestService.Save( prayerRequest, CurrentPersonId ); } } ); BindGrid(); }
/// <summary> /// Handles the CheckChanged event of the gPrayerRequests IsApproved field. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param> protected void gPrayerRequests_CheckChanged( object sender, RowEventArgs e ) { bool failure = true; if ( e.RowKeyValue != null ) { PrayerRequestService prayerRequestService = new PrayerRequestService(); PrayerRequest prayerRequest = prayerRequestService.Get( (int)e.RowKeyValue ); if ( prayerRequest != null ) { failure = false; // if it was approved, set it to unapproved... otherwise if ( prayerRequest.IsApproved ?? false ) { prayerRequest.IsApproved = false; } else { prayerRequest.IsApproved = true; prayerRequest.ApprovedByPersonId = CurrentPerson.Id; prayerRequest.ApprovedOnDateTime = 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; } } prayerRequestService.Save( prayerRequest, CurrentPersonId ); } BindGrid(); } if ( failure ) { maGridWarning.Show( "Unable to approve that prayer request", ModalAlertType.Warning ); } }
/// <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 }; PrayerRequestService prayerRequestService = new PrayerRequestService(); prayerRequestService.Add( prayerRequest, CurrentPersonId ); prayerRequest.EnteredDateTime = DateTime.Now; if ( isAutoApproved ) { prayerRequest.ApprovedByPersonId = CurrentPersonId; prayerRequest.ApprovedOnDateTime = DateTime.Now; var expireDays = Convert.ToDouble( GetAttributeValue( "ExpireDays" ) ); prayerRequest.ExpirationDate = DateTime.Now.AddDays( expireDays ); } // Now record all the bits... int? categoryId = bddlCategory.SelectedValueAsInt(); var defaultCategoryGuid = GetAttributeValue( "DefaultCategory" ); if ( categoryId == null && ! string.IsNullOrEmpty( defaultCategoryGuid ) ) { var category = new CategoryService().Get( new Guid( defaultCategoryGuid ) ); categoryId = category.Id; } prayerRequest.CategoryId = categoryId; prayerRequest.RequestedByPersonId = CurrentPersonId; prayerRequest.FirstName = Sanitizer.GetSafeHtmlFragment( dtbFirstName.Text.Trim() ); prayerRequest.LastName = Sanitizer.GetSafeHtmlFragment( dtbLastName.Text.Trim() ); prayerRequest.Email = dtbEmail.Text.Trim(); prayerRequest.Text = dtbRequest.Text.Trim(); if ( _enableUrgentFlag ) { prayerRequest.IsUrgent = cbIsUrgent.Checked; } else { prayerRequest.IsUrgent = false; } if ( _enableCommentsFlag ) { prayerRequest.AllowComments = cbAllowComments.Checked; } if ( _enablePublicDisplayFlag ) { prayerRequest.IsPublic = cbAllowPublicDisplay.Checked; } else { prayerRequest.IsPublic = false; } 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; } }
/// <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.EnteredDateTime = 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.ApprovedOnDateTime = 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; } } // If no expiration date was manually set, then use the default setting. if ( !dpExpirationDate.SelectedDate.HasValue ) { var expireDays = Convert.ToDouble( GetAttributeValue( "ExpireDays" ) ); prayerRequest.ExpirationDate = DateTime.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(); var defaultCategoryGuid = GetAttributeValue( "DefaultCategory" ); if ( categoryId == null && !string.IsNullOrEmpty( defaultCategoryGuid ) ) { var category = new CategoryService().Get( new Guid( 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; } prayerRequestService.Save( prayerRequest, CurrentPersonId ); NavigateToParentPage(); }