Esempio n. 1
0
        public void addingExercise(exerciseDAO addExercise)
        {
            try
            {
                //create a connection to a database using our connection string variable
                using (SqlConnection _connection = new SqlConnection(connectionStrings))
                {
                    using (SqlCommand _command = new SqlCommand("sp_addExercise", _connection))
                    {
                        // specify whay type of command is to be used
                        _command.CommandType = CommandType.StoredProcedure;

                        //where the values are sent to the command
                        _command.Parameters.AddWithValue("@exerciseName", addExercise.exerciseName);
                        _command.Parameters.AddWithValue("@exerciseDescription", addExercise.exerciseDescription);
                        _command.Parameters.AddWithValue("@FK_bodyPart", addExercise.FK_bodyPart);

                        // this is where the connection is open
                        _connection.Open();

                        // this is where we will execute the command
                        _command.ExecuteNonQuery();
                    }
                }
            }
            catch (Exception _error)
            {
                // putting error into a file
                _logger.logError(_error);
            }
        }
Esempio n. 2
0
        // mapping data back to exercise DAO
        public exerciseModel map(exerciseDAO _exerciseMod)
        {
            // making new instance of exercise model
            exerciseModel _exerciseRetMod = new exerciseModel();

            _exerciseRetMod.exerciseID          = _exerciseMod.exerciseID;
            _exerciseRetMod.exerciseName        = _exerciseMod.exerciseName;
            _exerciseRetMod.exerciseDescription = _exerciseMod.exerciseDescription;
            _exerciseRetMod.FK_bodyPart         = _exerciseMod.FK_bodyPart;

            return(_exerciseRetMod);
        }
Esempio n. 3
0
        public List <exerciseDAO> bodyPartExercise(int FK_bodyPart)
        {
            // making a new instance of the list
            List <exerciseDAO> _exerciseList = new List <exerciseDAO>();

            try
            {
                using (SqlConnection _connection = new SqlConnection(connectionStrings))
                {
                    using (SqlCommand _command = new SqlCommand("sp_viewExercise", _connection))
                    {
                        // specify what type of command is to be used
                        _command.CommandType = CommandType.StoredProcedure;

                        //where the values are sent to the command
                        _command.Parameters.AddWithValue("@FK_bodyPart", FK_bodyPart);

                        _connection.Open();
                        using (SqlDataReader _reader = _command.ExecuteReader())
                        {
                            // checking if the _reader has rows
                            if (_reader.HasRows)
                            {
                                // loop to go through the columns
                                while (_reader.Read())
                                {
                                    // new instance of to store all the values into persontolist.
                                    exerciseDAO exerciseToList = new exerciseDAO();
                                    exerciseToList.exerciseID          = _reader.GetInt32(_reader.GetOrdinal("exerciseID"));
                                    exerciseToList.exerciseName        = (string)_reader["exerciseName"];
                                    exerciseToList.exerciseDescription = (string)_reader["exerciseDescription"];

                                    // adding values to varibale _personList.add
                                    _exerciseList.Add(exerciseToList);
                                }
                            }
                            else
                            {
                                // showing error if no data found
                                Console.WriteLine("No data found");
                            }
                        }
                    }
                }
            }
            catch (Exception _error)
            {
                _logger.logError(_error);
            }

            // returning exercise list
            return(_exerciseList);
        }