public void updateSetsReps(routineDAO _routineSetsReps, int routineID) { try { using (SqlConnection _connection = new SqlConnection(connectionStrings)) { using (SqlCommand _command = new SqlCommand("sp_updateSetsReps", _connection)) { // specify whay type of command is to be used _command.CommandType = CommandType.StoredProcedure; //where the values are sen to the command _command.Parameters.AddWithValue("@routineWSets", _routineSetsReps.totalSets); _command.Parameters.AddWithValue("@routineWReps", _routineSetsReps.totalReps); _command.Parameters.AddWithValue("@routineWExercise", _routineSetsReps.totalExercise); _command.Parameters.AddWithValue("@routineID", routineID); // 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 void addingRoutine(routineDAO addRoutine) { try { //create a connection to a database using our connection string variable using (SqlConnection _connection = new SqlConnection(connectionStrings)) { using (SqlCommand _command = new SqlCommand("sp_addRoutine", _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("@routineName", addRoutine.routineName); _command.Parameters.AddWithValue("@FK_personID", addRoutine.FK_personID); _command.Parameters.AddWithValue("@login", addRoutine.login); _command.Parameters.AddWithValue("@totalSets", addRoutine.totalSets); _command.Parameters.AddWithValue("@totalReps", addRoutine.totalReps); _command.Parameters.AddWithValue("@totalExercise", addRoutine.totalExercise); // 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 <routineDAO> listAllRoutine(int personID) { // making a new instance of the list List <routineDAO> _routineList = new List <routineDAO>(); try { using (SqlConnection _connection = new SqlConnection(connectionStrings)) { using (SqlCommand _command = new SqlCommand("sp_viewRoutine", _connection)) { // specify whay type of command is to be used _command.CommandType = CommandType.StoredProcedure; _command.Parameters.AddWithValue("@personID", personID); //attempt to open connection _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. routineDAO routineToList = new routineDAO(); routineToList.routineID = _reader.GetInt32(0); routineToList.routineName = (string)_reader["routineName"]; routineToList.FK_personID = _reader.GetInt32(2); routineToList.login = _reader.GetDateTime(3); routineToList.totalSets = _reader.GetInt32(4); routineToList.totalReps = _reader.GetInt32(5); routineToList.totalExercise = _reader.GetInt32(6); // adding values to varibale _personList.add _routineList.Add(routineToList); } } else { // showing error if no data found Console.WriteLine("No data found"); } } } } } catch (Exception _error) { _logger.logError(_error); } // returning routine list return(_routineList); }
public routineDAO listSingleRoutine(int personID, int routineID) { // making a new instance of the list routineDAO _singleRoutine = new routineDAO(); try { using (SqlConnection _connection = new SqlConnection(connectionStrings)) { using (SqlCommand _command = new SqlCommand("sp_viewSingleRoutine", _connection)) { // specify whay type of command is to be used _command.CommandType = CommandType.StoredProcedure; _command.Parameters.AddWithValue("@personID", personID); _command.Parameters.AddWithValue("@routineID", routineID); //attempt to open connection _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. _singleRoutine.routineName = (string)_reader["routineName"]; _singleRoutine.login = _reader.GetDateTime(_reader.GetOrdinal("login")); _singleRoutine.totalSets = _reader.GetInt32(_reader.GetOrdinal("totalSets")); _singleRoutine.totalReps = _reader.GetInt32(_reader.GetOrdinal("totalReps")); _singleRoutine.totalExercise = _reader.GetInt32(_reader.GetOrdinal("totalExercise")); } } else { // showing error if no data found Console.WriteLine("No data found"); } } } } } catch (Exception _error) { _logger.logError(_error); } // returning routine list return(_singleRoutine); }
public BL_routine map(routineDAO _routineToMap) { BL_routine _routineRetMod = new BL_routine(); _routineRetMod.routineID = _routineToMap.routineID; _routineRetMod.routineName = _routineToMap.routineName; _routineRetMod.FK_personID = _routineToMap.FK_personID; _routineRetMod.login = _routineToMap.login; _routineRetMod.totalSets = _routineToMap.totalSets; _routineRetMod.totalReps = _routineToMap.totalReps; _routineRetMod.totalExercise = _routineToMap.totalExercise; return(_routineRetMod); }
// mapping data to routine model public routineDAO map(routineModel _routineMod) { // making new instance of routine dao routineDAO _routineRetMod = new routineDAO(); _routineRetMod.routineID = _routineMod.routineID; _routineRetMod.routineName = _routineMod.routineName; _routineRetMod.FK_personID = _routineMod.FK_personID; _routineRetMod.login = _routineMod.login; _routineRetMod.totalSets = _routineMod.totalSets; _routineRetMod.totalReps = _routineMod.totalReps; _routineRetMod.totalExercise = _routineMod.totalExercise; return(_routineRetMod); }
public ActionResult viewRoutine() { if ((int)Session["FK_roleID"] == 1 || (int)Session["FK_roleID"] == 2 || (int)Session["FK_roleID"] == 3) { try { // making int variable personid to view routines for that member int _personID = (int)Session["personID"]; // new instance of view model viewModel viewRoutine = new viewModel(); // getting the list from view model to map it the data access to view all routines viewRoutine.routineList = _mapper.map(_routineDataAccess.listAllRoutine(_personID)); //making a for loop to count total sets and reps and exercises for the routine for (int i = 0; i < viewRoutine.routineList.Count(); i++) { // making an int variable to hold routineid int _routineID = viewRoutine.routineList[i].routineID; // make data access object with listing single routine routineDAO routine = _routineDataAccess.listSingleRoutine(_personID, _routineID); // calling in the business logic layer with the object and routine and person id's _workoutLogic.addSets(_blMapper.map(routine), _routineID, _personID); } // updated view viewRoutine.routineList = _mapper.map(_routineDataAccess.listAllRoutine(_personID)); return(View(viewRoutine)); } catch (Exception _error) { // putting error into a file _logger.logError(_error); } } return(View("Error")); }