Exemplo n.º 1
0
        /// <summary>
        /// Refresh the list and return it.
        /// </summary>
        /// <returns></returns>
        public string RefreshAndGetListOfAvailableElections()
        {
            const string template = "<option value=\"{0}\">{1} {2}</option>";

            var activeElectionGuids = new ComputerCacher().ElectionGuidsOfActiveComputers;

            if (activeElectionGuids.Count == 0)
            {
                return(template.FilledWith(0, "(No elections are active right now.)", ""));
            }

            //TODO - does this hit the DB every time??
            var elections = Db.Election
                            .Where(e => activeElectionGuids.Contains(e.ElectionGuid) &&
                                   e.ListForPublic.HasValue &&
                                   e.ListForPublic.Value &&
                                   e.ElectionPasscode != null)
                            .Select(e => new { e.Name, e.ElectionGuid, e.Convenor })
                            .ToList();

            return(elections
                   .OrderBy(e => e.Name)
                   .Select(e => template.FilledWith(e.ElectionGuid, e.Name, e.Convenor.SurroundContentWith("(", ")")))
                   .JoinedAsString());
        }