public static DailyCaseCountsBLDto ToDailyCasesBLDto(this DailyCaseCountsDADto rec) { return(new DailyCaseCountsBLDto { Date = rec.Date, Count = rec.Count }); }
public List <DailyCaseCountsDADto> GetDailyCaseCountsByCountry(Metrics metrics, string Country) { List <DailyCaseCountsDADto> DailyCaseCounts = new List <DailyCaseCountsDADto>(); SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["MSSQL_MainDB"].ConnectionString); SqlCommand sqlCommand = new SqlCommand("SELECT ConfirmedCases.[Date], ConfirmedCases.ConfirmedCasesCount As Count FROM ConfirmedCases INNER JOIN LocationsGlobal ON LocationsGlobal.Id = ConfirmedCases.Id WHERE LocationsGlobal.Country = @ctry", connection); connection.Open(); if (metrics == Metrics.DEATHS) { sqlCommand = new SqlCommand("SELECT Deaths.[Date], Deaths.DeathCount As Count FROM Deaths INNER JOIN LocationsGlobal ON LocationsGlobal.Id = Deaths.Id WHERE LocationsGlobal.Country = @ctry", connection); } else if (metrics == Metrics.RECOVERIES) { sqlCommand = new SqlCommand("SELECT Recoveries.[Date], Recoveries.RecoveriesCount As Count FROM Recoveries INNER JOIN LocationsGlobal ON LocationsGlobal.Id = Recoveries.Id WHERE LocationsGlobal.Country = @ctry", connection); } SqlParameter ctry = new SqlParameter("ctry", System.Data.SqlDbType.NVarChar); ctry.Value = Country; sqlCommand.Parameters.Add(ctry); SqlDataReader reader = sqlCommand.ExecuteReader(); try { while (reader.Read()) { DailyCaseCountsDADto DailyCaseCountsDto = new DailyCaseCountsDADto { Date = (DateTime)reader["Date"], Count = (int)reader["Count"] }; DailyCaseCounts.Add(DailyCaseCountsDto); } } catch (SqlException ex) { Console.WriteLine("Commit Exception Type: {0}", ex.GetType()); Console.WriteLine(" Message: {0}", ex.Message); } catch (Exception ex) { Console.WriteLine(ex.Message); } return(DailyCaseCounts); }