Ejemplo n.º 1
0
        public ActionResult AddWorkout(AddWorkoutModel model, List<AddWorkoutModel.Exercise> Exercise)
        {
            if (!ModelState.IsValid)
            {
                return View(model);
            }
            var currentlyLoggedInUserId = (int)Session["UserId"];
            var workout = new Trainingsession();
            DateTime Date = DateTime.Parse(model.Date);
            workout.Date = Date;
            workout.Comment = model.Comment;
            workout.Title = model.WorkoutTitle;

            //adds the workout and returns and returns its id.
            var workoutID = DiaryRepository.addWorkout(workout, currentlyLoggedInUserId);

            var ListOfExercises = new List<TrainingIncludes_StrengthExercise>();
            foreach (var exer in Exercise)
            {
                var item = new TrainingIncludes_StrengthExercise();
                item.BodyWeight = model.BodyWeight;
                item.Repetitions = exer.Reps;
                item.Weight = exer.Weight;
                item.StrengthExerciseID = exer.ExerciseID;
                 ListOfExercises.Add(item);
            }

            //adds the exercises to the created workout
            DiaryRepository.addWorkoutExercises(workoutID, ListOfExercises);
            return RedirectToAction("DiaryOverview","Diary");
        }
Ejemplo n.º 2
0
        public ActionResult AddWorkout()
        {
            var model = new AddWorkoutModel();
            model.ExerciseDropdown = getListForExerciseDropdown(1);
            model.CategoriesList = getListForExercisCategorieseDropdown();

            return View(model);
        }