Exemple #1
0
        public ActionResult CreateWorkout(CreateWorkoutViewModel workout)
        {
            if (this.ModelState.IsValid)
            {
                var workoutDataModel = this.mapper.Map <WorkoutInformation>(workout);

                this.workoutInformationService.AddWorkoutInformation(workoutDataModel);

                var validExercisesIds = workout.AllExercises.Where(x => x.IsSelected == true).Select(x => x.Id).ToList();

                var validExerciseDataModels = new List <Exercise>();

                foreach (var id in validExercisesIds)
                {
                    var exerciseToInsert = this.exerciseService.GetById(id);

                    validExerciseDataModels.Add(exerciseToInsert);
                }

                this.workoutInformationService.InsertMultipleExercisesToWorkoutInformation(workoutDataModel, validExerciseDataModels);

                return(this.RedirectToAction("Index"));
            }

            return(this.RedirectToAction("CreateWorkout"));
        }
Exemple #2
0
        // grab the drop down menu selection
        public IActionResult Create(CreateWorkoutViewModel addWorkoutViewModel, int[] SelectedExercise)

        {
            if (ModelState.IsValid)
            {
                {
                    foreach (int userSelection in SelectedExercise)
                    {
                        // for each drop-down menu selection

                        {
                            //make a Workout

                            // TODO: add SAME WorkoutID to the GROUP of Exercises

                            Workout newWorkoutEntry = new Workout
                            {
                                Name             = addWorkoutViewModel.Name,
                                UserID           = User.Identity.Name,
                                Date             = addWorkoutViewModel.Date,
                                SelectedExercise = userSelection
                            };

                            //save the Workout to the Db
                            context.Workouts.Add(newWorkoutEntry);
                            context.SaveChanges();
                        }
                    }
                }

                return(View("CreateConfirmation"));
            }

            return(View("Create"));
        }
        public IActionResult Create(CreateWorkoutViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(this.View(viewModel));
            }

            var identityUserId = _userService.GetIdentityIdByUsername(this.User.Identity.Name);

            var mainUser = _userService.GetMainUserByIdentityId(identityUserId);

            var workout = new WorkoutRoutine
            {
                IsPublic  = viewModel.IsPublic,
                Name      = viewModel.Name,
                CreatorId = mainUser.Id,
            };

            var workoutDays = SetUpInitialWorkoutDays(workout.Id, viewModel.Days, viewModel.ExerciseName);

            workout.WorkoutDays = workoutDays;


            _repository.Add <WorkoutRoutine>(workout);

            return(Redirect("/Workout/Index"));
        }
        public ActionResult AddExercises(FormCollection formCollection)
        {
            var createWorkoutViewModel = new CreateWorkoutViewModel();

            if (TryUpdateModel(createWorkoutViewModel, formCollection))
            {
                var workoutmodel = AddExerciseDefinition(createWorkoutViewModel.ExerciseDefinition);
                var sessionModel = Session["CreateWorkout"] as CreateWorkoutViewModel;
                sessionModel.ExerciseDefinitions = workoutmodel.Result;
                if (sessionModel != null)
                {
                    var exercise = new Exercise();
                    exercise.ExerciseDefinition = createWorkoutViewModel.ExerciseDefinition;
                    if (sessionModel.WorkoutDefinition.Exercises != null)
                    {
                        sessionModel.WorkoutDefinition.Exercises.Add(exercise);
                    }
                    else
                    {
                        sessionModel.WorkoutDefinition.Exercises = new List <Exercise>();
                        sessionModel.WorkoutDefinition.Exercises.Add(exercise);
                    }
                    Session["CreateWorkout"] = sessionModel;
                    return(View("AddExercises", sessionModel));
                }
            }
            return(RedirectToAction("Index", "Home"));
        }
