Ejemplo n.º 1
0
        //[ValidateAntiForgeryToken]
        public ActionResult Edit(RegistrantInfo registrantinfo)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    RegistrantInfo registrantInfoOld = _context.RegistrantInfos.Find(registrantinfo.RegistrantInfoId);
                    registrantInfoOld.Update(registrantinfo);

                    //_context.Entry(registrantinfo).State = EntityState.Modified;
                    _context.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }
            catch (DataException ex)
            {
                string msg = ex + "\r\n"
                             + "Unable to save changes. Try again, and if the problem persists see your system administrator.";

                //Log the error (add a variable name after DataException)
                ModelState.AddModelError("", msg);
            }
            catch (Exception ex)
            {
                ViewBag.ErrorMessage = ex.Message;
            }
            ViewBag.RegistrantInfoId = new SelectList(_context.UserProfiles, "UserId", "UserName", registrantinfo.RegistrantInfoId);
            return(View(registrantinfo));
        }
Ejemplo n.º 2
0
        //[ValidateAntiForgeryToken]
        public ActionResult Create(RegistrantInfo registrantinfo, int userId)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    UserProfile user = _context.UserProfiles.Find(userId);
                    registrantinfo.ExamNumber  = user.UserName + GetRandomString();
                    registrantinfo.UserProfile = user;
                    _context.RegistrantInfos.Add(registrantinfo);
                    _context.SaveChanges();
                    return(RedirectToAction("ExamNumber", new { userId }));
                }
            }
            catch (DataException ex)
            {
                string msg = ex + "\r\n"
                             + "Unable to save changes. Try again, and if the problem persists see your system administrator.";

                //Log the error (add a variable name after DataException)
                ModelState.AddModelError("", msg);
            }
            catch (Exception ex)
            {
                ViewBag.ErrorMessage = ex.Message;
            }

            ViewBag.RegistrantInfoId = new SelectList(_context.UserProfiles, "UserId", "UserName", registrantinfo.RegistrantInfoId);
            return(View(registrantinfo));
        }
Ejemplo n.º 3
0
        //
        // GET: /RegistrantInfo/Details/5

        public ActionResult Details(int id = 0)
        {
            RegistrantInfo registrantinfo = _context.RegistrantInfos.Find(id);

            if (registrantinfo == null)
            {
                return(HttpNotFound());
            }
            return(View(registrantinfo));
        }
Ejemplo n.º 4
0
        //
        // GET: /RegistrantInfo/Edit/5

        public ActionResult Edit(int id = 0)
        {
            RegistrantInfo registrantinfo = _context.RegistrantInfos.Find(id);

            if (registrantinfo == null)
            {
                return(HttpNotFound());
            }
            ViewBag.RegistrantInfoId = new SelectList(_context.UserProfiles, "UserId", "UserName", registrantinfo.RegistrantInfoId);
            return(View(registrantinfo));
        }
Ejemplo n.º 5
0
        //
        // GET: /RegistrantInfo/Delete/5

        public ActionResult Delete(bool?saveChangesError, string errorMessage, int id = 0)
        {
            if (saveChangesError.GetValueOrDefault())
            {
                string msg = errorMessage + "<br/>"
                             + "Unable to save changes. Try again, and if the problem persists see your system administrator.";
                ViewBag.ErrorMessage = MvcHtmlString.Create(msg);
            }
            RegistrantInfo registrantinfo = _context.RegistrantInfos.Find(id);

            if (registrantinfo == null)
            {
                return(HttpNotFound());
            }
            return(View(registrantinfo));
        }
Ejemplo n.º 6
0
 //[ValidateAntiForgeryToken]
 public ActionResult DeleteConfirmed(int id)
 {
     try
     {
         RegistrantInfo registrantinfo = _context.RegistrantInfos.Find(id);
         _context.RegistrantInfos.Remove(registrantinfo);
         _context.SaveChanges();
     }
     catch (Exception ex)
     {
         //Log the error (add a variable name after DataException)
         return(RedirectToAction("Delete",
                                 new System.Web.Routing.RouteValueDictionary
         {
             { "id", id },
             { "saveChangesError", true },
             { "errorMessage", ex.Message }
         }));
     }
     return(RedirectToAction("Index"));
 }
Ejemplo n.º 7
0
        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" );
                }
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Adds (or removes) registrants to or from the registration. Only newly added registrants can
        /// can be removed. Any existing (saved) registrants cannot be removed from the registration
        /// </summary>
        /// <param name="registrantCount">The number of registrants that registration should have.</param>
        private void SetRegistrantState( int registrantCount )
        {
            if ( RegistrationState != null )
            {
                decimal cost = RegistrationTemplate.Cost;
                if ( ( RegistrationTemplate.SetCostOnInstance ?? false ) && RegistrationInstanceState != null )
                {
                    cost = RegistrationInstanceState.Cost ?? 0.0m;
                }

                // If this is the first registrant being added, default it to the current person
                if ( RegistrationState.RegistrantCount == 0 && registrantCount == 1 && CurrentPerson != null )
                {
                    var registrant = new RegistrantInfo( RegistrationInstanceState, CurrentPerson );
                    registrant.Cost = cost;
                    registrant.FamilyGuid = RegistrationState.FamilyGuid;
                    RegistrationState.Registrants.Add( registrant );
                }

                // While the number of registrants belonging to registration is less than the selected count, addd another registrant
                while ( RegistrationState.RegistrantCount < registrantCount )
                {
                    var registrant = new RegistrantInfo { Cost = cost };
                    if ( RegistrationTemplate.RegistrantsSameFamily == RegistrantsSameFamily.No )
                    {
                        registrant.FamilyGuid = Guid.NewGuid();
                    }
                    else if ( RegistrationTemplate.RegistrantsSameFamily == RegistrantsSameFamily.Yes )
                    {
                        registrant.FamilyGuid = RegistrationState.FamilyGuid;
                    }

                    RegistrationState.Registrants.Add( registrant );
                }

                // Get the number of registrants that needs to be removed.
                int removeCount = RegistrationState.RegistrantCount - registrantCount;
                if ( removeCount > 0 )
                {
                    // If removing any, reverse the order of registrants, so that most recently added will be removed first
                    RegistrationState.Registrants.Reverse();

                    // Try to get the registrants to remove. Most recently added will be taken first
                    foreach ( var registrant in RegistrationState.Registrants.Take( removeCount ).ToList() )
                    {
                        RegistrationState.Registrants.Remove( registrant );
                    }

                    // Reset the order after removing any registrants
                    RegistrationState.Registrants.Reverse();
                }
            }
        }
