Beispiel #1
0
        public ActionResult Delete(int idGoal)
        {
            var db = new DatabaseConnection(Server.MapPath("~"));

            db.connection.Open();

            GoalBL.DeleteGoal(idGoal, db);

            db.connection.Close();

            return(Redirect("Index", "Goal", null));
        }
Beispiel #2
0
        public JsonResult Modify(Goal goal)
        {
            var db = new DatabaseConnection(Server.MapPath("~"));

            db.connection.Open();

            GoalBL.UpdateGoal(goal, db);

            db.connection.Close();

            return(Json(new { status = "Saved" }));
        }
Beispiel #3
0
        public ActionResult Create(Goal goal)
        {
            goal.IdUser = (int)Session["IdUser"];

            var db = new DatabaseConnection(Server.MapPath("~"));

            db.connection.Open();

            GoalBL.CreateGoal(goal, db);

            db.connection.Close();
            return(Redirect("Index", "Goal", null));
        }
Beispiel #4
0
        public ActionResult Create()
        {
            var goal = new Goal();

            goal.Date = DateTime.Today;

            ViewBag.Units = GoalBL.GetUnits();

            var db = new DatabaseConnection(Server.MapPath("~"));

            db.connection.Open();

            ViewBag.Movements = GoalBL.GetMovementTypes(db);

            db.connection.Close();

            return(View(goal));
        }
Beispiel #5
0
        public ActionResult Index()
        {
            if (User.Identity.IsAuthenticated && Session["IdUser"] != null)
            {
                var db = new DatabaseConnection(Server.MapPath("~"));
                db.connection.Open();

                var goalList = GoalBL.GetGoals((int)Session["IdUser"], db);

                db.connection.Close();

                return(View(goalList));
            }
            else
            {
                return(RedirectToAction("Login", "User"));
            }
        }
Beispiel #6
0
        public ActionResult Details(int idGoal)
        {
            ViewBag.Units = GoalBL.GetUnits();

            var db = new DatabaseConnection(Server.MapPath("~"));

            db.connection.Open();

            ViewBag.Movements = GoalBL.GetMovementTypes(db);
            var goal = GoalBL.GetGoal(idGoal, db);

            db.connection.Close();


            if (goal.IdUser == (int)Session["IdUser"])
            {
                return(View(goal));
            }
            //Prevents users from accessing other users goals
            else
            {
                return(RedirectToAction("Index", "Goal"));
            }
        }
