public ActionResult addRoutineWorkoutG()
        {
            if ((int)Session["FK_roleID"] == 1 || (int)Session["FK_roleID"] == 2 || (int)Session["FK_roleID"] == 3)
            {
                try
                {
                    // making new instance of the view model
                    viewModel viewExercise = new viewModel();
                    // using the database of all exercise and adding back to exercise list
                    viewExercise.exerciseList = _mapper.map(_exerciseData.listAllExercise());


                    viewExercise.bodyPartList = _mapper.map(_bodyPartData.listAllBodyPart());

                    // making new instance of routineWorkout model
                    routineWorkoutModel routineWorkoutModel = new routineWorkoutModel();
                    // populating the routineWorkoutmodel exercise list with view model exercise listt
                    routineWorkoutModel.exerciseList = viewExercise.exerciseList;
                    routineWorkoutModel.bodyPartList = viewExercise.bodyPartList;
                    // setting variable view exercise to the routine workout model exercise list
                    Session["viewExercise"] = routineWorkoutModel.exerciseList;
                    Session["viewBodyPart"] = routineWorkoutModel.bodyPartList;

                    // return the view  with routine workout model
                    return(View(routineWorkoutModel));
                }
                catch (Exception _error)
                {
                    // putting error into a file
                    _logger.logError(_error);
                }
            }

            return(View("Error"));
        }
        public ActionResult updateRoutineWorkout(routineWorkoutModel _updateRoutineWorkout)
        {
            if ((int)Session["FK_roleID"] == 1 || (int)Session["FK_roleID"] == 2 || (int)Session["FK_roleID"] == 3)
            {
                try
                {
                    // if model state is valid
                    if (ModelState.IsValid)
                    {
                        try
                        {
                            // getting the FK_routineWorkoutID from session variable FK_routineWorkoutID
                            _updateRoutineWorkout.FK_routineWorkoutID = (int)Session["FK_routineWorkoutID"];

                            // updating the the routine exercises based to the id
                            _routineWorkoutDataAccess.updateRoutineWorkout(_mapper.map(_updateRoutineWorkout));

                            // making new instance of routine model
                            routineModel modelforid = new routineModel();
                            // setting routineID to updated FK routineWorkoutID
                            modelforid.routineID = _updateRoutineWorkout.FK_routineWorkoutID;

                            // returning back the page view routine workout
                            return(RedirectToAction("viewRoutineWorkout", modelforid));
                        }
                        catch (Exception _error)
                        {
                            // putting error into a file
                            _logger.logError(_error);
                        }
                    }
                    return(View());
                }
                catch (Exception _error)
                {
                    // putting error into a file
                    _logger.logError(_error);
                }
            }
            return(View("Error"));
        }
        public ActionResult addRoutineWorkout(routineWorkoutModel _addRoutineWorkout)
        {
            if ((int)Session["FK_roleID"] == 1 || (int)Session["FK_roleID"] == 2 || (int)Session["FK_roleID"] == 3)
            {
                try
                {
                    // if model state is valid
                    if (ModelState.IsValid)
                    {
                        try
                        {
                            // using session varible to get the FK routineWorkoutID
                            _addRoutineWorkout.FK_routineWorkoutID = (int)Session["FK_routineWorkoutID"];
                            // then adding the the routin workout to the database with the ID
                            _routineWorkoutDataAccess.addingRoutineWorkout(_mapper.map(_addRoutineWorkout));

                            // making new instance of routine model
                            routineModel modelforID = new routineModel();
                            // setting routineID for modelforID to addingRoutineWorkout FK routineWorkout ID
                            modelforID.routineID = _addRoutineWorkout.FK_routineWorkoutID;

                            // return back to routineWorkout page that belongs to the modelforID
                            return(RedirectToAction("viewRoutineWorkout", modelforID));
                        }
                        catch (Exception _error)
                        {
                            // putting error into a file
                            _logger.logError(_error);
                        }
                    }
                    return(View());
                }
                catch (Exception _error)
                {
                    // putting error into a file
                    _logger.logError(_error);
                }
            }
            return(View("Error"));
        }
        public ActionResult updateRoutineWorkoutGet(routineWorkoutModel routineWorkout)
        {
            if ((int)Session["FK_roleID"] == 1 || (int)Session["FK_roleID"] == 2 || (int)Session["FK_roleID"] == 3)
            {
                try
                {
                    // making new instance of view model
                    viewModel viewExercise = new viewModel();
                    // poplating exercise model, exercise list from database
                    viewExercise.exerciseList = _mapper.map(_exerciseData.listAllExercise());
                    Session["viewBodyPart"]   = _mapper.map(_bodyPartData.listAllBodyPart());

                    routineWorkoutModel routineWorkoutModel = new routineWorkoutModel();
                    routineWorkoutModel.exerciseList = viewExercise.exerciseList;
                    Session["viewExercise"]          = routineWorkoutModel.exerciseList;


                    // setting session varibale routineWorkoutID to routineWorkoutID
                    Session["routineWorkoutID"] = routineWorkout.routineWorkoutID;

                    // setting exercise list to view exercise model exercise list
                    routineWorkout.exerciseList = viewExercise.exerciseList;

                    exerciseModel exercise = _mapper.map(_exerciseData.exercise(routineWorkout.exerciseName));
                    routineWorkout.FK_exerciseID = exercise.exerciseID;
                    routineWorkout.bodyPartID    = exercise.FK_bodyPart;

                    // return view, routine Workout
                    return(View(routineWorkout));
                }
                catch (Exception _error)
                {
                    // putting error into a file
                    _logger.logError(_error);
                }
            }
            // return back error page
            return(View("Error"));
        }
Example #5
0
        public ActionResult addWeights(weightsModel _addWeights)
        {
            if ((int)Session["FK_roleID"] == 1 || (int)Session["FK_roleID"] == 2 || (int)Session["FK_roleID"] == 3)
            {
                try
                {
                    // if model state is valid
                    if (ModelState.IsValid)
                    {
                        try
                        {
                            Session["weightsID"] = _addWeights.WeightsID;

                            _routineWorkoutDataAccess.addWeights(_mapper.map(_addWeights));

                            routineWorkoutModel modelForID = new routineWorkoutModel();
                            modelForID.routineWorkoutID = _addWeights.FK_routineWorkID;

                            // return back to routineWorkout page that belongs to the modelforID
                            return(RedirectToAction("viewRoutineWorkout", "routineWorkout", modelForID));
                        }
                        catch (Exception _error)
                        {
                            // putting error into a file
                            _logger.logError(_error);
                        }
                    }
                    return(View());
                }
                catch (Exception _error)
                {
                    // putting error into a file
                    _logger.logError(_error);
                }
            }
            return(View("Error"));
        }