Ejemplo n.º 1
0
        public List <Dto.HomeMainDataTable> GetDataTableMain(Dto.DtParameters parameter, out int totalRow, out int totalFilter)
        {
            Func <string, DateTime?> parseDate = datestr =>
            {
                DateTime parsedDate;
                return(DateTime.TryParseExact(datestr, "yyyy", null, System.Globalization.DateTimeStyles.None, out parsedDate) ? parsedDate : (DateTime?)null);
            };

            var displayStart  = parameter.iDisplayStart;
            var displayLength = parameter.iDisplayLength;

            var countryCode = string.IsNullOrEmpty(parameter.sSearch_a) ? null : parameter.sSearch_a;
            var startDate   = parseDate(parameter.sSearch_b?.Trim());
            var endDate     = parseDate(parameter.sSearch_c?.Trim());
            var total       = new SqlParameter("@total", SqlDbType.Int)
            {
                Direction = ParameterDirection.Output
            };

            var spParameters = new List <SqlParameter>
            {
                new SqlParameter("offset", displayStart),
                new SqlParameter("fetch", displayLength),
                new SqlParameter("country_code", countryCode),
                new SqlParameter("start_date", startDate?.Year),
                new SqlParameter("end_date", endDate?.Year),
                total
            };

            var list = new List <Dto.HomeMainDataTable>();

            _dbContext.Query("sp_c_datatable_indicators_natalidad_mortalidad", spParameters, reader =>
            {
                list.Add(new Dto.HomeMainDataTable
                {
                    CountryName              = reader["CountryName"].ToString(),
                    Year                     = int.Parse(reader["Year"].ToString()),
                    BirthRateCrude           = decimal.Parse(reader["BirthRateCrude"].ToString()),
                    MortalityRateAdultMale   = decimal.Parse(reader["MortalityRateAdultMale"].ToString()),
                    MortalityRateAdultFemale = decimal.Parse(reader["MortalityRateAdultFemale"].ToString()),
                    MortalityRateInfant      = decimal.Parse(reader["MortalityRateAdultFemale"].ToString()),
                    MortalityRateUnder5      = decimal.Parse(reader["MortalityRateUnder5"].ToString()),
                    MortalityRate            = decimal.Parse(reader["MortalityRate"].ToString())
                });
            });

            totalFilter = totalRow = Convert.ToInt32(total.Value);

            return(list);
        }