public void addingRoutineWorkout(routineWorkoutDAO addRoutineWorkout) { try { //create a connection to a database using our connection string variable using (SqlConnection _connection = new SqlConnection(connectionStrings)) { using (SqlCommand _command = new SqlCommand("sp_addRoutineWorkout", _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_exerciseID", addRoutineWorkout.FK_exerciseID); _command.Parameters.AddWithValue("@FK_routineWorkoutID", addRoutineWorkout.FK_routineWorkoutID); _command.Parameters.AddWithValue("@routineWSets", addRoutineWorkout.routineWSets); _command.Parameters.AddWithValue("@routineWReps", addRoutineWorkout.routineWReps); _command.Parameters.AddWithValue("@routineWRest", addRoutineWorkout.routineWRest); // 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); } }
public List <routineWorkoutDAO> listAllRoutineWorkout(int personID, int routineID) { // making a new instance of the list List <routineWorkoutDAO> _routineWorkoutList = new List <routineWorkoutDAO>(); try { using (SqlConnection _connection = new SqlConnection(connectionStrings)) { using (SqlCommand _command = new SqlCommand("sp_viewRoutineWorkout", _connection)) { // specify whay type of command is to be used _command.CommandType = CommandType.StoredProcedure; _command.Parameters.AddWithValue("@personID", personID); _command.Parameters.AddWithValue("@routineID", routineID); _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. routineWorkoutDAO routineWorkoutToList = new routineWorkoutDAO(); routineWorkoutToList.routineWorkoutID = _reader.GetInt32(_reader.GetOrdinal("routineWorkoutID")); routineWorkoutToList.exerciseName = (string)_reader["exerciseName"]; routineWorkoutToList.routineName = (string)_reader["routineName"]; routineWorkoutToList.routineWSets = _reader.GetByte(_reader.GetOrdinal("routineWSets")); routineWorkoutToList.routineWReps = _reader.GetByte(_reader.GetOrdinal("routineWReps")); routineWorkoutToList.routineWRest = _reader.GetInt16(_reader.GetOrdinal("routineWRest")); // adding values to varibale _personList.add _routineWorkoutList.Add(routineWorkoutToList); } } else { // showing error if no data found Console.WriteLine("No data found"); } } } } } catch (Exception _error) { _logger.logError(_error); } // returning routine workou list return(_routineWorkoutList); }
public BL_routineWorkout map(routineWorkoutDAO _routineWorkoutToMap) { // put all the info in business logic routine exerices from databases BL_routineWorkout _routineWorkoutToReturn = new BL_routineWorkout(); _routineWorkoutToReturn.routineWorkoutID = _routineWorkoutToMap.routineWorkoutID; _routineWorkoutToReturn.FK_exerciseID = _routineWorkoutToMap.FK_exerciseID; _routineWorkoutToReturn.FK_routineWorkoutID = _routineWorkoutToMap.FK_routineWorkoutID; _routineWorkoutToReturn.routineWSets = _routineWorkoutToMap.routineWSets; _routineWorkoutToReturn.routineWReps = _routineWorkoutToMap.routineWReps; _routineWorkoutToReturn.routineWRest = _routineWorkoutToMap.routineWRest; return(_routineWorkoutToReturn); }
// mapping data back to routineWorkout DAO public routineWorkoutModel map(routineWorkoutDAO _routineWorkoutMod) { // making new instance of routineWorkout model routineWorkoutModel _routineWorkoutRetMod = new routineWorkoutModel(); _routineWorkoutRetMod.routineWorkoutID = _routineWorkoutMod.routineWorkoutID; _routineWorkoutRetMod.FK_exerciseID = _routineWorkoutMod.FK_exerciseID; _routineWorkoutRetMod.FK_routineWorkoutID = _routineWorkoutMod.FK_routineWorkoutID; _routineWorkoutRetMod.routineWSets = _routineWorkoutMod.routineWSets; _routineWorkoutRetMod.routineWReps = _routineWorkoutMod.routineWReps; _routineWorkoutRetMod.routineWRest = _routineWorkoutMod.routineWRest; return(_routineWorkoutRetMod); }