コード例 #1
0
ファイル: VandFService.cs プロジェクト: matusevichy/mycpp
 public List<VandF> GetOfCaloriesInRange(int min, int max)
 {
     List<VandF> vandFs = new List<VandF>();
     using (SqlConnection connection = new SqlConnection(connectionString))
     {
         connection.Open();
         Console.WriteLine("Success connection");
         SqlCommand command = new SqlCommand
         {
             Connection = connection,
             CommandText = "Select * from VandF where calories between @min and @max"
         };
         command.Parameters.AddWithValue("@min", min);
         command.Parameters.AddWithValue("@max", max);
         using (var reader = command.ExecuteReader())
         {
             if (reader.HasRows)
             {
                 while (reader.Read())
                 {
                     VandF vandF = new VandF
                     {
                         Id = reader.GetInt32(0),
                         Name = reader.GetString(1),
                         Type = reader.GetString(2),
                         Color = reader.GetString(3),
                         Calories = reader.GetDecimal(4)
                     };
                     vandFs.Add(vandF);
                 }
             }
         }
     }
     return vandFs;
 }
コード例 #2
0
ファイル: VandFService.cs プロジェクト: matusevichy/mycpp
 public List<VandF> GetAll()
 {
     List<VandF> vandFs = new List<VandF>();
     using (SqlConnection connection = new SqlConnection(connectionString))
     {
         connection.Open();
         Console.WriteLine("Success connection");
         SqlCommand command = new SqlCommand
         {
             Connection = connection,
             CommandText = "Select * from VandF"
         };
         using (var reader = command.ExecuteReader())
         {
             if (reader.HasRows)
             {
                 while (reader.Read())
                 {
                     VandF vandF = new VandF
                     {
                         Id = reader.GetInt32(0),
                         Name = reader.GetString(1),
                         Type = reader.GetString(2),
                         Color = reader.GetString(3),
                         Calories = reader.GetDecimal(4)
                     };
                     vandFs.Add(vandF);
                 }
             }
         }
     }
     return vandFs;
 }
コード例 #3
0
ファイル: VandFService.cs プロジェクト: matusevichy/mycpp
 public List<VandF> GetOfColorList(List<string> colors)
 {
     List<VandF> vandFs = new List<VandF>();
     using (SqlConnection connection = new SqlConnection(connectionString))
     {
         connection.Open();
         Console.WriteLine("Success connection");
         var newColors = colors.Select(c => $"\'{c}\'");
         string list = String.Join(",", newColors);
         SqlCommand command = new SqlCommand
         {
             Connection = connection,
             CommandText = "select * from VandF where color in (@list)"
         };
         command.Parameters.AddWithValue("@list", list);
         using (var reader = command.ExecuteReader())
         {
             if (reader.HasRows)
             {
                 while (reader.Read())
                 {
                     VandF vandF = new VandF
                     {
                         Id = reader.GetInt32(0),
                         Name = reader.GetString(1),
                         Type = reader.GetString(2),
                         Color = reader.GetString(3),
                         Calories = reader.GetDecimal(4)
                     };
                     vandFs.Add(vandF);
                 }
             }
         }
     }
     return vandFs;
 }