Ejemplo n.º 9
0
        private Control BuildRegistrantFieldControl( RegistrationTemplateFormField field, RegistrantInfo registrant, bool setValues )
        {
            // Ignore the first/last name fields since they are displayed in the panel's heading
            if ( field.FieldSource == RegistrationFieldSource.PersonField &&
                ( field.PersonFieldType == RegistrationPersonFieldType.FirstName || field.PersonFieldType == RegistrationPersonFieldType.LastName ) )
            {
                return null;
            }

            object fieldValue = null;
            if ( registrant != null && registrant.FieldValues != null && registrant.FieldValues.ContainsKey( field.Id ) )
            {
                fieldValue = registrant.FieldValues[field.Id];
            }

            var rlField = new RockLiteral();
            rlField.ID = string.Format( "rlField_{0}_{1}", registrant.Id, field.Id );

            if ( fieldValue != null )
            {
                if ( field.FieldSource == RegistrationFieldSource.PersonField )
                {
                    rlField.Label = field.PersonFieldType.ConvertToString( true );

                    switch ( field.PersonFieldType )
                    {
                        case RegistrationPersonFieldType.Campus:
                            {
                                var campus = CampusCache.Read( fieldValue.ToString().AsInteger() );
                                rlField.Text = campus != null ? campus.Name : string.Empty;
                                break;
                            }

                        case RegistrationPersonFieldType.Address:
                            {
                                var location = fieldValue.ToString().FromJsonOrNull<Location>();
                                rlField.Text = location != null ? location.ToString() : string.Empty;
                                break;
                            }

                        case RegistrationPersonFieldType.Email:
                            {
                                rlField.Text = fieldValue.ToString();
                                break;
                            }

                        case RegistrationPersonFieldType.Birthdate:
                            {
                                var birthDate = fieldValue as DateTime?;
                                rlField.Text = birthDate != null ? birthDate.Value.ToShortDateString() : string.Empty;
                                break;
                            }

                        case RegistrationPersonFieldType.Gender:
                            {
                                var gender = fieldValue.ToString().ConvertToEnumOrNull<Gender>() ?? Gender.Unknown;
                                rlField.Text = gender.ConvertToString();
                                break;
                            }

                        case RegistrationPersonFieldType.MaritalStatus:
                            {
                                var maritalStatusDv = DefinedValueCache.Read( fieldValue.ToString().AsInteger() );
                                rlField.Text = maritalStatusDv != null ? maritalStatusDv.Value : string.Empty;
                                break;
                            }

                        case RegistrationPersonFieldType.MobilePhone:
                        case RegistrationPersonFieldType.HomePhone:
                        case RegistrationPersonFieldType.WorkPhone:
                            {
                                var pn = fieldValue as PhoneNumber;
                                rlField.Text = pn != null ? pn.NumberFormatted : string.Empty;
                                break;
                            }
                    }

                }
                else
                {
                    if ( field.AttributeId.HasValue )
                    {
                        var attribute = AttributeCache.Read( field.AttributeId.Value );
                        if ( attribute == null )
                        {
                            return null;
                        }

                        rlField.Label = attribute.Name;
                        rlField.Text = attribute.FieldType.Field.FormatValueAsHtml( null, fieldValue.ToString(), attribute.QualifierValues );
                    }
                }
            }

            return rlField;
        }
Ejemplo n.º 10
0
        private Control BuildRegistrantFeeControl( RegistrationTemplateFee fee, FeeInfo feeInfo, RegistrantInfo registrant, bool setValues )
        {
            if ( feeInfo.Quantity > 0 )
            {
                var rlField = new RockLiteral();
                rlField.ID = string.Format( "rlFee_{0}_{1}_{2}", registrant.Id, fee.Id, feeInfo.Option );
                rlField.Label = fee.Name;

                if ( !string.IsNullOrWhiteSpace( feeInfo.Option ) )
                {
                    rlField.Label += " - " + feeInfo.Option;
                }

                if ( feeInfo.Quantity > 1 )
                {
                    rlField.Text = string.Format( "({0:N0} @ {1:C2}) {2:C2}",
                    feeInfo.Quantity, feeInfo.Cost, feeInfo.TotalCost );
                }
                else
                {
                    rlField.Text = feeInfo.TotalCost.ToString( "C2" );
                }

                return rlField;
            }

            return null;
        }
