static private void CreateAuthToken(RegistrationTemplate reg) { using (FileStream fs = new FileStream(RegistrationTemplate.AuthTokenFileName, FileMode.OpenOrCreate)) { BinaryFormatter formatter = new BinaryFormatter(); formatter.Serialize(fs, reg); } }
/// <summary> /// Raises the <see cref="E:System.Web.UI.Control.Init" /> event. /// </summary> /// <param name="e">An <see cref="T:System.EventArgs" /> object that contains the event data.</param> protected override void OnInit(EventArgs e) { base.OnInit(e); // this event gets fired after block settings are updated. it's nice to repaint the screen if these settings would alter it this.BlockUpdated += Block_BlockUpdated; this.AddConfigurationUpdateTrigger(upnlContent); var entitySetId = PageParameter("WaitListSetId").AsIntegerOrNull(); if (entitySetId.HasValue) { // get the registrant Ids var registrantIds = new EntitySetItemService(_rockContext) .Queryable().AsNoTracking() .Where(i => i.EntitySetId == entitySetId) .Select(i => i.EntityId) .ToList(); // get the registrants _registrants = new RegistrationRegistrantService(_rockContext) .Queryable() .Where(r => registrantIds.Contains(r.Id)) .ToList(); // get the first registration _firstRegistration = _registrants .Where(r => r.Registration != null) .Select(r => r.Registration) .FirstOrDefault(); // get the template _template = _registrants .Where(r => r.Registration != null && r.Registration.RegistrationInstance != null && r.Registration.RegistrationInstance.RegistrationTemplate != null) .Select(r => r.Registration.RegistrationInstance.RegistrationTemplate) .FirstOrDefault(); // Bind the grid rptRecipients.DataSource = _registrants .GroupBy(r => r.Registration) .Select(r => new RegistrationSummary { Registration = r.Key, Registrants = r.Key.Registrants.Where(g => registrantIds.Contains(g.Id)).ToList() }); rptRecipients.DataBind(); } }
/// <summary> /// Raises the <see cref="E:System.Web.UI.Control.Init" /> event. /// </summary> /// <param name="e">An <see cref="T:System.EventArgs" /> object that contains the event data.</param> protected override void OnInit(EventArgs e) { base.OnInit(e); int templateId = PageParameter("RegistrationTemplateId").AsInteger(); if (templateId != 0) { _template = GetRegistrationTemplate(templateId); if (_template != null && _template.IsAuthorized(Authorization.VIEW, CurrentPerson)) { _canView = true; rFilter.ApplyFilterClick += rFilter_ApplyFilterClick; gInstances.DataKeyNames = new string[] { "Id" }; gInstances.RowDataBound += gInstances_RowDataBound; gInstances.Actions.AddClick += gInstances_AddClick; gInstances.GridRebind += gInstances_GridRebind; gInstances.ExportFilename = _template.Name; gInstances.ShowConfirmDeleteDialog = false; // make sure they have Auth to edit the block OR edit to the template bool canEditBlock = UserCanEdit || _template.IsAuthorized(Authorization.EDIT, this.CurrentPerson); gInstances.Actions.ShowAdd = canEditBlock; gInstances.IsDeleteEnabled = canEditBlock; } } string deleteScript = @" $('table.js-grid-instances a.grid-delete-button').click(function( e ){ e.preventDefault(); Rock.dialogs.confirm('Are you sure you want to delete this registration instance? All of the registrations and registrants will also be deleted!', function (result) { if (result) { Rock.dialogs.confirm('Are you really sure? ', function (result) { if (result) { window.location = e.target.href ? e.target.href : e.target.parentElement.href; } }); } }); }); "; ScriptManager.RegisterStartupScript(gInstances, gInstances.GetType(), "deleteInstanceScript", deleteScript, true); }
/// <summary> /// Gets the registration template. /// </summary> /// <param name="registrationTemplateId">The registration template identifier.</param> /// <param name="rockContext">The rock context.</param> /// <returns></returns> private RegistrationTemplate GetRegistrationTemplate(int registrationTemplateId, RockContext rockContext = null) { string key = string.Format("RegistrationTemplate:{0}", registrationTemplateId); RegistrationTemplate registrationTemplate = RockPage.GetSharedItem(key) as RegistrationTemplate; if (registrationTemplate == null) { rockContext = rockContext ?? new RockContext(); registrationTemplate = new RegistrationTemplateService(rockContext) .Queryable("GroupType.Roles") .AsNoTracking() .FirstOrDefault(i => i.Id == registrationTemplateId); RockPage.SaveSharedItem(key, registrationTemplate); } return(registrationTemplate); }
/// <summary> /// Sets the value. /// </summary> /// <param name="registrationTemplate">The registrationTemplate.</param> public void SetValue( RegistrationTemplate registrationTemplate ) { if ( registrationTemplate != null ) { ItemId = registrationTemplate.Id.ToString(); string parentCategoryIds = string.Empty; var parentCategory = registrationTemplate.Category; while ( parentCategory != null ) { parentCategoryIds = parentCategory.Id + "," + parentCategoryIds; parentCategory = parentCategory.ParentCategory; } InitialItemParentIds = parentCategoryIds.TrimEnd( new[] { ',' } ); ItemName = registrationTemplate.Name; } else { ItemId = Constants.None.IdValue; ItemName = Constants.None.TextHtml; } }
/// <summary> /// Sets the value. /// </summary> /// <param name="registrationTemplate">The registrationTemplate.</param> public void SetValue(RegistrationTemplate registrationTemplate) { if (registrationTemplate != null) { ItemId = registrationTemplate.Id.ToString(); string parentCategoryIds = string.Empty; var parentCategory = registrationTemplate.Category; while (parentCategory != null) { parentCategoryIds = parentCategory.Id + "," + parentCategoryIds; parentCategory = parentCategory.ParentCategory; } InitialItemParentIds = parentCategoryIds.TrimEnd(new[] { ',' }); ItemName = registrationTemplate.Name; } else { ItemId = Constants.None.IdValue; ItemName = Constants.None.TextHtml; } }
/// <summary> /// Shows the detail. /// </summary> private void ShowDetail() { int? registrationTemplateId = PageParameter( "RegistrationTemplateId" ).AsIntegerOrNull(); int? parentCategoryId = PageParameter( "ParentCategoryId" ).AsIntegerOrNull(); if ( !registrationTemplateId.HasValue ) { pnlDetails.Visible = false; return; } var rockContext = new RockContext(); RegistrationTemplate registrationTemplate = null; if ( registrationTemplateId.HasValue ) { registrationTemplate = GetRegistrationTemplate( registrationTemplateId.Value, rockContext ); } if ( registrationTemplate == null ) { registrationTemplate = new RegistrationTemplate(); registrationTemplate.Id = 0; registrationTemplate.IsActive = true; registrationTemplate.CategoryId = parentCategoryId; registrationTemplate.ConfirmationFromName = "{{ RegistrationInstance.ContactPersonAlias.Person.FullName }}"; registrationTemplate.ConfirmationFromEmail = "{{ RegistrationInstance.ContactEmail }}"; registrationTemplate.ConfirmationSubject = "{{ RegistrationInstance.Name }} Confirmation"; registrationTemplate.ConfirmationEmailTemplate = GetAttributeValue( "DefaultConfirmationEmail" ); registrationTemplate.ReminderFromName = "{{ RegistrationInstance.ContactPersonAlias.Person.FullName }}"; registrationTemplate.ReminderFromEmail = "{{ RegistrationInstance.ContactEmail }}"; registrationTemplate.ReminderSubject = "{{ RegistrationInstance.Name }} Reminder"; registrationTemplate.ReminderEmailTemplate = GetAttributeValue( "DefaultReminderEmail" ); registrationTemplate.Notify = RegistrationNotify.None; registrationTemplate.SuccessTitle = "Congratulations {{ Registration.FirstName }}"; registrationTemplate.SuccessText = GetAttributeValue( "DefaultSuccessText" ); registrationTemplate.PaymentReminderEmailTemplate = GetAttributeValue( "DefaultPaymentReminderEmail" ); registrationTemplate.PaymentReminderFromEmail = "{{ RegistrationInstance.ContactEmail }}"; registrationTemplate.PaymentReminderFromName = "{{ RegistrationInstance.ContactPersonAlias.Person.FullName }}"; registrationTemplate.PaymentReminderSubject = "{{ RegistrationInstance.Name }} Payment Reminder"; registrationTemplate.AllowMultipleRegistrants = true; registrationTemplate.MaxRegistrants = 10; registrationTemplate.GroupMemberStatus = GroupMemberStatus.Active; } pnlDetails.Visible = true; hfRegistrationTemplateId.Value = registrationTemplate.Id.ToString(); // render UI based on Authorized bool readOnly = false; nbEditModeMessage.Text = string.Empty; // User must have 'Edit' rights to block, or 'Administrate' rights to template if ( !UserCanEdit && !registrationTemplate.IsAuthorized( Authorization.ADMINISTRATE, CurrentPerson ) ) { readOnly = true; nbEditModeMessage.Heading = "Information"; nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed( RegistrationTemplate.FriendlyTypeName ); } if ( readOnly ) { btnEdit.Visible = false; btnDelete.Visible = false; btnCopy.Visible = false; btnSecurity.Visible = false; ShowReadonlyDetails( registrationTemplate ); } else { btnEdit.Visible = true; btnDelete.Visible = true; btnCopy.ToolTip = "Copy " + registrationTemplate.Name; btnCopy.Visible = true; btnSecurity.Title = "Secure " + registrationTemplate.Name; btnSecurity.EntityId = registrationTemplate.Id; if ( registrationTemplate.Id > 0 ) { SetHasRegistrations( registrationTemplate.Id, rockContext ); ShowReadonlyDetails( registrationTemplate ); } else { LoadStateDetails(registrationTemplate, rockContext); ShowEditDetails( registrationTemplate, rockContext ); } } }
/// <summary> /// Loads the state details. /// </summary> /// <param name="RegistrationTemplate">The registration template.</param> /// <param name="rockContext">The rock context.</param> private void LoadStateDetails( RegistrationTemplate RegistrationTemplate, RockContext rockContext ) { if ( RegistrationTemplate != null ) { // If no forms, add at one if ( !RegistrationTemplate.Forms.Any() ) { var form = new RegistrationTemplateForm(); form.Guid = Guid.NewGuid(); form.Order = 0; form.Name = "Default Form"; RegistrationTemplate.Forms.Add( form ); } var defaultForm = RegistrationTemplate.Forms.First(); // Add first name field if it doesn't exist if ( !defaultForm.Fields .Any( f => f.FieldSource == RegistrationFieldSource.PersonField && f.PersonFieldType == RegistrationPersonFieldType.FirstName )) { var formField = new RegistrationTemplateFormField(); formField.FieldSource = RegistrationFieldSource.PersonField; formField.PersonFieldType = RegistrationPersonFieldType.FirstName; formField.IsGridField = true; formField.IsRequired = true; formField.PreText = @"<div class='row'> <div class='col-md-6'> "; formField.PostText = " </div>"; formField.Order = defaultForm.Fields.Any() ? defaultForm.Fields.Max( f => f.Order ) + 1 : 0; defaultForm.Fields.Add( formField ); } // Add last name field if it doesn't exist if ( !defaultForm.Fields .Any( f => f.FieldSource == RegistrationFieldSource.PersonField && f.PersonFieldType == RegistrationPersonFieldType.LastName ) ) { var formField = new RegistrationTemplateFormField(); formField.FieldSource = RegistrationFieldSource.PersonField; formField.PersonFieldType = RegistrationPersonFieldType.LastName; formField.IsGridField = true; formField.IsRequired = true; formField.PreText = " <div class='col-md-6'>"; formField.PostText = @" </div> </div>"; formField.Order = defaultForm.Fields.Any() ? defaultForm.Fields.Max( f => f.Order ) + 1 : 0; defaultForm.Fields.Add( formField ); } FormState = new List<RegistrationTemplateForm>(); FormFieldsState = new Dictionary<Guid, List<RegistrationTemplateFormField>>(); foreach ( var form in RegistrationTemplate.Forms.OrderBy( f => f.Order ) ) { FormState.Add( form.Clone( false ) ); FormFieldsState.Add( form.Guid, form.Fields.ToList() ); } DiscountState = RegistrationTemplate.Discounts.OrderBy( a => a.Order ).ToList(); FeeState = RegistrationTemplate.Fees.OrderBy( a => a.Order ).ToList(); } else { FormState = new List<RegistrationTemplateForm>(); FormFieldsState = new Dictionary<Guid, List<RegistrationTemplateFormField>>(); DiscountState = new List<RegistrationTemplateDiscount>(); FeeState = new List<RegistrationTemplateFee>(); } }
/// <summary> /// Raises the <see cref="E:System.Web.UI.Control.Init" /> event. /// </summary> /// <param name="e">An <see cref="T:System.EventArgs" /> object that contains the event data.</param> protected override void OnInit( EventArgs e ) { base.OnInit( e ); // this event gets fired after block settings are updated. it's nice to repaint the screen if these settings would alter it this.BlockUpdated += Block_BlockUpdated; this.AddConfigurationUpdateTrigger( upnlContent ); var entitySetId = PageParameter( "WaitListSetId" ).AsIntegerOrNull(); if ( entitySetId.HasValue ) { // get the registrant Ids var registrantIds = new EntitySetItemService( _rockContext ) .Queryable().AsNoTracking() .Where( i => i.EntitySetId == entitySetId ) .Select( i => i.EntityId ) .ToList(); // get the registrants _registrants = new RegistrationRegistrantService( _rockContext ) .Queryable() .Where( r => registrantIds.Contains( r.Id ) ) .ToList(); // get the first registration _firstRegistration = _registrants .Where( r => r.Registration != null ) .Select( r => r.Registration ) .FirstOrDefault(); // get the template _template = _registrants .Where( r => r.Registration != null && r.Registration.RegistrationInstance != null && r.Registration.RegistrationInstance.RegistrationTemplate != null ) .Select( r => r.Registration.RegistrationInstance.RegistrationTemplate ) .FirstOrDefault(); // Bind the grid rptRecipients.DataSource = _registrants .GroupBy( r => r.Registration ) .Select( r => new RegistrationSummary { Registration = r.Key, Registrants = r.Key.Registrants.Where( g => registrantIds.Contains( g.Id ) ).ToList() } ); rptRecipients.DataBind(); } }
public static RRTemplate ServerRequest(RRTemplate request) { try { client = new TcpClient(); client.Connect(serverIP, serverPort); clientStream = client.GetStream(); BinaryFormatter formatter = new BinaryFormatter(); using (MemoryStream memoryStream = new MemoryStream()) { formatter.Serialize(memoryStream, request); clientStream.Write(memoryStream.GetBuffer(), 0, memoryStream.GetBuffer().Length); switch (request.RRType) //если попадает в default, то будет ответ, если нет, то нет { case RRType.RefreshContacts: case RRType.SearchOutContacts: case RRType.UserDisconected: case RRType.AddContact: case RRType.RemoveContact: case RRType.SendMessage: case RRType.AddContactTarget: case RRType.RemoveContactTarget: case RRType.RefreshContactStatus: case RRType.RefreshMessageState: case RRType.CreateConv: case RRType.RemoveConv: clientStream.Close(); client.Close(); return(null); break; default: memoryStream.Flush(); memoryStream.Position = 0; do { byte[] buffer = new byte[256]; int bytes; bytes = clientStream.Read(buffer, 0, buffer.Length); memoryStream.Write(buffer, 0, bytes); buffer = new byte[256]; }while (clientStream.DataAvailable); memoryStream.Position = 0; RRTemplate serverResponse = formatter.Deserialize(memoryStream) as RRTemplate; if (serverResponse != null) { switch (serverResponse.RRType) { case RRType.Authorization: case RRType.RefreshUserData: RegistrationTemplate reg = serverResponse.RRObject as RegistrationTemplate; //RegistrationTemplate служит как шаблон для преднастройки приложения if (reg != null) { CreateAuthToken(reg); return(serverResponse); } break; case RRType.DownloadFile: DownloadFileTemplate dfileT = serverResponse.RRObject as DownloadFileTemplate; if (dfileT != null) { return(serverResponse); } break; case RRType.AdminSearch: AdminSearchTemplate admST = serverResponse.RRObject as AdminSearchTemplate; if (admST != null) { return(serverResponse); } break; case RRType.BlockUnblockUser: BlockUnblockUserTemplate blunblUT = serverResponse.RRObject as BlockUnblockUserTemplate; if (blunblUT != null) { return(serverResponse); } break; case RRType.Error: ErrorReportTemplate error = serverResponse.RRObject as ErrorReportTemplate; if (error != null) { return(new RRTemplate(RRType.Error, error)); } break; default: return(new RRTemplate(RRType.Error, new ErrorReportTemplate(ErrorType.Other, new Exception("Unknown problem")))); break; } } else { return(new RRTemplate(RRType.Error, new ErrorReportTemplate(ErrorType.UnCorrectServerResponse, new Exception("Uncorrect server response")))); } break; } } return(new RRTemplate(RRType.Error, new ErrorReportTemplate(ErrorType.Other, new Exception("Unknown problem")))); } catch (SocketException ex) { return(new RRTemplate(RRType.Error, new ErrorReportTemplate(ErrorType.NoConnectionWithServer, ex))); } catch (Exception ex) { return(new RRTemplate(RRType.Error, new ErrorReportTemplate(ErrorType.Other, ex))); } }
private void LoadState() { int? registrantId = PageParameter( "RegistrantId" ).AsIntegerOrNull(); int? registrationId = PageParameter( "RegistrationId" ).AsIntegerOrNull(); if ( RegistrantState == null ) { var rockContext = new RockContext(); RegistrationRegistrant registrant = null; if ( registrantId.HasValue && registrantId.Value != 0 ) { registrant = new RegistrationRegistrantService( rockContext ) .Queryable( "Registration.RegistrationInstance.RegistrationTemplate.Forms.Fields,Registration.RegistrationInstance.RegistrationTemplate.Fees,PersonAlias.Person,Fees" ).AsNoTracking() .Where( r => r.Id == registrantId.Value ) .FirstOrDefault(); if ( registrant != null && registrant.Registration != null && registrant.Registration.RegistrationInstance != null && registrant.Registration.RegistrationInstance.RegistrationTemplate != null ) { RegistrantState = new RegistrantInfo( registrant, rockContext ); TemplateState = registrant.Registration.RegistrationInstance.RegistrationTemplate; RegistrationInstanceId = registrant.Registration.RegistrationInstanceId; lWizardTemplateName.Text = registrant.Registration.RegistrationInstance.RegistrationTemplate.Name; lWizardInstanceName.Text = registrant.Registration.RegistrationInstance.Name; lWizardRegistrationName.Text = registrant.Registration.ToString(); lWizardRegistrantName.Text = registrant.ToString(); tglWaitList.Checked = !registrant.OnWaitList; } } if ( TemplateState == null && registrationId.HasValue && registrationId.Value != 0 ) { var registration = new RegistrationService( rockContext ) .Queryable( "RegistrationInstance.RegistrationTemplate.Forms.Fields,RegistrationInstance.RegistrationTemplate.Fees" ).AsNoTracking() .Where( r => r.Id == registrationId.Value ) .FirstOrDefault(); if ( registration != null && registration.RegistrationInstance != null && registration.RegistrationInstance.RegistrationTemplate != null ) { TemplateState = registration.RegistrationInstance.RegistrationTemplate; RegistrationInstanceId = registration.RegistrationInstanceId; lWizardTemplateName.Text = registration.RegistrationInstance.RegistrationTemplate.Name; lWizardInstanceName.Text = registration.RegistrationInstance.Name; lWizardRegistrationName.Text = registration.ToString(); lWizardRegistrantName.Text = "New Registrant"; } } if ( TemplateState != null ) { tglWaitList.Visible = TemplateState.WaitListEnabled; } if ( TemplateState != null && RegistrantState == null ) { RegistrantState = new RegistrantInfo(); RegistrantState.RegistrationId = registrationId ?? 0; if ( TemplateState.SetCostOnInstance.HasValue && TemplateState.SetCostOnInstance.Value ) { var instance = new RegistrationInstanceService( rockContext ).Get( RegistrationInstanceId ); if ( instance != null ) { RegistrantState.Cost = instance.Cost ?? 0.0m; } } else { RegistrantState.Cost = TemplateState.Cost; } } if ( registrant != null && registrant.PersonAlias != null && registrant.PersonAlias.Person != null ) { ppPerson.SetValue( registrant.PersonAlias.Person ); if ( TemplateState != null && TemplateState.RequiredSignatureDocumentTemplate != null ) { fuSignedDocument.Label = TemplateState.RequiredSignatureDocumentTemplate.Name; if ( TemplateState.RequiredSignatureDocumentTemplate.BinaryFileType != null ) { fuSignedDocument.BinaryFileTypeGuid = TemplateState.RequiredSignatureDocumentTemplate.BinaryFileType.Guid; } var signatureDocument = new SignatureDocumentService( rockContext ) .Queryable().AsNoTracking() .Where( d => d.SignatureDocumentTemplateId == TemplateState.RequiredSignatureDocumentTemplateId.Value && d.AppliesToPersonAlias != null && d.AppliesToPersonAlias.PersonId == registrant.PersonAlias.PersonId && d.LastStatusDate.HasValue && d.Status == SignatureDocumentStatus.Signed && d.BinaryFile != null ) .OrderByDescending( d => d.LastStatusDate.Value ) .FirstOrDefault(); if ( signatureDocument != null ) { hfSignedDocumentId.Value = signatureDocument.Id.ToString(); fuSignedDocument.BinaryFileId = signatureDocument.BinaryFileId; } fuSignedDocument.Visible = true; } else { fuSignedDocument.Visible = false; } } else { ppPerson.SetValue( null ); } if ( RegistrantState != null ) { cbCost.Text = RegistrantState.Cost.ToString( "N2" ); cbDiscountApplies.Checked = RegistrantState.DiscountApplies; } } }
/// <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 ) { ParseControls( true ); var rockContext = new RockContext(); var service = new RegistrationTemplateService( rockContext ); RegistrationTemplate RegistrationTemplate = null; int? RegistrationTemplateId = hfRegistrationTemplateId.Value.AsIntegerOrNull(); if ( RegistrationTemplateId.HasValue ) { RegistrationTemplate = service.Get( RegistrationTemplateId.Value ); } bool newTemplate = false; if ( RegistrationTemplate == null ) { newTemplate = true; RegistrationTemplate = new RegistrationTemplate(); } RegistrationNotify notify = RegistrationNotify.None; foreach( ListItem li in cblNotify.Items ) { if ( li.Selected ) { notify = notify | (RegistrationNotify)li.Value.AsInteger(); } } RegistrationTemplate.IsActive = cbIsActive.Checked; RegistrationTemplate.Name = tbName.Text; RegistrationTemplate.CategoryId = cpCategory.SelectedValueAsInt(); RegistrationTemplate.GroupTypeId = gtpGroupType.SelectedGroupTypeId; RegistrationTemplate.GroupMemberRoleId = rpGroupTypeRole.GroupRoleId; RegistrationTemplate.GroupMemberStatus = ddlGroupMemberStatus.SelectedValueAsEnum<GroupMemberStatus>(); RegistrationTemplate.RequiredSignatureDocumentTemplateId = ddlSignatureDocumentTemplate.SelectedValueAsInt(); RegistrationTemplate.SignatureDocumentAction = cbDisplayInLine.Checked ? SignatureDocumentAction.Embed : SignatureDocumentAction.Email; RegistrationTemplate.RegistrationWorkflowTypeId = wtpRegistrationWorkflow.SelectedValueAsInt(); RegistrationTemplate.Notify = notify; RegistrationTemplate.AddPersonNote = cbAddPersonNote.Checked; RegistrationTemplate.LoginRequired = cbLoginRequired.Checked; RegistrationTemplate.AllowExternalRegistrationUpdates = cbAllowExternalUpdates.Checked; RegistrationTemplate.AllowGroupPlacement = cbAllowGroupPlacement.Checked; RegistrationTemplate.AllowMultipleRegistrants = cbMultipleRegistrants.Checked; RegistrationTemplate.MaxRegistrants = nbMaxRegistrants.Text.AsInteger(); RegistrationTemplate.RegistrantsSameFamily = rblRegistrantsInSameFamily.SelectedValueAsEnum<RegistrantsSameFamily>(); RegistrationTemplate.ShowCurrentFamilyMembers = cbShowCurrentFamilyMembers.Checked; RegistrationTemplate.SetCostOnInstance = !tglSetCostOnTemplate.Checked; RegistrationTemplate.Cost = cbCost.Text.AsDecimal(); RegistrationTemplate.MinimumInitialPayment = cbMinimumInitialPayment.Text.AsDecimalOrNull(); RegistrationTemplate.FinancialGatewayId = fgpFinancialGateway.SelectedValueAsInt(); RegistrationTemplate.BatchNamePrefix = txtBatchNamePrefix.Text; RegistrationTemplate.ConfirmationFromName = tbConfirmationFromName.Text; RegistrationTemplate.ConfirmationFromEmail = tbConfirmationFromEmail.Text; RegistrationTemplate.ConfirmationSubject = tbConfirmationSubject.Text; RegistrationTemplate.ConfirmationEmailTemplate = ceConfirmationEmailTemplate.Text; RegistrationTemplate.ReminderFromName = tbReminderFromName.Text; RegistrationTemplate.ReminderFromEmail = tbReminderFromEmail.Text; RegistrationTemplate.ReminderSubject = tbReminderSubject.Text; RegistrationTemplate.ReminderEmailTemplate = ceReminderEmailTemplate.Text; RegistrationTemplate.PaymentReminderFromName = tbPaymentReminderFromName.Text; RegistrationTemplate.PaymentReminderFromEmail = tbPaymentReminderFromEmail.Text; RegistrationTemplate.PaymentReminderSubject = tbPaymentReminderSubject.Text; RegistrationTemplate.PaymentReminderEmailTemplate = cePaymentReminderEmailTemplate.Text; RegistrationTemplate.PaymentReminderTimeSpan = nbPaymentReminderTimeSpan.Text.AsInteger(); RegistrationTemplate.RegistrationTerm = string.IsNullOrWhiteSpace( tbRegistrationTerm.Text ) ? "Registration" : tbRegistrationTerm.Text; RegistrationTemplate.RegistrantTerm = string.IsNullOrWhiteSpace( tbRegistrantTerm.Text ) ? "Registrant" : tbRegistrantTerm.Text; RegistrationTemplate.FeeTerm = string.IsNullOrWhiteSpace( tbFeeTerm.Text ) ? "Additional Options" : tbFeeTerm.Text; RegistrationTemplate.DiscountCodeTerm = string.IsNullOrWhiteSpace( tbDiscountCodeTerm.Text ) ? "Discount Code" : tbDiscountCodeTerm.Text; RegistrationTemplate.SuccessTitle = tbSuccessTitle.Text; RegistrationTemplate.SuccessText = ceSuccessText.Text; if ( !Page.IsValid || !RegistrationTemplate.IsValid ) { return; } foreach ( var form in FormState ) { if ( !form.IsValid ) { return; } if ( FormFieldsState.ContainsKey( form.Guid ) ) { foreach( var formField in FormFieldsState[ form.Guid ]) { if ( !formField.IsValid ) { return; } } } } // Get the valid group member attributes var group = new Group(); group.GroupTypeId = gtpGroupType.SelectedGroupTypeId ?? 0; var groupMember = new GroupMember(); groupMember.Group = group; groupMember.LoadAttributes(); var validGroupMemberAttributeIds = groupMember.Attributes.Select( a => a.Value.Id ).ToList(); // Remove any group member attributes that are not valid based on selected group type foreach( var fieldList in FormFieldsState.Select( s => s.Value ) ) { foreach( var formField in fieldList .Where( a => a.FieldSource == RegistrationFieldSource.GroupMemberAttribute && a.AttributeId.HasValue && !validGroupMemberAttributeIds.Contains( a.AttributeId.Value ) ) .ToList() ) { fieldList.Remove( formField ); } } // Perform Validation var validationErrors = new List<string>(); if ( ( ( RegistrationTemplate.SetCostOnInstance ?? false ) || RegistrationTemplate.Cost > 0 || FeeState.Any() ) && !RegistrationTemplate.FinancialGatewayId.HasValue ) { validationErrors.Add( "A Financial Gateway is required when the registration has a cost or additional fees or is configured to allow instances to set a cost." ); } if ( validationErrors.Any() ) { nbValidationError.Visible = true; nbValidationError.Text = "<ul class='list-unstyled'><li>" + validationErrors.AsDelimited( "</li><li>" ) + "</li></ul>"; } else { // Save the entity field changes to registration template if ( RegistrationTemplate.Id.Equals( 0 ) ) { service.Add( RegistrationTemplate ); } rockContext.SaveChanges(); var attributeService = new AttributeService( rockContext ); var registrationTemplateFormService = new RegistrationTemplateFormService( rockContext ); var registrationTemplateFormFieldService = new RegistrationTemplateFormFieldService( rockContext ); var registrationTemplateDiscountService = new RegistrationTemplateDiscountService( rockContext ); var registrationTemplateFeeService = new RegistrationTemplateFeeService( rockContext ); var registrationRegistrantFeeService = new RegistrationRegistrantFeeService( rockContext ); var groupService = new GroupService( rockContext ); // delete forms that aren't assigned in the UI anymore var formUiGuids = FormState.Select( f => f.Guid ).ToList(); foreach ( var form in registrationTemplateFormService .Queryable() .Where( f => f.RegistrationTemplateId == RegistrationTemplate.Id && !formUiGuids.Contains( f.Guid ) ) ) { foreach( var formField in form.Fields.ToList() ) { form.Fields.Remove( formField ); registrationTemplateFormFieldService.Delete( formField ); } registrationTemplateFormService.Delete( form ); } // delete fields that aren't assigned in the UI anymore var fieldUiGuids = FormFieldsState.SelectMany( a => a.Value).Select( f => f.Guid ).ToList(); foreach ( var formField in registrationTemplateFormFieldService .Queryable() .Where( a => formUiGuids.Contains( a.RegistrationTemplateForm.Guid ) && !fieldUiGuids.Contains( a.Guid ) ) ) { registrationTemplateFormFieldService.Delete( formField ); } // delete discounts that aren't assigned in the UI anymore var discountUiGuids = DiscountState.Select( u => u.Guid ).ToList(); foreach ( var discount in registrationTemplateDiscountService .Queryable() .Where( d => d.RegistrationTemplateId == RegistrationTemplate.Id && !discountUiGuids.Contains( d.Guid ) ) ) { registrationTemplateDiscountService.Delete( discount ); } // delete fees that aren't assigned in the UI anymore var feeUiGuids = FeeState.Select( u => u.Guid ).ToList(); var deletedfees = registrationTemplateFeeService .Queryable() .Where( d => d.RegistrationTemplateId == RegistrationTemplate.Id && !feeUiGuids.Contains( d.Guid ) ) .ToList(); var deletedFeeIds = deletedfees.Select( f => f.Id ).ToList(); foreach ( var registrantFee in registrationRegistrantFeeService .Queryable() .Where( f => deletedFeeIds.Contains( f.RegistrationTemplateFeeId ) ) .ToList() ) { registrationRegistrantFeeService.Delete( registrantFee ); } foreach ( var fee in deletedfees ) { registrationTemplateFeeService.Delete( fee ); } int? entityTypeId = EntityTypeCache.Read( typeof( Rock.Model.RegistrationRegistrant ) ).Id; var qualifierColumn = "RegistrationTemplateId"; var qualifierValue = RegistrationTemplate.Id.ToString(); // Get the registration attributes still in the UI var attributesUI = FormFieldsState .SelectMany( s => s.Value.Where( a => a.FieldSource == RegistrationFieldSource.RegistrationAttribute && a.Attribute != null ) ) .Select( f => f.Attribute ) .ToList(); var selectedAttributeGuids = attributesUI.Select( a => a.Guid ); // Delete the registration attributes that were removed from the UI var attributesDB = attributeService.Get( entityTypeId, qualifierColumn, qualifierValue ); foreach ( var attr in attributesDB.Where( a => !selectedAttributeGuids.Contains( a.Guid ) ).ToList() ) { attributeService.Delete( attr ); Rock.Web.Cache.AttributeCache.Flush( attr.Id ); } rockContext.SaveChanges(); // Save all of the registration attributes still in the UI foreach ( var attr in attributesUI ) { Helper.SaveAttributeEdits( attr, entityTypeId, qualifierColumn, qualifierValue, rockContext ); } // add/updated forms/fields foreach ( var formUI in FormState ) { var form = RegistrationTemplate.Forms.FirstOrDefault( f => f.Guid.Equals( formUI.Guid ) ); if ( form == null ) { form = new RegistrationTemplateForm(); form.Guid = formUI.Guid; RegistrationTemplate.Forms.Add( form ); } form.Name = formUI.Name; form.Order = formUI.Order; if ( FormFieldsState.ContainsKey( form.Guid ) ) { foreach ( var formFieldUI in FormFieldsState[form.Guid] ) { var formField = form.Fields.FirstOrDefault( a => a.Guid.Equals( formFieldUI.Guid ) ); if ( formField == null ) { formField = new RegistrationTemplateFormField(); formField.Guid = formFieldUI.Guid; form.Fields.Add( formField ); } formField.AttributeId = formFieldUI.AttributeId; if ( !formField.AttributeId.HasValue && formFieldUI.FieldSource == RegistrationFieldSource.RegistrationAttribute && formFieldUI.Attribute != null ) { var attr = AttributeCache.Read( formFieldUI.Attribute.Guid, rockContext ); if ( attr != null ) { formField.AttributeId = attr.Id; } } formField.FieldSource = formFieldUI.FieldSource; formField.PersonFieldType = formFieldUI.PersonFieldType; formField.IsInternal = formFieldUI.IsInternal; formField.IsSharedValue = formFieldUI.IsSharedValue; formField.ShowCurrentValue = formFieldUI.ShowCurrentValue; formField.PreText = formFieldUI.PreText; formField.PostText = formFieldUI.PostText; formField.IsGridField = formFieldUI.IsGridField; formField.IsRequired = formFieldUI.IsRequired; formField.Order = formFieldUI.Order; } } } // add/updated discounts foreach ( var discountUI in DiscountState ) { var discount = RegistrationTemplate.Discounts.FirstOrDefault( a => a.Guid.Equals( discountUI.Guid ) ); if ( discount == null ) { discount = new RegistrationTemplateDiscount(); discount.Guid = discountUI.Guid; RegistrationTemplate.Discounts.Add( discount ); } discount.Code = discountUI.Code; discount.DiscountPercentage = discountUI.DiscountPercentage; discount.DiscountAmount = discountUI.DiscountAmount; discount.Order = discountUI.Order; } // add/updated fees foreach ( var feeUI in FeeState ) { var fee = RegistrationTemplate.Fees.FirstOrDefault( a => a.Guid.Equals( feeUI.Guid ) ); if ( fee == null ) { fee = new RegistrationTemplateFee(); fee.Guid = feeUI.Guid; RegistrationTemplate.Fees.Add( fee ); } fee.Name = feeUI.Name; fee.FeeType = feeUI.FeeType; fee.CostValue = feeUI.CostValue; fee.DiscountApplies = feeUI.DiscountApplies; fee.AllowMultiple = feeUI.AllowMultiple; fee.Order = feeUI.Order; } rockContext.SaveChanges(); AttributeCache.FlushEntityAttributes(); // If this is a new template, give the current user and the Registration Administrators role administrative // rights to this template, and staff, and staff like roles edit rights if ( newTemplate ) { RegistrationTemplate.AllowPerson( Authorization.ADMINISTRATE, CurrentPerson, rockContext ); var registrationAdmins = groupService.Get( Rock.SystemGuid.Group.GROUP_EVENT_REGISTRATION_ADMINISTRATORS.AsGuid() ); RegistrationTemplate.AllowSecurityRole( Authorization.ADMINISTRATE, registrationAdmins, rockContext ); var staffLikeUsers = groupService.Get( Rock.SystemGuid.Group.GROUP_STAFF_LIKE_MEMBERS.AsGuid() ); RegistrationTemplate.AllowSecurityRole( Authorization.EDIT, staffLikeUsers, rockContext ); var staffUsers = groupService.Get( Rock.SystemGuid.Group.GROUP_STAFF_MEMBERS.AsGuid() ); RegistrationTemplate.AllowSecurityRole( Authorization.EDIT, staffUsers, rockContext ); } var qryParams = new Dictionary<string, string>(); qryParams["RegistrationTemplateId"] = RegistrationTemplate.Id.ToString(); NavigateToPage( RockPage.Guid, qryParams ); } }
/// <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 ) { ParseControls( true ); var rockContext = new RockContext(); var service = new RegistrationTemplateService( rockContext ); RegistrationTemplate RegistrationTemplate = null; int? RegistrationTemplateId = hfRegistrationTemplateId.Value.AsIntegerOrNull(); if ( RegistrationTemplateId.HasValue ) { RegistrationTemplate = service.Get( RegistrationTemplateId.Value ); } if ( RegistrationTemplate == null ) { RegistrationTemplate = new RegistrationTemplate(); } RegistrationNotify notify = RegistrationNotify.None; foreach( ListItem li in cblNotify.Items ) { if ( li.Selected ) { notify = notify | (RegistrationNotify)li.Value.AsInteger(); } } RegistrationTemplate.IsActive = cbIsActive.Checked; RegistrationTemplate.Name = tbName.Text; RegistrationTemplate.CategoryId = cpCategory.SelectedValueAsInt(); RegistrationTemplate.GroupTypeId = gtpGroupType.SelectedGroupTypeId; RegistrationTemplate.GroupMemberRoleId = rpGroupTypeRole.GroupRoleId; RegistrationTemplate.GroupMemberStatus = ddlGroupMemberStatus.SelectedValueAsEnum<GroupMemberStatus>(); RegistrationTemplate.Notify = notify; RegistrationTemplate.LoginRequired = cbLoginRequired.Checked; RegistrationTemplate.AllowMultipleRegistrants = cbMultipleRegistrants.Checked; RegistrationTemplate.MaxRegistrants = nbMaxRegistrants.Text.AsInteger(); RegistrationTemplate.RegistrantsSameFamily = rblRegistrantsInSameFamily.SelectedValueAsEnum<RegistrantsSameFamily>(); RegistrationTemplate.Cost = cbCost.Text.AsDecimal(); RegistrationTemplate.MinimumInitialPayment = cbMinimumInitialPayment.Text.AsDecimalOrNull(); RegistrationTemplate.FinancialGatewayId = fgpFinancialGateway.SelectedValueAsInt(); RegistrationTemplate.ConfirmationFromName = tbConfirmationFromName.Text; RegistrationTemplate.ConfirmationFromEmail = tbConfirmationFromEmail.Text; RegistrationTemplate.ConfirmationSubject = tbConfirmationSubject.Text; RegistrationTemplate.ConfirmationEmailTemplate = ceConfirmationEmailTemplate.Text; RegistrationTemplate.ReminderFromName = tbReminderFromName.Text; RegistrationTemplate.ReminderFromEmail = tbReminderFromEmail.Text; RegistrationTemplate.ReminderSubject = tbReminderSubject.Text; RegistrationTemplate.ReminderEmailTemplate = ceReminderEmailTemplate.Text; RegistrationTemplate.RegistrationTerm = string.IsNullOrWhiteSpace( tbRegistrationTerm.Text ) ? "Registration" : tbRegistrationTerm.Text; RegistrationTemplate.RegistrantTerm = string.IsNullOrWhiteSpace( tbRegistrantTerm.Text ) ? "Registrant" : tbRegistrantTerm.Text; RegistrationTemplate.FeeTerm = string.IsNullOrWhiteSpace( tbFeeTerm.Text ) ? "Additional Options" : tbFeeTerm.Text; RegistrationTemplate.DiscountCodeTerm = string.IsNullOrWhiteSpace( tbDiscountCodeTerm.Text ) ? "Discount Code" : tbDiscountCodeTerm.Text; RegistrationTemplate.SuccessTitle = tbSuccessTitle.Text; RegistrationTemplate.SuccessText = ceSuccessText.Text; if ( !Page.IsValid || !RegistrationTemplate.IsValid ) { return; } foreach ( var form in FormState ) { if ( !form.IsValid ) { return; } if ( FormFieldsState.ContainsKey( form.Guid ) ) { foreach( var formField in FormFieldsState[ form.Guid ]) { if ( !formField.IsValid ) { return; } } } } // Get the valid group member attributes var group = new Group(); group.GroupTypeId = gtpGroupType.SelectedGroupTypeId ?? 0; var groupMember = new GroupMember(); groupMember.Group = group; groupMember.LoadAttributes(); var validGroupMemberAttributeIds = groupMember.Attributes.Select( a => a.Value.Id ).ToList(); // Remove any group member attributes that are not valid based on selected group type foreach( var fieldList in FormFieldsState.Select( s => s.Value ) ) { foreach( var formField in fieldList .Where( a => a.FieldSource == RegistrationFieldSource.GroupMemberAttribute && a.AttributeId.HasValue && !validGroupMemberAttributeIds.Contains( a.AttributeId.Value ) ) .ToList() ) { fieldList.Remove( formField ); } } // Perform Validation var validationErrors = new List<string>(); if ( ( RegistrationTemplate.Cost > 0 || FeeState.Any() ) && !RegistrationTemplate.FinancialGatewayId.HasValue ) { validationErrors.Add( "A Financial Gateway is required when the registration has a cost or additional fees." ); } if ( validationErrors.Any() ) { nbValidationError.Visible = true; nbValidationError.Text = "<ul class='list-unstyled'><li>" + validationErrors.AsDelimited( "</li><li>" ) + "</li></ul>"; } else { rockContext.WrapTransaction( () => { // Save the entity field changes to registration template if ( RegistrationTemplate.Id.Equals( 0 ) ) { service.Add( RegistrationTemplate ); } rockContext.SaveChanges(); var attributeService = new AttributeService( rockContext ); var registrationTemplateFormService = new RegistrationTemplateFormService( rockContext ); var registrationTemplateFormFieldService = new RegistrationTemplateFormFieldService( rockContext ); var registrationTemplateDiscountService = new RegistrationTemplateDiscountService( rockContext ); var registrationTemplateFeeService = new RegistrationTemplateFeeService( rockContext ); // delete forms that aren't assigned in the UI anymore var formUiGuids = FormState.Select( f => f.Guid ).ToList(); foreach ( var form in registrationTemplateFormService .Queryable() .Where( f => f.RegistrationTemplateId == RegistrationTemplate.Id && !formUiGuids.Contains( f.Guid ) ) ) { registrationTemplateFormService.Delete( form ); } // delete discounts that aren't assigned in the UI anymore var discountUiGuids = DiscountState.Select( u => u.Guid ).ToList(); foreach ( var discount in registrationTemplateDiscountService .Queryable() .Where( d => d.RegistrationTemplateId == RegistrationTemplate.Id && !discountUiGuids.Contains( d.Guid ) ) ) { registrationTemplateDiscountService.Delete( discount ); } // delete fees that aren't assigned in the UI anymore var feeUiGuids = FeeState.Select( u => u.Guid ).ToList(); foreach ( var fee in registrationTemplateFeeService .Queryable() .Where( d => d.RegistrationTemplateId == RegistrationTemplate.Id && !feeUiGuids.Contains( d.Guid ) ) ) { registrationTemplateFeeService.Delete( fee ); } var attributesUI = FormFieldsState .SelectMany( s => s.Value.Where( a => a.FieldSource == RegistrationFieldSource.RegistrationAttribute && a.Attribute != null ) ) .Select( f => f.Attribute ); int? entityTypeId = EntityTypeCache.Read( typeof( Rock.Model.RegistrationRegistrant ) ).Id; var qualifierColumn = "RegistrationTemplateId"; var qualifierValue = RegistrationTemplate.Id.ToString(); // Get the existing registration attributes for this entity type and qualifier value var attributesDB = attributeService.Get( entityTypeId, qualifierColumn, qualifierValue ); // Delete any of the registration attributes that were removed in the UI var selectedAttributeGuids = attributesUI.Select( a => a.Guid ); foreach ( var attr in attributesDB.Where( a => !selectedAttributeGuids.Contains( a.Guid ) ) ) { attributeService.Delete( attr ); rockContext.SaveChanges(); Rock.Web.Cache.AttributeCache.Flush( attr.Id ); } // Update the registration attributes that were assigned in the UI foreach ( var attr in attributesUI ) { Helper.SaveAttributeEdits( attr, entityTypeId, qualifierColumn, qualifierValue, rockContext ); } // add/updated forms/fields foreach ( var formUI in FormState ) { var form = RegistrationTemplate.Forms.FirstOrDefault( f => f.Guid.Equals( formUI.Guid ) ); if ( form == null ) { form = new RegistrationTemplateForm(); form.Guid = formUI.Guid; RegistrationTemplate.Forms.Add( form ); } form.Name = formUI.Name; form.Order = formUI.Order; if ( FormFieldsState.ContainsKey( form.Guid ) ) { var fieldUiGuids = FormFieldsState[form.Guid].Select( a => a.Guid ).ToList(); foreach ( var formField in registrationTemplateFormFieldService .Queryable() .Where( a => a.RegistrationTemplateForm.Guid.Equals( form.Guid ) && !fieldUiGuids.Contains( a.Guid ) ) ) { registrationTemplateFormFieldService.Delete( formField ); } foreach ( var formFieldUI in FormFieldsState[form.Guid] ) { var formField = form.Fields.FirstOrDefault( a => a.Guid.Equals( formFieldUI.Guid ) ); if ( formField == null ) { formField = new RegistrationTemplateFormField(); formField.Guid = formFieldUI.Guid; form.Fields.Add( formField ); } formField.AttributeId = formFieldUI.AttributeId; if ( !formField.AttributeId.HasValue && formFieldUI.FieldSource == RegistrationFieldSource.RegistrationAttribute && formFieldUI.Attribute != null ) { var attr = AttributeCache.Read( formFieldUI.Attribute.Guid, rockContext ); if ( attr != null ) { formField.AttributeId = attr.Id; } } formField.FieldSource = formFieldUI.FieldSource; formField.PersonFieldType = formFieldUI.PersonFieldType; formField.IsSharedValue = formFieldUI.IsSharedValue; formField.ShowCurrentValue = formFieldUI.ShowCurrentValue; formField.PreText = formFieldUI.PreText; formField.PostText = formFieldUI.PostText; formField.IsGridField = formFieldUI.IsGridField; formField.IsRequired = formFieldUI.IsRequired; formField.Order = formFieldUI.Order; } } } // add/updated discounts foreach ( var discountUI in DiscountState ) { var discount = RegistrationTemplate.Discounts.FirstOrDefault( a => a.Guid.Equals( discountUI.Guid ) ); if ( discount == null ) { discount = new RegistrationTemplateDiscount(); discount.Guid = discountUI.Guid; RegistrationTemplate.Discounts.Add( discount ); } discount.Code = discountUI.Code; discount.DiscountPercentage = discountUI.DiscountPercentage; discount.DiscountAmount = discountUI.DiscountAmount; discount.Order = discountUI.Order; } // add/updated fees foreach ( var feeUI in FeeState ) { var fee = RegistrationTemplate.Fees.FirstOrDefault( a => a.Guid.Equals( feeUI.Guid ) ); if ( fee == null ) { fee = new RegistrationTemplateFee(); fee.Guid = feeUI.Guid; RegistrationTemplate.Fees.Add( fee ); } fee.Name = feeUI.Name; fee.FeeType = feeUI.FeeType; fee.CostValue = feeUI.CostValue; fee.DiscountApplies = feeUI.DiscountApplies; fee.AllowMultiple = feeUI.AllowMultiple; fee.Order = feeUI.Order; } rockContext.SaveChanges(); } ); var qryParams = new Dictionary<string, string>(); qryParams["RegistrationTemplateId"] = RegistrationTemplate.Id.ToString(); NavigateToPage( RockPage.Guid, qryParams ); } }
/// <summary> /// Adds any registration templates given in the XML file. /// </summary> /// <param name="elemFamilies"></param> /// <param name="rockContext"></param> private void AddRegistrationTemplates( XElement elemRegistrationTemplates, RockContext rockContext ) { if ( elemRegistrationTemplates == null ) { return; } // Get attribute values from RegistrationTemplateDetail block // Get instance of the attribute. string defaultConfirmationEmail = string.Empty; string defaultReminderEmail = string.Empty; string defaultSuccessText = string.Empty; string defaultPaymentReminderEmail = string.Empty; //CodeEditorFieldAttribute MyAttribute = (CodeEditorFieldAttribute)System.Attribute.GetCustomAttribute( typeof( RockWeb.Blocks.Event.RegistrationTemplateDetail ), typeof( CodeEditorFieldAttribute ) ); var blockAttributes = System.Attribute.GetCustomAttributes( typeof( RockWeb.Blocks.Event.RegistrationTemplateDetail ), typeof( CodeEditorFieldAttribute ) ); foreach ( CodeEditorFieldAttribute blockAttribute in blockAttributes ) { switch ( blockAttribute.Name ) { case "Default Confirmation Email": defaultConfirmationEmail = blockAttribute.DefaultValue; break; case "Default Reminder Email": defaultReminderEmail = blockAttribute.DefaultValue; break; case "Default Success Text": defaultSuccessText = blockAttribute.DefaultValue; break; case "Default Payment Reminder Email": defaultPaymentReminderEmail = blockAttribute.DefaultValue; break; default: break; } } RegistrationTemplateService registrationTemplateService = new RegistrationTemplateService( rockContext ); // Add a template for each... foreach ( var element in elemRegistrationTemplates.Elements( "registrationTemplate" ) ) { // skip any illegally formatted items if ( element.Attribute( "guid" ) == null ) { continue; } int categoryId = CategoryCache.Read( element.Attribute( "categoryGuid" ).Value.Trim().AsGuid() ).Id; // Find the group type and var groupType = GroupTypeCache.Read( element.Attribute( "groupTypeGuid" ).Value.Trim().AsGuid() ); RegistrantsSameFamily registrantsSameFamily; if ( element.Attribute( "registrantsInSameFamily" ) != null ) { Enum.TryParse( element.Attribute( "registrantsInSameFamily" ).Value.Trim(), out registrantsSameFamily ); } else { registrantsSameFamily = RegistrantsSameFamily.Ask; } bool setCostOnInstance = true; if ( element.Attribute( "setCostOn" ).Value.Trim() == "template" ) { setCostOnInstance = false; } RegistrationNotify notify = RegistrationNotify.None; RegistrationNotify matchNotify; foreach ( string item in element.Attribute( "notify" ).Value.SplitDelimitedValues( whitespace: false ) ) { if ( Enum.TryParse( item.Replace( " ", string.Empty ), out matchNotify ) ) { notify = notify | matchNotify; } } // Now find the matching financial gateway FinancialGatewayService financialGatewayService = new FinancialGatewayService( rockContext ); string gatewayName = element.Attribute( "financialGateway" ) != null ? element.Attribute( "financialGateway" ).Value : "Test Gateway"; var financialGateway = financialGatewayService.Queryable() .Where( g => g.Name == gatewayName ) .FirstOrDefault(); RegistrationTemplate registrationTemplate = new RegistrationTemplate() { Guid = element.Attribute( "guid" ).Value.Trim().AsGuid(), Name = element.Attribute( "name" ).Value.Trim(), IsActive = true, CategoryId = categoryId, GroupTypeId = groupType.Id, GroupMemberRoleId = groupType.DefaultGroupRoleId, GroupMemberStatus = GroupMemberStatus.Active, Notify = notify, AddPersonNote = element.Attribute( "addPersonNote" ) != null ? element.Attribute( "addPersonNote" ).Value.AsBoolean() : false, LoginRequired = element.Attribute( "loginRequired" ) != null ? element.Attribute( "loginRequired" ).Value.AsBoolean() : false, AllowExternalRegistrationUpdates = element.Attribute( "allowExternalUpdatesToSavedRegistrations" ) != null ? element.Attribute( "allowExternalUpdatesToSavedRegistrations" ).Value.AsBoolean() : false, AllowGroupPlacement = element.Attribute( "allowGroupPlacement" ) != null ? element.Attribute( "allowGroupPlacement" ).Value.AsBoolean() : false, AllowMultipleRegistrants = element.Attribute( "allowMultipleRegistrants" ) != null ? element.Attribute( "allowMultipleRegistrants" ).Value.AsBoolean() : false, MaxRegistrants = element.Attribute( "maxRegistrants" ).Value.AsInteger(), RegistrantsSameFamily = registrantsSameFamily, SetCostOnInstance = setCostOnInstance, FinancialGatewayId = financialGateway.Id, BatchNamePrefix = element.Attribute( "batchNamePrefix" ) != null ? element.Attribute( "batchNamePrefix" ).Value.Trim() : string.Empty, Cost = element.Attribute( "cost" ).Value.AsDecimal(), MinimumInitialPayment = element.Attribute( "minInitialPayment" ).Value.AsDecimal(), RegistrationTerm = element.Attribute( "registrationTerm" ) != null ? element.Attribute( "registrationTerm" ).Value.Trim() : "Registration", RegistrantTerm = element.Attribute( "registrantTerm" ) != null ? element.Attribute( "registrantTerm" ).Value.Trim() : "Registrant", FeeTerm = element.Attribute( "feeTerm" ) != null ? element.Attribute( "feeTerm" ).Value.Trim() : "Additional Options", DiscountCodeTerm = element.Attribute( "discountCodeTerm" ) != null ? element.Attribute( "discountCodeTerm" ).Value.Trim() : "Discount Code", ConfirmationFromName = "{{ RegistrationInstance.ContactPersonAlias.Person.FullName }}", ConfirmationFromEmail = "{{ RegistrationInstance.ContactEmail }}", ConfirmationSubject = "{{ RegistrationInstance.Name }} Confirmation", ConfirmationEmailTemplate = defaultConfirmationEmail, ReminderFromName = "{{ RegistrationInstance.ContactPersonAlias.Person.FullName }}", ReminderFromEmail = "{{ RegistrationInstance.ContactEmail }}", ReminderSubject = "{{ RegistrationInstance.Name }} Reminder", ReminderEmailTemplate = defaultReminderEmail, SuccessTitle = "Congratulations {{ Registration.FirstName }}", SuccessText = defaultSuccessText, PaymentReminderEmailTemplate = defaultPaymentReminderEmail, PaymentReminderFromEmail = "{{ RegistrationInstance.ContactEmail }}", PaymentReminderFromName = "{{ RegistrationInstance.ContactPersonAlias.Person.FullName }}", PaymentReminderSubject = "{{ RegistrationInstance.Name }} Payment Reminder", PaymentReminderTimeSpan = element.Attribute( "paymentReminderTimeSpan" ) != null ? element.Attribute( "paymentReminderTimeSpan" ).Value.AsInteger() : 0, CreatedDateTime = RockDateTime.Now, ModifiedDateTime = RockDateTime.Now, }; registrationTemplateService.Add( registrationTemplate ); rockContext.SaveChanges(); var x = registrationTemplate.Id; string name = element.Attribute( "name" ).Value.Trim(); bool allowExternalUpdatesToSavedRegistrations = element.Attribute( "allowExternalUpdatesToSavedRegistrations" ).Value.AsBoolean(); bool addPersonNote = element.Attribute( "addPersonNote" ).Value.AsBoolean(); bool loginRequired = element.Attribute( "loginRequired" ).Value.AsBoolean(); Guid guid = element.Attribute( "guid" ).Value.Trim().AsGuid(); // Find any Form elements and add them to the template int formOrder = 0; var registrationAttributeQualifierColumn = "RegistrationTemplateId"; int? registrationRegistrantEntityTypeId = EntityTypeCache.Read( typeof( Rock.Model.RegistrationRegistrant ) ).Id; if ( element.Elements( "forms" ).Count() > 0 ) { foreach ( var formElement in element.Elements( "forms" ).Elements( "form" ) ) { formOrder++; var form = new RegistrationTemplateForm(); form.Guid = formElement.Attribute( "guid" ).Value.Trim().AsGuid(); registrationTemplate.Forms.Add( form ); form.Name = formElement.Attribute( "name" ).Value.Trim(); form.Order = formOrder; int ffOrder = 0; if ( formElement.Elements( "formFields" ).Count() > 0 ) { foreach ( var formFieldElement in formElement.Elements( "formFields" ).Elements( "field" ) ) { ffOrder++; var formField = new RegistrationTemplateFormField(); formField.Guid = Guid.NewGuid(); formField.CreatedDateTime = RockDateTime.Now; form.Fields.Add( formField ); switch ( formFieldElement.Attribute( "source" ).Value.Trim().ToLowerInvariant() ) { case "person field": formField.FieldSource = RegistrationFieldSource.PersonField; break; case "person attribute": formField.FieldSource = RegistrationFieldSource.PersonAttribute; break; case "group member attribute": formField.FieldSource = RegistrationFieldSource.GroupMemberAttribute; break; case "registration attribute": formField.FieldSource = RegistrationFieldSource.RegistrationAttribute; //var qualifierValue = RegistrationTemplate.Id.ToString(); var attrState = new Rock.Model.Attribute(); attrState.Guid = formFieldElement.Attribute( "guid" ).Value.AsGuid(); attrState.Name = formFieldElement.Attribute( "name" ).Value.Trim(); attrState.Key = attrState.Name.RemoveSpecialCharacters().Replace( " ", string.Empty ); var type = formFieldElement.Attribute( "type" ).Value.Trim(); var fieldType = FieldTypeCache.All().Where( f => f.Name == type ).FirstOrDefault(); attrState.FieldTypeId = fieldType.Id; var attribute = Helper.SaveAttributeEdits( attrState, registrationRegistrantEntityTypeId, registrationAttributeQualifierColumn, registrationTemplate.Id.ToString(), rockContext ); //rockContext.ChangeTracker.DetectChanges(); rockContext.SaveChanges( disablePrePostProcessing: true ); formField.Attribute = attribute; break; default: throw new NotSupportedException( string.Format( "unknown form field source: {0}", formFieldElement.Attribute( "source" ).Value ) ); } formField.AttributeId = null; if ( !formField.AttributeId.HasValue && formField.FieldSource == RegistrationFieldSource.RegistrationAttribute && formField.Attribute != null ) { var attr = AttributeCache.Read( formField.Attribute.Guid, rockContext ); if ( attr != null ) { formField.AttributeId = attr.Id; } } RegistrationPersonFieldType registrationPersonFieldType; if ( formField.FieldSource == RegistrationFieldSource.PersonField && formFieldElement.Attribute( "name" ) != null && Enum.TryParse( formFieldElement.Attribute( "name" ).Value.Replace( " ", string.Empty ).Trim(), out registrationPersonFieldType ) ) { formField.PersonFieldType = registrationPersonFieldType; } formField.IsInternal = formFieldElement.Attribute( "isInternal" ) != null ? formFieldElement.Attribute( "isInternal" ).Value.AsBoolean() : false; formField.IsSharedValue = formFieldElement.Attribute( "isCommon" ) != null ? formFieldElement.Attribute( "isCommon" ).Value.AsBoolean() : false; formField.ShowCurrentValue = formFieldElement.Attribute( "showCurrentValue" ) != null ? formFieldElement.Attribute( "showCurrentValue" ).Value.AsBoolean() : false; formField.PreText = formFieldElement.Attribute( "preText" ) != null ? formFieldElement.Attribute( "preText" ).Value : string.Empty; formField.PostText = formFieldElement.Attribute( "postText" ) != null ? formFieldElement.Attribute( "postText" ).Value : string.Empty; formField.IsGridField = formFieldElement.Attribute( "showOnGrid" ) != null ? formFieldElement.Attribute( "showOnGrid" ).Value.AsBoolean() : false; formField.IsRequired = formFieldElement.Attribute( "isRequired" ) != null ? formFieldElement.Attribute( "isRequired" ).Value.AsBoolean() : false; formField.Order = ffOrder; formField.CreatedDateTime = RockDateTime.Now; } } } } // Discounts int discountOrder = 0; if ( element.Elements( "discounts" ) != null ) { foreach ( var discountElement in element.Elements( "discounts" ).Elements( "discount" ) ) { discountOrder++; var discount = new RegistrationTemplateDiscount(); discount.Guid = Guid.NewGuid(); registrationTemplate.Discounts.Add( discount ); discount.Code = discountElement.Attribute( "code" ).Value; switch ( discountElement.Attribute( "type" ).Value.Trim().ToLowerInvariant() ) { case "percentage": discount.DiscountPercentage = discountElement.Attribute( "value" ).Value.Trim().AsDecimal() * 0.01m; discount.DiscountAmount = 0.0m; break; case "amount": discount.DiscountPercentage = 0.0m; discount.DiscountAmount = discountElement.Attribute( "value" ).Value.Trim().AsDecimal(); break; default: throw new NotSupportedException( string.Format( "unknown discount type: {0}", discountElement.Attribute( "type" ).Value ) ); } discount.Order = discountOrder; } } // Fees int feeOrder = 0; if ( element.Elements( "fees" ) != null ) { foreach ( var feeElement in element.Elements( "fees" ).Elements( "fee" ) ) { feeOrder++; var fee = new RegistrationTemplateFee(); fee.Guid = Guid.NewGuid(); registrationTemplate.Fees.Add( fee ); switch ( feeElement.Attribute( "type" ).Value.Trim().ToLowerInvariant() ) { case "multiple": fee.FeeType = RegistrationFeeType.Multiple; fee.CostValue = FormatMultipleFeeCosts( feeElement.Elements( "option" ) ); break; case "single": fee.FeeType = RegistrationFeeType.Single; fee.CostValue = feeElement.Attribute( "cost" ).Value.Trim(); break; default: throw new NotSupportedException( string.Format( "unknown fee type: {0}", feeElement.Attribute( "type" ).Value ) ); } fee.Name = feeElement.Attribute( "name" ).Value.Trim(); fee.DiscountApplies = feeElement.Attribute( "discountApplies" ).Value.AsBoolean(); fee.AllowMultiple = feeElement.Attribute( "enableQuantity" ).Value.AsBoolean(); fee.Order = feeOrder; } } } }
/// <summary> /// Shows the edit details. /// </summary> /// <param name="RegistrationTemplate">The registration template.</param> /// <param name="rockContext">The rock context.</param> private void ShowEditDetails( RegistrationTemplate RegistrationTemplate, RockContext rockContext ) { if ( RegistrationTemplate.Id == 0 ) { lReadOnlyTitle.Text = ActionTitle.Add( RegistrationTemplate.FriendlyTypeName ).FormatAsHtmlTitle(); hlInactive.Visible = false; hlType.Visible = false; } else { pwDetails.Expanded = false; } SetEditMode( true ); LoadDropDowns( rockContext ); cbIsActive.Checked = RegistrationTemplate.IsActive; tbName.Text = RegistrationTemplate.Name; cpCategory.SetValue( RegistrationTemplate.CategoryId ); gtpGroupType.SelectedGroupTypeId = RegistrationTemplate.GroupTypeId; rpGroupTypeRole.GroupTypeId = RegistrationTemplate.GroupTypeId ?? 0; rpGroupTypeRole.GroupRoleId = RegistrationTemplate.GroupMemberRoleId; ddlGroupMemberStatus.SetValue( RegistrationTemplate.GroupMemberStatus.ConvertToInt() ); ddlSignatureDocumentTemplate.SetValue( RegistrationTemplate.RequiredSignatureDocumentTemplateId ); cbDisplayInLine.Checked = RegistrationTemplate.SignatureDocumentAction == SignatureDocumentAction.Embed; wtpRegistrationWorkflow.SetValue( RegistrationTemplate.RegistrationWorkflowTypeId ); foreach( ListItem li in cblNotify.Items ) { RegistrationNotify notify = (RegistrationNotify)li.Value.AsInteger(); li.Selected = ( RegistrationTemplate.Notify & notify ) == notify; } cbAddPersonNote.Checked = RegistrationTemplate.AddPersonNote; cbLoginRequired.Checked = RegistrationTemplate.LoginRequired; cbAllowExternalUpdates.Checked = RegistrationTemplate.AllowExternalRegistrationUpdates; cbAllowGroupPlacement.Checked = RegistrationTemplate.AllowGroupPlacement; cbMultipleRegistrants.Checked = RegistrationTemplate.AllowMultipleRegistrants; nbMaxRegistrants.Visible = RegistrationTemplate.AllowMultipleRegistrants; nbMaxRegistrants.Text = RegistrationTemplate.MaxRegistrants.ToString(); rblRegistrantsInSameFamily.SetValue( RegistrationTemplate.RegistrantsSameFamily.ConvertToInt() ); cbShowCurrentFamilyMembers.Checked = RegistrationTemplate.ShowCurrentFamilyMembers; tglSetCostOnTemplate.Checked = !RegistrationTemplate.SetCostOnInstance.HasValue || !RegistrationTemplate.SetCostOnInstance.Value; cbCost.Text = RegistrationTemplate.Cost.ToString(); cbMinimumInitialPayment.Text = RegistrationTemplate.MinimumInitialPayment.HasValue ? RegistrationTemplate.MinimumInitialPayment.Value.ToString( "N2" ) : ""; fgpFinancialGateway.SetValue( RegistrationTemplate.FinancialGatewayId ); txtBatchNamePrefix.Text = RegistrationTemplate.BatchNamePrefix; SetCostVisibility(); tbConfirmationFromName.Text = RegistrationTemplate.ConfirmationFromName; tbConfirmationFromEmail.Text = RegistrationTemplate.ConfirmationFromEmail; tbConfirmationSubject.Text = RegistrationTemplate.ConfirmationSubject; ceConfirmationEmailTemplate.Text = RegistrationTemplate.ConfirmationEmailTemplate; tbReminderFromName.Text = RegistrationTemplate.ReminderFromName; tbReminderFromEmail.Text = RegistrationTemplate.ReminderFromEmail; tbReminderSubject.Text = RegistrationTemplate.ReminderSubject; ceReminderEmailTemplate.Text = RegistrationTemplate.ReminderEmailTemplate; tbPaymentReminderFromName.Text = RegistrationTemplate.PaymentReminderFromName; tbPaymentReminderFromEmail.Text = RegistrationTemplate.PaymentReminderFromEmail; tbPaymentReminderSubject.Text = RegistrationTemplate.PaymentReminderSubject; cePaymentReminderEmailTemplate.Text = RegistrationTemplate.PaymentReminderEmailTemplate; nbPaymentReminderTimeSpan.Text = RegistrationTemplate.PaymentReminderTimeSpan.ToString(); tbRegistrationTerm.Text = RegistrationTemplate.RegistrationTerm; tbRegistrantTerm.Text = RegistrationTemplate.RegistrantTerm; tbFeeTerm.Text = RegistrationTemplate.FeeTerm; tbDiscountCodeTerm.Text = RegistrationTemplate.DiscountCodeTerm; tbSuccessTitle.Text = RegistrationTemplate.SuccessTitle; ceSuccessText.Text = RegistrationTemplate.SuccessText; BuildControls( true ); }
public UserInfo(RegistrationTemplate info) { this.Info = info; }
private void LoadState() { int? registrantId = PageParameter( "RegistrantId" ).AsIntegerOrNull(); int? registrationId = PageParameter( "RegistrationId" ).AsIntegerOrNull(); if ( RegistrantState == null ) { var rockContext = new RockContext(); RegistrationRegistrant registrant = null; if ( registrantId.HasValue && registrantId.Value != 0 ) { registrant = new RegistrationRegistrantService( rockContext ) .Queryable( "Registration.RegistrationInstance.RegistrationTemplate.Forms.Fields,Registration.RegistrationInstance.RegistrationTemplate.Fees,PersonAlias.Person,Fees" ).AsNoTracking() .Where( r => r.Id == registrantId.Value ) .FirstOrDefault(); if ( registrant != null && registrant.Registration != null && registrant.Registration.RegistrationInstance != null && registrant.Registration.RegistrationInstance.RegistrationTemplate != null ) { RegistrantState = new RegistrantInfo( registrant, rockContext ); TemplateState = registrant.Registration.RegistrationInstance.RegistrationTemplate; RegistrationInstanceId = registrant.Registration.RegistrationInstanceId; lWizardTemplateName.Text = registrant.Registration.RegistrationInstance.RegistrationTemplate.Name; lWizardInstanceName.Text = registrant.Registration.RegistrationInstance.Name; lWizardRegistrationName.Text = registrant.Registration.ToString(); lWizardRegistrantName.Text = registrant.ToString(); } } if ( TemplateState == null && registrationId.HasValue && registrationId.Value != 0 ) { var registration = new RegistrationService( rockContext ) .Queryable( "RegistrationInstance.RegistrationTemplate.Forms.Fields,RegistrationInstance.RegistrationTemplate.Fees" ).AsNoTracking() .Where( r => r.Id == registrationId.Value ) .FirstOrDefault(); if ( registration != null && registration.RegistrationInstance != null && registration.RegistrationInstance.RegistrationTemplate != null ) { TemplateState = registration.RegistrationInstance.RegistrationTemplate; RegistrationInstanceId = registration.RegistrationInstanceId; lWizardTemplateName.Text = registration.RegistrationInstance.RegistrationTemplate.Name; lWizardInstanceName.Text = registration.RegistrationInstance.Name; lWizardRegistrationName.Text = registration.ToString(); lWizardRegistrantName.Text = "New Registrant"; } } if ( TemplateState != null && RegistrantState == null ) { RegistrantState = new RegistrantInfo(); RegistrantState.RegistrationId = registrationId ?? 0; RegistrantState.Cost = TemplateState.Cost; } if ( registrant != null && registrant.PersonAlias != null && registrant.PersonAlias.Person != null ) { ppPerson.SetValue( registrant.PersonAlias.Person ); } else { ppPerson.SetValue( null ); } if ( RegistrantState != null ) { cbCost.Text = RegistrantState.Cost.ToString( "N2" ); } } }
/// <summary> /// Restores the view-state information from a previous user control request that was saved by the <see cref="M:System.Web.UI.UserControl.SaveViewState" /> method. /// </summary> /// <param name="savedState">An <see cref="T:System.Object" /> that represents the user control state to be restored.</param> protected override void LoadViewState( object savedState ) { base.LoadViewState( savedState ); string json = ViewState["Template"] as string; if ( !string.IsNullOrWhiteSpace( json ) ) { TemplateState = JsonConvert.DeserializeObject<RegistrationTemplate>( json ); } json = ViewState["Registrant"] as string; if ( !string.IsNullOrWhiteSpace( json ) ) { RegistrantState = JsonConvert.DeserializeObject<RegistrantInfo>( json ); } RegistrationInstanceId = ViewState["RegistrationInstanceId"] as int? ?? 0; BuildControls( false ); }
/// <summary> /// Restores the view-state information from a previous user control request that was saved by the <see cref="M:System.Web.UI.UserControl.SaveViewState" /> method. /// </summary> /// <param name="savedState">An <see cref="T:System.Object" /> that represents the user control state to be restored.</param> protected override void LoadViewState( object savedState ) { base.LoadViewState( savedState ); Title = ViewState["Title"] as string ?? string.Empty; RegistrationInstanceId = ViewState["RegistrationInstanceId"] as int?; RegistrationId = ViewState["RegistrationId"] as int?; EditAllowed = ViewState["EditAllowed"] as bool? ?? false; PercentageDiscountExists = ViewState["PercentageDiscountExists"] as bool? ?? false; string json = ViewState["RegistrationTemplate"] as string; if ( !string.IsNullOrWhiteSpace( json ) ) { RegistrationTemplateState = JsonConvert.DeserializeObject<RegistrationTemplate>( json ); } json = ViewState["Registrants"] as string; if ( !string.IsNullOrWhiteSpace( json ) ) { RegistrantsState = JsonConvert.DeserializeObject<List<RegistrantInfo>>( json ); } if ( RegistrationTemplateState != null && RegistrantsState != null ) { BuildRegistrationControls( false ); } Registration = GetRegistration( RegistrationId ); }
private void LoadState() { if ( !RegistrationInstanceId.HasValue ) { Title = "New Registration"; RegistrationInstanceId = PageParameter( "RegistrationInstanceId" ).AsIntegerOrNull(); RegistrationId = PageParameter( "RegistrationId" ).AsIntegerOrNull(); var rockContext = new RockContext(); if ( RegistrationId.HasValue ) { Registration = GetRegistration( RegistrationId.Value, rockContext ); if ( Registration != null ) { Title = Registration.ToString(); RegistrationInstanceId = Registration.RegistrationInstanceId; RegistrationTemplateState = Registration.RegistrationInstance.RegistrationTemplate; lWizardTemplateName.Text = Registration.RegistrationInstance.RegistrationTemplate.Name; lWizardInstanceName.Text = Registration.RegistrationInstance.Name; lWizardRegistrationName.Text = Registration.ToString(); } } EditAllowed = IsUserAuthorized( Authorization.EDIT ) || ( Registration != null && Registration.IsAuthorized( Authorization.EDIT, CurrentPerson ) ); if ( RegistrationTemplateState == null && RegistrationInstanceId.HasValue ) { var registrationInstance = new RegistrationInstanceService( rockContext ) .Queryable( "RegistrationTemplate" ).AsNoTracking() .Where( i => i.Id == RegistrationInstanceId.Value ) .FirstOrDefault(); if ( registrationInstance != null ) { lWizardTemplateName.Text = registrationInstance.RegistrationTemplate.Name; lWizardInstanceName.Text = registrationInstance.Name; lWizardRegistrationName.Text = "New Registration"; RegistrationTemplateState = registrationInstance.RegistrationTemplate; EditAllowed = EditAllowed || registrationInstance.RegistrationTemplate.IsAuthorized( Authorization.EDIT, CurrentPerson ); } } } }
/// <summary> /// Shows the readonly details. /// </summary> /// <param name="RegistrationTemplate">The registration template.</param> private void ShowReadonlyDetails( RegistrationTemplate RegistrationTemplate ) { SetEditMode( false ); hfRegistrationTemplateId.SetValue( RegistrationTemplate.Id ); FormState = null; ExpandedForms = null; DiscountState = null; FeeState = null; lReadOnlyTitle.Text = RegistrationTemplate.Name.FormatAsHtmlTitle(); hlInactive.Visible = RegistrationTemplate.IsActive == false; hlType.Visible = RegistrationTemplate.Category != null; hlType.Text = RegistrationTemplate.Category != null ? RegistrationTemplate.Category.Name : string.Empty; lGroupType.Text = RegistrationTemplate.GroupType != null ? RegistrationTemplate.GroupType.Name : string.Empty; lRequiredSignedDocument.Text = RegistrationTemplate.RequiredSignatureDocumentTemplate != null ? RegistrationTemplate.RequiredSignatureDocumentTemplate.Name : string.Empty; lRequiredSignedDocument.Visible = !string.IsNullOrWhiteSpace( lRequiredSignedDocument.Text ); lWorkflowType.Text = RegistrationTemplate.RegistrationWorkflowType != null ? RegistrationTemplate.RegistrationWorkflowType.Name : string.Empty; lWorkflowType.Visible = !string.IsNullOrWhiteSpace( lWorkflowType.Text ); rcwForms.Label = string.Format( "<strong>Forms</strong> ({0}) <i class='fa fa-caret-down'></i>", RegistrationTemplate.Forms.Count() ); if ( RegistrationTemplate.Forms.Any() ) { foreach ( var form in RegistrationTemplate.Forms.OrderBy( a => a.Order ) ) { string formTextFormat = @" <br/><strong>{0}</strong> {1} "; string attributeText = string.Empty; foreach ( var formField in form.Fields.OrderBy( a => a.Order ) ) { string formFieldName = ( formField.Attribute != null ) ? formField.Attribute.Name : formField.PersonFieldType.ConvertToString(); string fieldTypeName = ( formField.Attribute != null ) ? FieldTypeCache.GetName( formField.Attribute.FieldTypeId ) : ""; attributeText += string.Format( @" <div class='row'> <div class='col-sm-1'></div> <div class='col-sm-4'>{0}</div> <div class='col-sm-3'>{1}</div> <div class='col-sm-4'>{2}</div> </div> ", formFieldName, fieldTypeName, formField.FieldSource.ConvertToString() ); } lFormsReadonly.Text += string.Format( formTextFormat, form.Name, attributeText ); } } else { lFormsReadonly.Text = "<div>" + None.TextHtml + "</div>"; } if ( RegistrationTemplate.SetCostOnInstance ?? false ) { lCost.Text = "Set on Instance"; lMinimumInitialPayment.Text = "Set on Instance"; } else { lCost.Text = RegistrationTemplate.Cost.FormatAsCurrency(); lMinimumInitialPayment.Visible = RegistrationTemplate.MinimumInitialPayment.HasValue; lMinimumInitialPayment.Text = RegistrationTemplate.MinimumInitialPayment.HasValue ? RegistrationTemplate.MinimumInitialPayment.Value.FormatAsCurrency() : ""; } rFees.DataSource = RegistrationTemplate.Fees.OrderBy( f => f.Order ).ToList(); rFees.DataBind(); }
/// <summary> /// Raises the <see cref="E:System.Web.UI.Control.Init" /> event. /// </summary> /// <param name="e">An <see cref="T:System.EventArgs" /> object that contains the event data.</param> protected override void OnInit( EventArgs e ) { base.OnInit( e ); int templateId = PageParameter( "RegistrationTemplateId" ).AsInteger(); if ( templateId != 0 ) { _template = GetRegistrationTemplate( templateId ); if ( _template != null && _template.IsAuthorized( Authorization.VIEW, CurrentPerson ) ) { _canView = true; rFilter.ApplyFilterClick += rFilter_ApplyFilterClick; gInstances.DataKeyNames = new string[] { "Id" }; gInstances.RowDataBound += gInstances_RowDataBound; gInstances.Actions.AddClick += gInstances_AddClick; gInstances.GridRebind += gInstances_GridRebind; gInstances.ExportFilename = _template.Name; gInstances.ShowConfirmDeleteDialog = false; // make sure they have Auth to edit the block OR edit to the Group bool canEditBlock = IsUserAuthorized( Authorization.EDIT ) || _template.IsAuthorized( Authorization.EDIT, this.CurrentPerson ); gInstances.Actions.ShowAdd = canEditBlock; gInstances.IsDeleteEnabled = canEditBlock; } } string deleteScript = @" $('table.js-grid-instances a.grid-delete-button').click(function( e ){ e.preventDefault(); Rock.dialogs.confirm('Are you sure you want to delete this registration instance? All of the registrations and registrants will also be deleted!', function (result) { if (result) { Rock.dialogs.confirm('Are you really sure? ', function (result) { if (result) { window.location = e.target.href ? e.target.href : e.target.parentElement.href; } }); } }); }); "; ScriptManager.RegisterStartupScript( gInstances, gInstances.GetType(), "deleteInstanceScript", deleteScript, true ); }
public void TryAuthtorizait(bool isNeedRefreshUserData) { try { FileStream fs = new FileStream(RegistrationTemplate.AuthTokenFileName, FileMode.Open, FileAccess.Read); BinaryFormatter formatter = new BinaryFormatter(); RegistrationTemplate regTempl = formatter.Deserialize(fs) as RegistrationTemplate; if (regTempl != null) { if (isNeedRefreshUserData) { fs.Close(); RRTemplate response = Client.ServerRequest(new RRTemplate(RRType.RefreshUserData, new AuthtorizationTemplate(regTempl.Login, ""))); switch (response.RRType) { case RRType.RefreshUserData: RegistrationTemplate regResponseObj = response.RRObject as RegistrationTemplate; if (regResponseObj != null) { UserInfo.Info = regResponseObj; } break; default: ErrorService(response.RRObject as ErrorReportTemplate); break; } } if (UserInfo.Info != null) { if (UserInfo.Info.IsBlocked) { CurrentPage = new BlockPage(this); } else { CurrentPage = new MainPage(this); NotifyUserByRowState(RowStateResourcesName.l_sAuth); } } } else { CurrentPage = new AuhtorizationPage(this); } } catch (FileNotFoundException ex) { CurrentPage = new Pages.AuhtorizationPage(this); } catch (SocketException ex) { NotifyUserByRowState(RowStateResourcesName.l_noConWithServer); } catch (Exception ex) { MessageBox.Show(ex.Message + " (ИЗ MainViewModel!!!!)"); } }
/// <summary> /// Shows the edit details. /// </summary> /// <param name="RegistrationTemplate">The registration template.</param> /// <param name="rockContext">The rock context.</param> private void ShowEditDetails( RegistrationTemplate RegistrationTemplate, RockContext rockContext ) { if ( RegistrationTemplate.Id == 0 ) { lReadOnlyTitle.Text = ActionTitle.Add( RegistrationTemplate.FriendlyTypeName ).FormatAsHtmlTitle(); hlInactive.Visible = false; hlType.Visible = false; } else { pwDetails.Expanded = false; } SetEditMode( true ); LoadDropDowns( rockContext ); cbIsActive.Checked = RegistrationTemplate.IsActive; tbName.Text = RegistrationTemplate.Name; cpCategory.SetValue( RegistrationTemplate.CategoryId ); gtpGroupType.SelectedGroupTypeId = RegistrationTemplate.GroupTypeId; rpGroupTypeRole.GroupTypeId = RegistrationTemplate.GroupTypeId ?? 0; rpGroupTypeRole.GroupRoleId = RegistrationTemplate.GroupMemberRoleId; ddlGroupMemberStatus.SetValue( RegistrationTemplate.GroupMemberStatus.ConvertToInt() ); foreach( ListItem li in cblNotify.Items ) { RegistrationNotify notify = (RegistrationNotify)li.Value.AsInteger(); li.Selected = ( RegistrationTemplate.Notify & notify ) == notify; } cbLoginRequired.Checked = RegistrationTemplate.LoginRequired; cbMultipleRegistrants.Checked = RegistrationTemplate.AllowMultipleRegistrants; nbMaxRegistrants.Visible = RegistrationTemplate.AllowMultipleRegistrants; nbMaxRegistrants.Text = RegistrationTemplate.MaxRegistrants.ToString(); rblRegistrantsInSameFamily.SetValue( RegistrationTemplate.RegistrantsSameFamily.ConvertToInt() ); cbCost.Text = RegistrationTemplate.Cost.ToString(); cbMinimumInitialPayment.Text = RegistrationTemplate.MinimumInitialPayment.HasValue ? RegistrationTemplate.MinimumInitialPayment.Value.ToString( "N2" ) : ""; fgpFinancialGateway.SetValue( RegistrationTemplate.FinancialGatewayId ); tbConfirmationFromName.Text = RegistrationTemplate.ConfirmationFromName; tbConfirmationFromEmail.Text = RegistrationTemplate.ConfirmationFromEmail; tbConfirmationSubject.Text = RegistrationTemplate.ConfirmationSubject; ceConfirmationEmailTemplate.Text = RegistrationTemplate.ConfirmationEmailTemplate; tbReminderFromName.Text = RegistrationTemplate.ReminderFromName; tbReminderFromEmail.Text = RegistrationTemplate.ReminderFromEmail; tbReminderSubject.Text = RegistrationTemplate.ReminderSubject; ceReminderEmailTemplate.Text = RegistrationTemplate.ReminderEmailTemplate; tbRegistrationTerm.Text = RegistrationTemplate.RegistrationTerm; tbRegistrantTerm.Text = RegistrationTemplate.RegistrantTerm; tbFeeTerm.Text = RegistrationTemplate.FeeTerm; tbDiscountCodeTerm.Text = RegistrationTemplate.DiscountCodeTerm; tbSuccessTitle.Text = RegistrationTemplate.SuccessTitle; ceSuccessText.Text = RegistrationTemplate.SuccessText; BuildControls( true ); }