Пример #1
0
        public List <PresidentDto> GetPresidentsInfo(PresidentFieldEnum sortByEnum, bool isDescending)
        {
            // Setup the CSV reader
            CsvHelper.Configuration.Configuration configuration = new CsvHelper.Configuration.Configuration
            {
                AllowComments            = true,
                DetectColumnCountChanges = true,
                HasHeaderRecord          = false,
                Delimiter   = ";",
                CultureInfo = CultureInfo.InvariantCulture
            };
            configuration.RegisterClassMap <PresidentMapper>();
            // Read the CSV content
            string     content    = GetCsv(Parameter.PresidentsCsv);
            TextReader textReader = new StringReader(content);
            CsvReader  csvReader  = new CsvReader(textReader, configuration);
            IEnumerable <PresidentDto> records = csvReader.GetRecords <PresidentDto>();

            // Order the list
            if (sortByEnum != PresidentFieldEnum.None)
            {
                var propertyInfo = typeof(PresidentDto).GetProperty(sortByEnum.ToString());
                if (propertyInfo != null)
                {
                    records = isDescending
                        ? records.OrderByDescending(item => propertyInfo.GetValue(item, null))
                        : records.OrderBy(item => propertyInfo.GetValue(item, null));
                }
            }

            return(records.ToList());
        }
Пример #2
0
 public List <PresidentDto> Get(PresidentFieldEnum sortBy = PresidentFieldEnum.None, bool isDescending = false)
 {
     return(Factory.PresidentControl.GetPresidentsInfo(sortBy, isDescending));
 }