Ejemplo n.º 11
0
        private void BuildRegistrantControls( RegistrantInfo registrant, bool setValues )
        {
            var anchor = new HtmlAnchor();
            anchor.Name = registrant.Id.ToString();
            phDynamicControls.Controls.Add( anchor );

            var divPanel = new HtmlGenericControl( "div" );
            divPanel.AddCssClass( "panel" );
            divPanel.AddCssClass( "panel-block" );
            phDynamicControls.Controls.Add( divPanel );

            var divHeading = new HtmlGenericControl( "div" );
            divHeading.AddCssClass( "panel-heading" );
            divHeading.AddCssClass( "clearfix" );
            divPanel.Controls.Add( divHeading );

            var h1Heading = new HtmlGenericControl( "h1" );
            h1Heading.AddCssClass( "panel-title" );
            h1Heading.AddCssClass( "pull-left" );
            h1Heading.InnerText = registrant.PersonName;
            divHeading.Controls.Add( h1Heading );

            var divLabels = new HtmlGenericControl( "div" );
            divLabels.AddCssClass( "panel-labels" );
            divHeading.Controls.Add( divLabels );

            decimal registrantCost = registrant.TotalCost;
            if ( registrantCost != 0.0m )
            {
                var hlCost = new HighlightLabel();
                hlCost.ID = string.Format( "hlCost_{0}", registrant.Id );
                hlCost.LabelType = LabelType.Info;
                hlCost.ToolTip = "Cost";
                hlCost.Text = registrantCost.ToString( "C2" );
                divLabels.Controls.Add( hlCost );
            }

            var divBody = new HtmlGenericControl( "div" );
            divBody.AddCssClass( "panel-body" );
            divPanel.Controls.Add( divBody );

            var divRow = new HtmlGenericControl( "div" );
            divRow.AddCssClass( "row" );
            divBody.Controls.Add( divRow );

            var divFields = new HtmlGenericControl( "div" );
            divFields.AddCssClass( "col-md-6");
            divRow.Controls.Add( divFields );

            var divFees = new HtmlGenericControl( "div" );
            divFees.AddCssClass( "col-md-6");
            divRow.Controls.Add( divFees );

            foreach( var form in RegistrationTemplateState.Forms )
            {
                foreach( var field in form.Fields )
                {
                    var fieldControl = BuildRegistrantFieldControl( field, registrant, setValues );
                    if ( fieldControl != null )
                    {
                        divFields.Controls.Add( fieldControl );
                    }
                }
            }

            if ( registrant.Cost > 0.0m)
            {
                var rlCost = new RockLiteral();
                rlCost.ID = string.Format( "rlCost_{0}", registrant.Id );
                rlCost.Label = "Cost";
                rlCost.Text = registrant.Cost.ToString( "C2" );
                divFees.Controls.Add( rlCost );
            }

            foreach ( var fee in registrant.FeeValues )
            {
                var templateFee = RegistrationTemplateState.Fees.Where( f => f.Id == fee.Key ).FirstOrDefault();
                if ( templateFee != null && fee.Value != null )
                {
                    foreach ( var feeInfo in fee.Value )
                    {
                        var feeControl = BuildRegistrantFeeControl( templateFee, feeInfo, registrant, setValues );
                        if ( feeControl != null )
                        {
                            divFees.Controls.Add( feeControl );
                        }
                    }
                }
            }

            var divActions = new HtmlGenericControl( "Div" );
            divActions.AddCssClass( "actions" );
            divBody.Controls.Add( divActions );

            var lbEditRegistrant = new LinkButton();
            lbEditRegistrant.Visible = EditAllowed;
            lbEditRegistrant.CausesValidation = false;
            lbEditRegistrant.ID = string.Format( "lbEditRegistrant_{0}", registrant.Id );
            lbEditRegistrant.Text = "Edit";
            lbEditRegistrant.CssClass = "btn btn-primary";
            lbEditRegistrant.Click += lbEditRegistrant_Click;
            divActions.Controls.Add( lbEditRegistrant );

            var lbDeleteRegistrant = new LinkButton();
            lbDeleteRegistrant.Visible = EditAllowed;
            lbDeleteRegistrant.CausesValidation = false;
            lbDeleteRegistrant.ID = string.Format( "lbDeleteRegistrant_{0}", registrant.Id );
            lbDeleteRegistrant.Text = "Delete";
            lbDeleteRegistrant.CssClass = "btn btn-link";
            lbDeleteRegistrant.Attributes["onclick"] = "javascript: return Rock.dialogs.confirmDelete(event, 'Registrant');";
            lbDeleteRegistrant.Click += lbDeleteRegistrant_Click;
            divActions.Controls.Add( lbDeleteRegistrant );
        }
Ejemplo n.º 12
0
        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");
                }
            }
        }