Beispiel #7
0
        // GET: Dashboard
        public ActionResult Index()
        {
            if (User.Identity.IsAuthenticated && Session["IdUser"] != null)
            {
                var dashboard = new Dashboard();

                var db = new DatabaseConnection(Server.MapPath("~"));
                db.connection.Open();

                var user           = UserBL.GetUser((int)Session["IdUser"], db);
                var meetResultList = MeetBL.GetResultsForUser((int)Session["IdUser"], db);
                var trainingList   = TrainingBL.GetTrainings((int)Session["IdUser"], db);
                var goalList       = GoalBL.GetGoals((int)Session["IdUser"], db);

                dashboard.Name = user.Name;

                var maxMeetSquat            = 0.0f;
                var maxMeetBench            = 0.0f;
                var maxMeetDeadlift         = 0.0f;
                var maxTrainingSquat        = 0.0f;
                var maxTrainingSquatUnit    = "";
                var maxTrainingBench        = 0.0f;
                var maxTrainingBenchUnit    = "";
                var maxTrainingDeadlift     = 0.0f;
                var maxTrainingDeadliftUnit = "";

                var accomplishedGoals = new List <GoalProgress>();
                var pendingGoals      = new List <GoalProgress>();

                foreach (var meetResult in meetResultList)
                {
                    if (meetResult.Success)
                    {
                        if (meetResult.MovementType == 1 && meetResult.Weight > maxMeetSquat)
                        {
                            maxMeetSquat = meetResult.Weight;
                        }

                        if (meetResult.MovementType == 2 && meetResult.Weight > maxMeetBench)
                        {
                            maxMeetBench = meetResult.Weight;
                        }

                        if (meetResult.MovementType == 3 && meetResult.Weight > maxMeetDeadlift)
                        {
                            maxMeetDeadlift = meetResult.Weight;
                        }
                    }
                }

                foreach (var training in trainingList)
                {
                    foreach (var exercise in TrainingBL.GetExercices(training.Id, db))
                    {
                        if (exercise.MovementType == 1 && exercise.Weight > maxTrainingSquat)
                        {
                            maxTrainingSquat     = exercise.Weight;
                            maxTrainingSquatUnit = exercise.Unit;
                        }

                        if (exercise.MovementType == 2 && exercise.Weight > maxTrainingBench)
                        {
                            maxTrainingBench     = exercise.Weight;
                            maxTrainingBenchUnit = exercise.Unit;
                        }

                        if (exercise.MovementType == 3 && exercise.Weight > maxTrainingDeadlift)
                        {
                            maxTrainingDeadlift     = exercise.Weight;
                            maxTrainingDeadliftUnit = exercise.Unit;
                        }
                    }
                }

                dashboard.MaxCompetitionSquat        = maxMeetSquat;
                dashboard.MaxCompetitionSquatUnit    = "kg";
                dashboard.MaxCompetitionBench        = maxMeetBench;
                dashboard.MaxCompetitionBenchUnit    = "kg";
                dashboard.MaxCompetitionDeadlift     = maxMeetDeadlift;
                dashboard.MaxCompetitionDeadliftUnit = "kg";

                dashboard.MaxTrainingSquat        = maxTrainingSquat;
                dashboard.MaxTrainingSquatUnit    = maxTrainingSquatUnit;
                dashboard.MaxTrainingBench        = maxTrainingBench;
                dashboard.MaxTrainingBenchUnit    = maxTrainingBenchUnit;
                dashboard.MaxTrainingDeadlift     = maxTrainingDeadlift;
                dashboard.MaxTrainingDeadliftUnit = maxTrainingDeadliftUnit;

                dashboard.SquatProgression = TrainingBL.GetSquatProgression((int)Session["IdUser"], db);

                dashboard.BenchProgression = TrainingBL.GetBenchProgression((int)Session["IdUser"], db);

                dashboard.DeadliftProgression = TrainingBL.GetDeadliftProgression((int)Session["IdUser"], db);

                foreach (var currentGoal in goalList)
                {
                    var    maxForRep    = TrainingBL.GetMaxForReps(currentGoal.MovementType, currentGoal.Repetition, db);
                    String exerciseName = "";

                    if (currentGoal.MovementType == 1)
                    {
                        exerciseName = "Squat";
                    }
                    else if (currentGoal.MovementType == 2)
                    {
                        exerciseName = "Bench";
                    }
                    else if (currentGoal.MovementType == 3)
                    {
                        exerciseName = "Deadlift";
                    }

                    if (maxForRep != null)
                    {
                        float normalisedMax = maxForRep.Weight;
                        var   date          = TrainingBL.GetHeader(maxForRep.IdTraining, db).Date;

                        if (maxForRep.Unit == "lbs" && currentGoal.Unit == "kg")
                        {
                            normalisedMax = normalisedMax / 2.2f;
                        }

                        else if (maxForRep.Unit == "kg" && currentGoal.Unit == "lbs")
                        {
                            normalisedMax = normalisedMax * 2.2f;
                        }

                        if (normalisedMax >= currentGoal.Weight)
                        {
                            accomplishedGoals.Add(new GoalProgress
                            {
                                goal = currentGoal,
                                PerformedExercise = maxForRep,
                                ExerciseName      = exerciseName,
                                Difference        = normalisedMax - currentGoal.Weight,
                                AccomplishedDate  = date
                            });
                        }

                        else
                        {
                            pendingGoals.Add(new GoalProgress
                            {
                                goal = currentGoal,
                                PerformedExercise = maxForRep,
                                ExerciseName      = exerciseName,
                                Difference        = normalisedMax - currentGoal.Weight
                            });
                        }
                    }
                    else
                    {
                        pendingGoals.Add(new GoalProgress
                        {
                            goal = currentGoal,
                            PerformedExercise =
                            {
                                Weight     = 0.0f,
                                Repetition =    0,
                                Unit       = "kg"
                            },
                            ExerciseName = exerciseName,
                            Difference   = 0.0f - currentGoal.Weight
                        });
                    }
                }

                dashboard.AccomplishedGoals = accomplishedGoals;

                dashboard.PendingGoals = pendingGoals;

                db.connection.Close();

                return(View(dashboard));
            }

            else
            {
                return(RedirectToAction("Login", "User"));
            }
        }