Esempio n. 1
0
        private void GetPoliticianForSingleOption()
        {
            var politicianKey = TextBoxPoliticianKey.Text.Trim();

            if (string.IsNullOrWhiteSpace(politicianKey))
            {
                throw new VoteUIException("A Politician Key is required.");
            }

            if (!Politicians.PoliticianKeyExists(politicianKey))
            {
                throw new VoteUIException(politicianKey + " is not a valid PoliticianKey.");
            }

            var item = PoliticianImagesInfo.GetHeadshotDataForPolitician(politicianKey);

            LabelRows.Text = (item == null ? 0 : 1).ToString(CultureInfo.InvariantCulture);

            if (item == null)
            {
                throw new VoteUIException("Politician for PoliticianKey not found.");
            }

            SetLabelsFromItem(item);
            TextBoxPoliticianKey.Text = string.Empty; // only clear if valid
        }
Esempio n. 2
0
        private void GetNextPoliticianForNewOption()
        {
            var lastDate        = Str.ToDateTime(LabelUploadDate.Text, VoteDb.DateTimeMax);
            var lastKey         = LabelPoliticianKey.Text;
            var lastOfficeLevel = Str.ToIntOr0(LabelOfficeLevel.Text);

            var list = PoliticianImagesInfo.GetNextOutOfDateHeadshot(lastOfficeLevel,
                                                                     lastDate, lastKey);

            if (list.Count == 0)
            {
                throw new VoteUIException("No more out-of-date headshots.");
            }

            SetLabelsFromList(list);
        }
Esempio n. 3
0
        private void SetLabelsFromItem(PoliticianImagesInfo item)
        {
            if (item == null)
            {
                return;
            }
            LabelUploadDate.Text =
                item.ProfileOriginalDate.ToString(CultureInfo.InvariantCulture);
            //UploadDatePlaceHolder.Controls.Clear();
            //new LocalDate(item.ProfileOriginalDate, "M/D/YYYY h:mm:ss A")
            //  .AddTo(UploadDatePlaceHolder);
            LabelPoliticianKey.Text = item.PoliticianKey;
            LabelOfficeLevel.Text   = item.OfficeLevel.ToString(CultureInfo.InvariantCulture);
            LabelPolitician.Text    = Politicians.GetFormattedName(item.PoliticianKey) + " - " +
                                      Politician_PartyCode(item.PoliticianKey);
            var officeKey = GetPageCache().Politicians.GetOfficeKey(item.PoliticianKey);

            LabelOffice.Text = Offices.GetStateCodeFromKey(officeKey) + " - " +
                               Offices.FormatOfficeName(officeKey);
        }
Esempio n. 4
0
        private void GetNextPoliticianForStateOption()
        {
            try
            {
                var politicianKeys = ViewState[ViewStateKeysKey] as List <string>;
                int politicianIndex;
                if (ViewState[ViewStateIndexKey] is int)
                {
                    politicianIndex = (int)ViewState[ViewStateIndexKey];
                }
                else
                {
                    politicianIndex = int.MinValue; // invalid indicator
                }
                // If not found, its the right time to generate the list
                if ((politicianKeys == null) || (politicianIndex == int.MinValue))
                {
                    // Edit the StateCode
                    var stateCode = TextBoxStateCode.Text.Trim()
                                    .ToUpperInvariant();
                    TextBoxStateCode.Text = stateCode;
                    if (stateCode == string.Empty)
                    {
                        throw new VoteUIException("A State Code is required.");
                    }
                    if (!StateCache.IsValidStateCode(stateCode))
                    {
                        throw new VoteUIException("The State Code is not valid.");
                    }

                    // Edit the OfficeLevel
                    var officeLevel     = -1; // default of -1 means not used
                    var officeLevelText = TextBoxOfficeLevel.Text.Trim();
                    if (officeLevelText != string.Empty)
                    {
                        if (!int.TryParse(officeLevelText, out officeLevel))
                        {
                            throw new VoteUIException("The Office Level is not valid.");
                        }
                    }

                    var onlyOutOfDate = CheckBoxOutOfDateOnly.Checked;

                    var stateList = PoliticianImagesInfo.GetStateHeadshots(stateCode,
                                                                           officeLevel, onlyOutOfDate);

                    // Create the StateKeys object and save it in the ViewState
                    politicianIndex = -1;
                    politicianKeys  = stateList.Select(i => i.PoliticianKey)
                                      .ToList();
                    ViewState[ViewStateKeysKey]        = politicianKeys;
                    ViewState[ViewStateOutOfDateKey]   = onlyOutOfDate;
                    ViewState[ViewStateStateCodeKey]   = stateCode;
                    ViewState[ViewStateOfficeLevelKey] = officeLevel;
                    SetRowCountForStateOption();
                }

                // Advance to the next key and fetch if there are any more
                politicianIndex++;
                if (politicianIndex >= politicianKeys.Count)
                {
                    throw new VoteUIException(
                              "No more selected headshots for this selection criteria.");
                }

                var item =
                    PoliticianImagesInfo.GetHeadshotDataForPolitician(
                        politicianKeys[politicianIndex]);
                // Update the ViewState with the new index
                ViewState[ViewStateIndexKey] = politicianIndex;

                SetLabelsFromItem(item);
            }
            catch
            {
                // On failure don't leave possibly incomplete state option status
                ClearStateOptionStatus();
                throw; // Exception handled upstream
            }
        }