Ejemplo n.º 13
0
        private void BuildRegistrantControls( RegistrantInfo registrant, bool setValues )
        {
            var anchor = new HtmlAnchor();
            anchor.Name = registrant.Id.ToString();
            phDynamicControls.Controls.Add( anchor );

            var divPanel = new HtmlGenericControl( "div" );
            divPanel.AddCssClass( "panel" );
            divPanel.AddCssClass( "panel-block" );
            phDynamicControls.Controls.Add( divPanel );

            var divHeading = new HtmlGenericControl( "div" );
            divHeading.AddCssClass( "panel-heading" );
            divHeading.AddCssClass( "clearfix" );
            divPanel.Controls.Add( divHeading );

            var h1Heading = new HtmlGenericControl( "h1" );
            h1Heading.AddCssClass( "panel-title" );
            h1Heading.AddCssClass( "pull-left" );
            h1Heading.InnerHtml = "<i class='fa fa-user'></i> " + registrant.PersonName;
            divHeading.Controls.Add( h1Heading );

            var divLabels = new HtmlGenericControl( "div" );
            divLabels.AddCssClass( "panel-labels" );
            divHeading.Controls.Add( divLabels );

            decimal registrantCost = registrant.TotalCost;
            if ( registrantCost != 0.0m )
            {
                var hlCost = new HighlightLabel();
                hlCost.ID = string.Format( "hlCost_{0}", registrant.Id );
                hlCost.LabelType = LabelType.Info;
                hlCost.ToolTip = "Cost";
                hlCost.Text = registrantCost.FormatAsCurrency();
                divLabels.Controls.Add( hlCost );
            }

            if ( registrant.PersonId.HasValue )
            {
                var aProfileLink = new HtmlAnchor();
                aProfileLink.HRef = ResolveRockUrl( string.Format( "~/Person/{0}", registrant.PersonId.Value ) );
                divLabels.Controls.Add( aProfileLink );
                aProfileLink.AddCssClass( "btn btn-default btn-xs margin-l-sm" );
                var iProfileLink = new HtmlGenericControl( "i" );
                iProfileLink.AddCssClass( "fa fa-user" );
                aProfileLink.Controls.Add( iProfileLink );
            }

            var divBody = new HtmlGenericControl( "div" );
            divBody.AddCssClass( "panel-body" );
            divPanel.Controls.Add( divBody );

            var divRow = new HtmlGenericControl( "div" );
            divRow.AddCssClass( "row" );
            divBody.Controls.Add( divRow );

            var divFields = new HtmlGenericControl( "div" );
            divFields.AddCssClass( "col-md-6");
            divRow.Controls.Add( divFields );

            var divFees = new HtmlGenericControl( "div" );
            divFees.AddCssClass( "col-md-6");
            divRow.Controls.Add( divFees );

            if ( RegistrationTemplateState != null &&
                RegistrationTemplateState.GroupTypeId.HasValue &&
                Registration != null &&
                Registration.Group != null &&
                Registration.Group.GroupTypeId == RegistrationTemplateState.GroupTypeId.Value )
            {
                if ( Registration != null && Registration.Group != null )
                {
                    var rcwGroupMember = new RockControlWrapper();
                    rcwGroupMember.ID = string.Format( "rcwGroupMember_{0}", registrant.Id );
                    divFields.Controls.Add( rcwGroupMember );
                    rcwGroupMember.Label = "Group";

                    var pGroupMember = new HtmlGenericControl( "p" );
                    pGroupMember.ID = string.Format( "pGroupMember_{0}", registrant.Id );
                    divRow.AddCssClass( "form-control-static" );
                    rcwGroupMember.Controls.Add( pGroupMember );

                    if ( registrant.GroupMemberId.HasValue )
                    {
                        var qryParams = new Dictionary<string, string>();
                        qryParams.Add( "GroupMemberId", registrant.GroupMemberId.Value.ToString() );

                        var aProfileLink = new HtmlAnchor();
                        aProfileLink.HRef = LinkedPageUrl( "GroupMemberPage", qryParams );
                        pGroupMember.Controls.Add( aProfileLink );
                        aProfileLink.Controls.Add( new LiteralControl( string.IsNullOrWhiteSpace( registrant.GroupName ) ? "Group" : registrant.GroupName ) );
                    }
                    else
                    {
                        pGroupMember.Controls.Add( new LiteralControl( "None (" ) );

                        var lbGroupMember = new LinkButton();
                        lbGroupMember.CausesValidation = false;
                        lbGroupMember.ID = string.Format( "lbGroupMember_{0}", registrant.Id );
                        lbGroupMember.Text = string.Format( "Add {0} to Target Group", registrant.GetFirstName( RegistrationTemplateState ) );
                        lbGroupMember.Click += lbGroupMember_Click;
                        pGroupMember.Controls.Add( lbGroupMember );

                        pGroupMember.Controls.Add( new LiteralControl( ")" ) );
                    }
                }
            }

            foreach( var form in RegistrationTemplateState.Forms.OrderBy( f => f.Order ) )
            {
                foreach( var field in form.Fields.OrderBy( f => f.Order ) )
                {
                    var fieldControl = BuildRegistrantFieldControl( field, registrant, setValues );
                    if ( fieldControl != null )
                    {
                        divFields.Controls.Add( fieldControl );
                    }
                }
            }

            if ( registrant.Cost > 0.0m)
            {
                var rlCost = new RockLiteral();
                rlCost.ID = string.Format( "rlCost_{0}", registrant.Id );
                rlCost.Label = "Cost";
                rlCost.Text = registrant.Cost.FormatAsCurrency();
                divFees.Controls.Add( rlCost );
            }

            foreach ( var fee in registrant.FeeValues )
            {
                var templateFee = RegistrationTemplateState.Fees.Where( f => f.Id == fee.Key ).FirstOrDefault();
                if ( templateFee != null && fee.Value != null )
                {
                    foreach ( var feeInfo in fee.Value )
                    {
                        var feeControl = BuildRegistrantFeeControl( templateFee, feeInfo, registrant, setValues );
                        if ( feeControl != null )
                        {
                            divFees.Controls.Add( feeControl );
                        }
                    }
                }
            }

            var divActions = new HtmlGenericControl( "Div" );
            divActions.AddCssClass( "actions" );
            divBody.Controls.Add( divActions );

            var lbEditRegistrant = new LinkButton();
            lbEditRegistrant.Visible = EditAllowed;
            lbEditRegistrant.CausesValidation = false;
            lbEditRegistrant.ID = string.Format( "lbEditRegistrant_{0}", registrant.Id );
            lbEditRegistrant.Text = "Edit";
            lbEditRegistrant.CssClass = "btn btn-primary";
            lbEditRegistrant.Click += lbEditRegistrant_Click;
            divActions.Controls.Add( lbEditRegistrant );

            var lbDeleteRegistrant = new LinkButton();
            lbDeleteRegistrant.Visible = EditAllowed;
            lbDeleteRegistrant.CausesValidation = false;
            lbDeleteRegistrant.ID = string.Format( "lbDeleteRegistrant_{0}", registrant.Id );
            lbDeleteRegistrant.Text = "Delete";
            lbDeleteRegistrant.CssClass = "btn btn-link";
            lbDeleteRegistrant.Attributes["onclick"] = "javascript: return Rock.dialogs.confirmDelete(event, 'Registrant');";
            lbDeleteRegistrant.Click += lbDeleteRegistrant_Click;
            divActions.Controls.Add( lbDeleteRegistrant );
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Adds (or removes) registrants to or from the registration. Only newly added registrants can
        /// can be removed. Any existing (saved) registrants cannot be removed from the registration
        /// </summary>
        /// <param name="registrantCount">The number of registrants that registration should have.</param>
        private void SetRegistrantState( int registrantCount )
        {
            if ( RegistrationState != null )
            {
                decimal cost = RegistrationTemplate.Cost;
                if ( ( RegistrationTemplate.SetCostOnInstance ?? false ) && RegistrationInstanceState != null )
                {
                    cost = RegistrationInstanceState.Cost ?? 0.0m;
                }

                // If this is the first registrant being added, default it to the current person
                if ( RegistrationState.RegistrantCount == 0 && registrantCount == 1 && CurrentPerson != null )
                {
                    var registrant = new RegistrantInfo( RegistrationInstanceState, CurrentPerson );
                    if ( RegistrationTemplate.ShowCurrentFamilyMembers )
                    {
                        // If currentfamily members can be selected, the firstname and lastname fields will be
                        // disabled so values need to be set (in case those fields did not have the 'showCurrentValue'
                        // option selected
                        foreach( var field in RegistrationTemplate.Forms
                            .SelectMany( f => f.Fields )
                            .Where( f =>
                                f.PersonFieldType == RegistrationPersonFieldType.FirstName ||
                                f.PersonFieldType == RegistrationPersonFieldType.LastName ) )
                        {
                            registrant.FieldValues.AddOrReplace( field.Id,
                                new FieldValueObject( field, field.PersonFieldType == RegistrationPersonFieldType.FirstName ? CurrentPerson.NickName : CurrentPerson.LastName ) );
                        }
                    }
                    registrant.Cost = cost;
                    registrant.FamilyGuid = RegistrationState.FamilyGuid;
                    if ( RegistrationState.Registrants.Count >= RegistrationState.SlotsAvailable )
                    {
                        registrant.OnWaitList = true;
                    }

                    RegistrationState.Registrants.Add( registrant );
                }

                // While the number of registrants belonging to registration is less than the selected count, addd another registrant
                while ( RegistrationState.RegistrantCount < registrantCount )
                {
                    var registrant = new RegistrantInfo { Cost = cost };
                    if ( RegistrationTemplate.RegistrantsSameFamily == RegistrantsSameFamily.No )
                    {
                        registrant.FamilyGuid = Guid.NewGuid();
                    }
                    else if ( RegistrationTemplate.RegistrantsSameFamily == RegistrantsSameFamily.Yes )
                    {
                        registrant.FamilyGuid = RegistrationState.FamilyGuid;
                    }

                    if ( RegistrationState.Registrants.Count >= RegistrationState.SlotsAvailable )
                    {
                        registrant.OnWaitList = true;
                    }
                    RegistrationState.Registrants.Add( registrant );
                }

                // Get the number of registrants that needs to be removed.
                int removeCount = RegistrationState.RegistrantCount - registrantCount;
                if ( removeCount > 0 )
                {
                    // If removing any, reverse the order of registrants, so that most recently added will be removed first
                    RegistrationState.Registrants.Reverse();

                    // Try to get the registrants to remove. Most recently added will be taken first
                    foreach ( var registrant in RegistrationState.Registrants.Take( removeCount ).ToList() )
                    {
                        RegistrationState.Registrants.Remove( registrant );
                    }

                    // Reset the order after removing any registrants
                    RegistrationState.Registrants.Reverse();
                }
            }
        }
Ejemplo n.º 15
0
        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;
                }
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Creates the RegistrantState and TemplateState obj and loads the UI with values.
        /// </summary>
        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().AsNoTracking()
                                 .Include(a => a.Registration.RegistrationInstance.RegistrationTemplate.Forms)
                                 .Include(a => a.Registration.RegistrationInstance.RegistrationTemplate.Fees)
                                 .Include(a => a.PersonAlias.Person)
                                 .Include(a => a.Fees)
                                 .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);
                        this.RegistrationTemplateId = registrant.Registration.RegistrationInstance.RegistrationTemplateId;
                        this.RegistrationInstanceId = registrant.Registration.RegistrationInstanceId;

                        lTitle.Text = registrant.ToString();

                        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 (this.RegistrationTemplate == null && registrationId.HasValue && registrationId.Value != 0)
                {
                    var registration = new RegistrationService(rockContext)
                                       .Queryable().AsNoTracking()
                                       .Include(a => a.RegistrationInstance.RegistrationTemplate)
                                       .Include(a => a.RegistrationInstance.RegistrationTemplate.Forms)
                                       .Include(a => a.RegistrationInstance.RegistrationTemplate.Fees)
                                       .Include(a => a.PersonAlias.Person)
                                       .Where(r => r.Id == registrationId.Value)
                                       .FirstOrDefault();

                    if (registration != null &&
                        registration.RegistrationInstance != null &&
                        registration.RegistrationInstance.RegistrationTemplate != null)
                    {
                        this.RegistrationTemplateId = registration.RegistrationInstance.RegistrationTemplateId;
                        this.RegistrationInstanceId = registration.RegistrationInstanceId;

                        lTitle.Text = "Add Registrant";

                        lWizardTemplateName.Text     = registration.RegistrationInstance.RegistrationTemplate.Name;
                        lWizardInstanceName.Text     = registration.RegistrationInstance.Name;
                        lWizardRegistrationName.Text = registration.ToString();
                        lWizardRegistrantName.Text   = "New Registrant";
                    }
                }

                if (this.RegistrationTemplate != null)
                {
                    tglWaitList.Visible = this.RegistrationTemplate.WaitListEnabled;
                }

                if (this.RegistrationTemplate != null && RegistrantState == null)
                {
                    RegistrantState = new RegistrantInfo();
                    RegistrantState.RegistrationId = registrationId ?? 0;
                    if (this.RegistrationTemplate.SetCostOnInstance.HasValue && this.RegistrationTemplate.SetCostOnInstance.Value)
                    {
                        var instance = new RegistrationInstanceService(rockContext).Get(RegistrationInstanceId);
                        if (instance != null)
                        {
                            RegistrantState.Cost = instance.Cost ?? 0.0m;
                        }
                    }
                    else
                    {
                        RegistrantState.Cost = this.RegistrationTemplate.Cost;
                    }
                }

                if (registrant != null && registrant.PersonAlias != null && registrant.PersonAlias.Person != null)
                {
                    ppPerson.SetValue(registrant.PersonAlias.Person);
                }
                else
                {
                    ppPerson.SetValue(null);
                }

                if (this.RegistrationTemplate != null && this.RegistrationTemplate.RequiredSignatureDocumentTemplate != null)
                {
                    fuSignedDocument.Label = this.RegistrationTemplate.RequiredSignatureDocumentTemplate.Name;
                    if (this.RegistrationTemplate.RequiredSignatureDocumentTemplate.BinaryFileType != null)
                    {
                        fuSignedDocument.BinaryFileTypeGuid = this.RegistrationTemplate.RequiredSignatureDocumentTemplate.BinaryFileType.Guid;
                    }

                    if (ppPerson.PersonId.HasValue)
                    {
                        var signatureDocument = new SignatureDocumentService(rockContext)
                                                .Queryable().AsNoTracking()
                                                .Where(d =>
                                                       d.SignatureDocumentTemplateId == this.RegistrationTemplate.RequiredSignatureDocumentTemplateId.Value &&
                                                       d.AppliesToPersonAlias != null &&
                                                       d.AppliesToPersonAlias.PersonId == ppPerson.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;
                }

                if (RegistrantState != null)
                {
                    cbCost.Text = RegistrantState.Cost.ToString("N2");
                    cbDiscountApplies.Checked = RegistrantState.DiscountApplies;
                }
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Adds (or removes) registrants to or from the registration. Only newly added registrants can
        /// can be removed. Any existing (saved) registrants cannot be removed from the registration
        /// </summary>
        /// <param name="registrantCount">The number of registrants that registration should have.</param>
        private void SetRegistrantState( int registrantCount )
        {
            if ( RegistrationState != null )
            {
                var firstFamilyGuid = RegistrationState.RegistrantCount > 0 ? RegistrationState.Registrants[0].FamilyGuid : Guid.NewGuid();

                // While the number of registrants belonging to registration is less than the selected count, addd another registrant
                while ( RegistrationState.RegistrantCount < registrantCount )
                {
                    var registrant = new RegistrantInfo { Cost = RegistrationTemplate.Cost };
                    if ( RegistrationTemplate.RegistrantsSameFamily == RegistrantsSameFamily.No )
                    {
                        registrant.FamilyGuid = Guid.NewGuid();
                    }
                    else if ( RegistrationTemplate.RegistrantsSameFamily == RegistrantsSameFamily.Yes )
                    {
                        registrant.FamilyGuid = firstFamilyGuid;
                    }

                    RegistrationState.Registrants.Add( registrant );
                }

                // Get the number of registrants that needs to be removed.
                int removeCount = RegistrationState.RegistrantCount - registrantCount;
                if ( removeCount > 0 )
                {
                    // If removing any, reverse the order of registrants, so that most recently added will be removed first
                    RegistrationState.Registrants.Reverse();

                    // Try to get the registrants to remove. Most recently added will be taken first
                    foreach ( var registrant in RegistrationState.Registrants.Take( removeCount ).ToList() )
                    {
                        RegistrationState.Registrants.Remove( registrant );
                    }

                    // Reset the order after removing any registrants
                    RegistrationState.Registrants.Reverse();
                }
            }
        }
Ejemplo n.º 18
0
        private void BuildRegistrantControls( RegistrantInfo registrant, bool setValues )
        {
            var anchor = new HtmlAnchor();
            anchor.Name = registrant.Id.ToString();
            phDynamicControls.Controls.Add( anchor );

            var divPanel = new HtmlGenericControl( "div" );
            divPanel.AddCssClass( "panel" );
            divPanel.AddCssClass( "panel-block" );
            phDynamicControls.Controls.Add( divPanel );

            var divHeading = new HtmlGenericControl( "div" );
            divHeading.AddCssClass( "panel-heading" );
            divHeading.AddCssClass( "clearfix" );
            divPanel.Controls.Add( divHeading );

            var h1Heading = new HtmlGenericControl( "h1" );
            h1Heading.AddCssClass( "panel-title" );
            h1Heading.AddCssClass( "pull-left" );
            h1Heading.InnerHtml = "<i class='fa fa-user'></i> " + registrant.PersonName;
            divHeading.Controls.Add( h1Heading );

            var divLabels = new HtmlGenericControl( "div" );
            divLabels.AddCssClass( "panel-labels" );
            divHeading.Controls.Add( divLabels );

            if ( registrant.OnWaitList )
            {
                var hlOnWaitList = new HighlightLabel();
                hlOnWaitList.ID = string.Format( "hlWaitList_{0}", registrant.Id );
                hlOnWaitList.LabelType = LabelType.Warning;
                hlOnWaitList.Text = "Wait List";
                hlOnWaitList.CssClass = "margin-r-sm";
                divLabels.Controls.Add( hlOnWaitList );
            }

            decimal discountedTotalCost = registrant.DiscountedTotalCost( Registration.DiscountPercentage, Registration.DiscountAmount );
            if ( discountedTotalCost != 0.0m )
            {
                var hlCost = new HighlightLabel();
                hlCost.ID = string.Format( "hlCost_{0}", registrant.Id );
                hlCost.LabelType = LabelType.Info;
                hlCost.ToolTip = "Cost";
                hlCost.Text = discountedTotalCost.FormatAsCurrency();
                divLabels.Controls.Add( hlCost );
            }

            if ( registrant.PersonId.HasValue )
            {
                var aProfileLink = new HtmlAnchor();
                aProfileLink.HRef = ResolveRockUrl( string.Format( "~/Person/{0}", registrant.PersonId.Value ) );
                divLabels.Controls.Add( aProfileLink );
                aProfileLink.AddCssClass( "btn btn-default btn-xs margin-l-sm" );
                var iProfileLink = new HtmlGenericControl( "i" );
                iProfileLink.AddCssClass( "fa fa-user" );
                aProfileLink.Controls.Add( iProfileLink );
            }

            var divBody = new HtmlGenericControl( "div" );
            divBody.AddCssClass( "panel-body" );
            divPanel.Controls.Add( divBody );

            SignatureDocumentTemplate documentTemplate = null;

            if ( Registration != null &&
                Registration.RegistrationInstance != null &&
                Registration.RegistrationInstance.RegistrationTemplate != null &&
                Registration.RegistrationInstance.RegistrationTemplate.RequiredSignatureDocumentTemplate != null )
            {
                documentTemplate = Registration.RegistrationInstance.RegistrationTemplate.RequiredSignatureDocumentTemplate;
            }

            if ( documentTemplate != null && !registrant.SignatureDocumentId.HasValue )
            {
                var template = Registration.RegistrationInstance.RegistrationTemplate;
                var divSigAlert = new HtmlGenericControl( "div" );
                divSigAlert.AddCssClass( "alert alert-warning" );
                divBody.Controls.Add( divSigAlert );

                StringBuilder sb = new StringBuilder();
                sb.Append( "<div class='row'><div class='col-md-9'>" );

                sb.AppendFormat(
                    "There is not a signed {0} for {1}",
                    template.RequiredSignatureDocumentTemplate.Name,
                    registrant.GetFirstName( template ) );

                if ( registrant.SignatureDocumentLastSent.HasValue )
                {
                    sb.AppendFormat(
                        " (a request was sent {0})",
                        registrant.SignatureDocumentLastSent.Value.ToElapsedString() );
                }
                sb.Append( ".</div>" );

                divSigAlert.Controls.Add( new LiteralControl( sb.ToString() ) );

                var divSigAction = new HtmlGenericControl( "div" );
                divSigAction.AddCssClass( "col-md-3 text-right" );
                divSigAlert.Controls.Add( divSigAction );

                var lbResendDocumentRequest = new LinkButton();
                lbResendDocumentRequest.CausesValidation = false;
                lbResendDocumentRequest.ID = string.Format( "lbResendDocumentRequest_{0}", registrant.Id );
                lbResendDocumentRequest.Text = registrant.SignatureDocumentLastSent.HasValue ? "Resend Signature Request" : "Send Signature Request";
                lbResendDocumentRequest.CssClass = "btn btn-warning btn-sm";
                lbResendDocumentRequest.Click += lbResendDocumentRequest_Click;
                divSigAction.Controls.Add( lbResendDocumentRequest );

                divSigAlert.Controls.Add( new LiteralControl( "</div>" ) );
            }

            var divRow = new HtmlGenericControl( "div" );
            divRow.AddCssClass( "row" );
            divBody.Controls.Add( divRow );

            var divLeftColumn = new HtmlGenericControl( "div" );
            divLeftColumn.AddCssClass( "col-md-6");
            divRow.Controls.Add( divLeftColumn );

            var divRightColumn = new HtmlGenericControl( "div" );
            divRightColumn.AddCssClass( "col-md-6");
            divRow.Controls.Add( divRightColumn );

            if ( RegistrationTemplateState != null &&
                RegistrationTemplateState.GroupTypeId.HasValue &&
                Registration != null &&
                Registration.Group != null &&
                Registration.Group.GroupTypeId == RegistrationTemplateState.GroupTypeId.Value )
            {
                if ( Registration != null && Registration.Group != null )
                {
                    var rcwGroupMember = new RockControlWrapper();
                    rcwGroupMember.ID = string.Format( "rcwGroupMember_{0}", registrant.Id );
                    divLeftColumn.Controls.Add( rcwGroupMember );
                    rcwGroupMember.Label = "Group";

                    var pGroupMember = new HtmlGenericControl( "p" );
                    pGroupMember.ID = string.Format( "pGroupMember_{0}", registrant.Id );
                    divRow.AddCssClass( "form-control-static" );
                    rcwGroupMember.Controls.Add( pGroupMember );

                    if ( registrant.GroupMemberId.HasValue )
                    {
                        var qryParams = new Dictionary<string, string>();
                        qryParams.Add( "GroupMemberId", registrant.GroupMemberId.Value.ToString() );

                        var aProfileLink = new HtmlAnchor();
                        aProfileLink.HRef = LinkedPageUrl( "GroupMemberPage", qryParams );
                        pGroupMember.Controls.Add( aProfileLink );
                        aProfileLink.Controls.Add( new LiteralControl( string.IsNullOrWhiteSpace( registrant.GroupName ) ? "Group" : registrant.GroupName ) );
                    }
                    else
                    {
                        pGroupMember.Controls.Add( new LiteralControl( "None (" ) );

                        var lbGroupMember = new LinkButton();
                        lbGroupMember.CausesValidation = false;
                        lbGroupMember.ID = string.Format( "lbGroupMember_{0}", registrant.Id );
                        lbGroupMember.Text = string.Format( "Add {0} to Target Group", registrant.GetFirstName( RegistrationTemplateState ) );
                        lbGroupMember.Click += lbGroupMember_Click;
                        pGroupMember.Controls.Add( lbGroupMember );

                        pGroupMember.Controls.Add( new LiteralControl( ")" ) );
                    }
                }
            }

            foreach( var form in RegistrationTemplateState.Forms.OrderBy( f => f.Order ) )
            {
                foreach( var field in form.Fields.OrderBy( f => f.Order ) )
                {
                    var fieldControl = BuildRegistrantFieldControl( field, registrant, setValues );
                    if ( fieldControl != null )
                    {
                        divLeftColumn.Controls.Add( fieldControl );
                    }
                }
            }

            if ( registrant.Cost > 0.0m)
            {
                var rlCost = new RockLiteral();
                rlCost.ID = string.Format( "rlCost_{0}", registrant.Id );
                rlCost.Label = "Cost";
                rlCost.Text = registrant.Cost.FormatAsCurrency();

                decimal discountedCost = registrant.DiscountedCost( Registration.DiscountPercentage, Registration.DiscountAmount );
                if ( registrant.Cost == discountedCost )
                {
                    var divCost = new HtmlGenericControl( "div" );
                    divCost.AddCssClass( "col-xs-12" );
                    divCost.Controls.Add( rlCost );
                    divRightColumn.Controls.Add( divCost );
                }
                else
                {
                    var rlDiscountedCost = new RockLiteral();
                    rlDiscountedCost.ID = string.Format( "rlDiscountedCost_{0}", registrant.Id );
                    rlDiscountedCost.Label = "Discounted Cost";
                    rlDiscountedCost.Text = discountedCost.FormatAsCurrency();

                    var divCost = new HtmlGenericControl( "div" );
                    divCost.AddCssClass( "col-xs-6" );
                    divCost.Controls.Add( rlCost );
                    divRightColumn.Controls.Add( divCost );

                    var divDiscountedCost = new HtmlGenericControl( "div" );
                    divDiscountedCost.AddCssClass( "col-xs-6" );
                    divDiscountedCost.Controls.Add( rlDiscountedCost );
                    divRightColumn.Controls.Add( divDiscountedCost );
                }
            }

            foreach ( var fee in registrant.FeeValues )
            {
                var templateFee = RegistrationTemplateState.Fees.Where( f => f.Id == fee.Key ).FirstOrDefault();
                if ( templateFee != null && fee.Value != null )
                {
                    foreach ( var feeInfo in fee.Value )
                    {
                        var discountedCost = registrant.DiscountApplies ? feeInfo.DiscountedCost( Registration.DiscountPercentage ) : feeInfo.TotalCost;
                        var feeControl = BuildRegistrantFeeControl( templateFee, feeInfo, registrant, setValues );
                        if ( feeControl != null )
                        {
                            if ( feeInfo.TotalCost == discountedCost )
                            {
                                var divFee = new HtmlGenericControl( "div" );
                                divFee.AddCssClass( "col-xs-12" );
                                divFee.Controls.Add( feeControl );
                                divRightColumn.Controls.Add( divFee );
                            }
                            else
                            {
                                var rlDiscountedFee = new RockLiteral();
                                rlDiscountedFee.ID = string.Format( "rlDiscountedFee_{0}_{1}_{2}", registrant.Id, templateFee.Id, feeInfo.Option );
                                rlDiscountedFee.Label = "Discounted Amount";
                                rlDiscountedFee.Text = discountedCost.FormatAsCurrency();

                                var divFee = new HtmlGenericControl( "div" );
                                divFee.AddCssClass( "col-xs-6" );
                                divFee.Controls.Add( feeControl );
                                divRightColumn.Controls.Add( divFee );

                                var divDiscountedFee = new HtmlGenericControl( "div" );
                                divDiscountedFee.AddCssClass( "col-xs-6" );
                                divDiscountedFee.Controls.Add( rlDiscountedFee );
                                divRightColumn.Controls.Add( divDiscountedFee );
                            }
                        }
                    }
                }
            }

            if ( documentTemplate != null && registrant.SignatureDocumentId.HasValue )
            {
                var rlDocumentLink = new RockLiteral();
                rlDocumentLink.ID = string.Format( "rlDocumentLink_{0}", registrant.Id );
                rlDocumentLink.Label = documentTemplate.Name;
                rlDocumentLink.Text = string.Format( "<a href='{0}?id={1}' target='_blank'>View Document</a>",
                    ResolveRockUrl( "~/GetFile.ashx" ), registrant.SignatureDocumentId.Value );
                divRightColumn.Controls.Add( rlDocumentLink );
            }

            var divActions = new HtmlGenericControl( "Div" );
            divActions.AddCssClass( "actions" );
            divBody.Controls.Add( divActions );

            var lbEditRegistrant = new LinkButton();
            lbEditRegistrant.Visible = EditAllowed;
            lbEditRegistrant.CausesValidation = false;
            lbEditRegistrant.ID = string.Format( "lbEditRegistrant_{0}", registrant.Id );
            lbEditRegistrant.Text = "Edit";
            lbEditRegistrant.CssClass = "btn btn-primary";
            lbEditRegistrant.Click += lbEditRegistrant_Click;
            divActions.Controls.Add( lbEditRegistrant );

            var lbDeleteRegistrant = new LinkButton();
            lbDeleteRegistrant.Visible = EditAllowed;
            lbDeleteRegistrant.CausesValidation = false;
            lbDeleteRegistrant.ID = string.Format( "lbDeleteRegistrant_{0}", registrant.Id );
            lbDeleteRegistrant.Text = "Delete";
            lbDeleteRegistrant.CssClass = "btn btn-link";
            lbDeleteRegistrant.Attributes["onclick"] = "javascript: return Rock.dialogs.confirmDelete(event, 'Registrant');";
            lbDeleteRegistrant.Click += lbDeleteRegistrant_Click;
            divActions.Controls.Add( lbDeleteRegistrant );
        }