Пример #1
0
        public Training GetTraining(int IdTraining)
        {
            ExerciseDAL exerciseDAL   = new ExerciseDAL(configuration);
            Training    result        = new Training();
            string      TrainingQuery = "SELECT * FROM [dbo].[Treningi] WHERE ID_Treningi = @ParamID";

            try
            {
                using (SqlConnection con = new SqlConnection(_connectionString))
                {
                    con.Open();
                    SqlCommand cmd = new SqlCommand(TrainingQuery, con);
                    cmd.Parameters.AddWithValue("@ParamID", IdTraining);
                    SqlDataReader rdr = cmd.ExecuteReader();
                    while (rdr.Read())
                    {
                        result.Id        = Convert.ToInt32(rdr[0]);
                        result.Duration  = Convert.ToInt32(rdr[1]);
                        result.Name      = rdr[2].ToString();
                        result.Exercises = exerciseDAL.GetTrainingExercises(IdTraining);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(result);
        }
Пример #2
0
        public List <Training> GetList()
        {
            ExerciseDAL exerciseDAL   = new ExerciseDAL(configuration);
            var         listTraining  = new List <Training>();
            string      trainingQuery = "SELECT * FROM [dbo].[Treningi]";

            try
            {
                using (SqlConnection con = new SqlConnection(_connectionString))
                {
                    SqlCommand cmd = new SqlCommand(trainingQuery, con);
                    con.Open();
                    SqlDataReader rdr = cmd.ExecuteReader();
                    while (rdr.Read())
                    {
                        listTraining.Add(new Training
                        {
                            Id        = Convert.ToInt32(rdr[0]),
                            Exercises = exerciseDAL.GetTrainingExercises(Convert.ToInt32(rdr[0])),
                            Duration  = Convert.ToInt32(rdr[1]),
                            Name      = rdr[2].ToString()
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            return(listTraining);
        }