Esempio n. 1
0
        public void ClearAddNewCandidate(bool clearErrors = false)
        {
            if (clearErrors)
            {
                _AddNewCandidateSubTabInfo.ClearValidationErrors();
            }
            ControlAddNewCandidateFName.SetValue(Empty);
            ControlAddNewCandidateMName.SetValue(Empty);
            ControlAddNewCandidateNickname.SetValue(Empty);
            ControlAddNewCandidateLName.SetValue(Empty);
            ControlAddNewCandidateSuffix.SetValue(Empty);
            var stateCode = Mode == DataMode.AddPoliticians
        ? VotePage.GetPage <SecureAdminPage>().StateCode
        : Offices.GetValidatedStateCodeFromKey(SafeGetOfficeKey());

            ControlAddNewCandidateStateCode.SetValue(stateCode);
            ControlAddNewCandidateStateCode.Enabled = !StateCache.IsValidStateCode(stateCode);
        }
Esempio n. 2
0
        protected void ButtonAddNewCandidate_OnClick(object sender, EventArgs e)
        {
            bool validateDuplicates;

            bool.TryParse(AddCandidateValidateDuplicates.GetValue(),
                          out validateDuplicates);

            AddCandidateDuplicatesHtml.Controls.Clear();
            _AddNewCandidateSubTabInfo.ClearValidationErrors();
            AddCandidateNewId.SetValue(string.Empty);

            // No actual updating here, just validation and reformatting
            _AddNewCandidateSubTabInfo.Update(FeedbackAddNewCandidate, false);
            if (FeedbackAddNewCandidate.ValidationErrorCount > 0)
            {
                return;
            }

            var stateCode  = ControlAddNewCandidateStateCode.GetValue();
            var firstName  = ControlAddNewCandidateFName.GetValue();
            var middleName = ControlAddNewCandidateMName.GetValue();
            var nickname   = ControlAddNewCandidateNickname.GetValue();
            var lastName   = ControlAddNewCandidateLName.GetValue();
            var suffix     = ControlAddNewCandidateSuffix.GetValue();

            var formattedName = Politicians.FormatName(firstName, middleName, nickname,
                                                       lastName, suffix);

            if (validateDuplicates)
            {
                var duplicatesHtml = Politicians.GetCandidateList(lastName, null, stateCode,
                                                                  null, true);
                AddCandidateDuplicatesHtml.Controls.Add(duplicatesHtml);
                if (duplicatesHtml.Controls.Count > 0)
                {
                    // Set up the duplicates dialog
                    AddCandidateFormattedName.SetValue(formattedName);
                    AddCandidateStateName.SetValue(StateCache.GetStateName(stateCode));
                    FeedbackAddNewCandidate.PostValidationError(ControlAddNewCandidateLName,
                                                                "Potential duplicate politician");
                    return;
                }
            }

            var newPoliticianKey = Politicians.GetUniqueKey(stateCode, lastName,
                                                            firstName, middleName, suffix);

            AddCandidateNewId.SetValue(newPoliticianKey);

            // If it's a primary, get the party key from the election
            //var partyKey = "X";
            var partyKey    = string.Empty; // mantis 508
            var electionKey = SafeGetElectionKey();

            if (Elections.IsPrimaryElection(electionKey))
            {
                partyKey = stateCode + Elections.GetNationalPartyCodeFromKey(electionKey);
            }

            Politicians.AddPolitician(newPoliticianKey, firstName, middleName, nickname,
                                      lastName, suffix, SafeGetOfficeKey(), partyKey, SecurePage.CreateUniquePassword());

            LogDataChange.LogInsert(Politicians.TableName, VotePage.UserName, SecurePage.UserSecurityClass,
                                    DateTime.UtcNow, newPoliticianKey);

            ClearAddNewCandidate();

            FeedbackAddNewCandidate.AddInfo("Politician " + formattedName + " was added.");
            if (Mode == DataMode.AddPoliticians)
            {
                FeedbackAddNewCandidate.AddInfo(new HtmlAnchor
                {
                    InnerText = "Intro Page",
                    HRef      = UrlManager.GetIntroPageUri(newPoliticianKey).ToString(),
                    Target    = "Politician"
                }.RenderToString());
                FeedbackAddNewCandidate.AddInfo(new HtmlAnchor
                {
                    InnerText = "Politician Admin Page",
                    HRef      = SecureAdminPage.GetPoliticianPageUrl(newPoliticianKey),
                    Target    = "Politician"
                }.RenderToString());
            }
        }