Exemple #5
0
        public void CreateWorkout_ShouldCallInsertIntoWorkoutInformationServiceCorrectDataModel()
        {
            var mapperStub                    = new Mock <IMapper>();
            var exerciseServiceStub           = new Mock <IExerciseService>();
            var workoutInformationServiceStub = new Mock <IWorkoutInformationService>();
            var weekScheduleServiceStub       = new Mock <IWeekScheduleService>();
            var modelViewFactoryStub          = new Mock <IModelViewFactory>();

            var sut = new ManagerController(mapperStub.Object, exerciseServiceStub.Object, workoutInformationServiceStub.Object, weekScheduleServiceStub.Object, modelViewFactoryStub.Object);

            var workoutViewModel = new CreateWorkoutViewModel();

            workoutViewModel.AllExercises = new List <ExerciseMutipleSelectionViewModel>()
            {
                new ExerciseMutipleSelectionViewModel
                {
                    IsSelected = true,
                    Id         = new Guid()
                }
            };

            var workoutDataModel = new WorkoutInformation();
            var exercise         = new Exercise();

            mapperStub.Setup(x => x.Map <WorkoutInformation>(It.IsAny <CreateWorkoutViewModel>())).Returns(workoutDataModel);
            workoutInformationServiceStub.Setup(x => x.AddWorkoutInformation(It.IsAny <WorkoutInformation>()));
            exerciseServiceStub.Setup(x => x.GetById(It.IsAny <Guid>())).Returns(exercise);
            workoutInformationServiceStub.Setup(x => x.InsertMultipleExercisesToWorkoutInformation(It.IsAny <WorkoutInformation>(), It.IsAny <ICollection <Exercise> >()));

            sut
            .WithCallTo(x => x.CreateWorkout(workoutViewModel));

            workoutInformationServiceStub.Verify(x => x.InsertMultipleExercisesToWorkoutInformation(workoutDataModel, It.IsAny <ICollection <Exercise> >()), Times.Once);
        }
Exemple #6
0
        public IActionResult Create()
        {
            // show a list of Exercise options
            CreateWorkoutViewModel addWorkoutViewModel = new CreateWorkoutViewModel(context.
                                                                                    Exercises.OrderBy(e => e.Name).ToList());

            return(View(addWorkoutViewModel));
        }
        public ActionResult Create(CreateWorkoutViewModel viewmodel)
        {
            var workoutmodel = AddWorkout(viewmodel.WorkoutDefinition);
            var listOfExerciseDefinitions = GetExerciseDefinitions();

            viewmodel.ExerciseDefinitions = listOfExerciseDefinitions.Result;
            Session["CreateWorkout"]      = viewmodel;

            return(View("AddExercises", viewmodel));
        }
Exemple #8
0
        public async Task <IActionResult> Create(CreateWorkoutViewModel vm)
        {
            if (ModelState.IsValid)
            {
                using (exercisesRepo)
                    using (workoutsRepo)
                        using (weRepo)
                            using (userManager)
                            {
                                var user = await userManager.GetUserAsync(HttpContext.User);

                                var exercises          = exercisesRepo.All().Where(e => e.ApplicationUserId == user.Id).ToList();
                                var selectedExercises  = vm.Exercises.Select(e => Int32.Parse(e));
                                var filteredExcercises = exercises.Where(e => selectedExercises.Contains(e.ExerciseId));

                                Workout workout = new Workout()
                                {
                                    WorkoutName       = vm.WorkoutName,
                                    WorkoutDetails    = vm.WorkoutDetails,
                                    DateCreated       = DateTime.Now,
                                    ApplicationUserId = user.Id
                                };
                                workoutsRepo.Add(workout);

                                foreach (var e in filteredExcercises)
                                {
                                    weRepo.Add(new WorkoutExercise()
                                    {
                                        Exercise = e, Workout = workout
                                    });
                                }


                                workoutsRepo.SaveChanges();
                                weRepo.SaveChanges();
                                return(RedirectToAction(nameof(Index)));
                            }
            }
            return(View(vm));
        }
        public async Task <IActionResult> CreateWorkout(CreateWorkoutViewModel model)
        {
            var user = await userManager.FindByNameAsync(User.Identity.Name);


            if (ModelState.IsValid)
            {
                GPWorkout gpworkout = new GPWorkout()
                {
                    Weight             = model.Weight,
                    Height             = model.Height,
                    BMI                = model.BMI,
                    WorkoutDescription = model.WorkoutDescription,
                    GoalId             = model.GoalId,
                    IsApproved         = false,
                    Id = user.Id
                };
                GPWorkoutBs.Create(gpworkout);
                return(RedirectToAction("CreateWorkout"));
            }

            ViewBag.Goals = GoalBs.GetAll();
            return(View());
        }
Exemple #10
0
        public ActionResult Create()
        {
            var viewmodel = new CreateWorkoutViewModel();

            return(View(viewmodel));
        }