Exemplo n.º 1
0
        public ViewResult Create()
        {
            var availableShoes = GetAvailableShoeList();

            var workout = new EditWorkoutViewModel
            {
                WorkoutDate = DateTime.Today,
                AvailableShoes = availableShoes
            };

            return View(workout);
        }
Exemplo n.º 2
0
        public ActionResult Create(EditWorkoutViewModel workoutViewModel)
        {
            if (ModelState.IsValid)
            {
                var workout = MapEditViewModelToWorkout(workoutViewModel);
                _dbContext.Workouts.Add(workout);
                _dbContext.SaveChanges();

                return RedirectToAction("Index");
            }

            return View(workoutViewModel);
        }
Exemplo n.º 3
0
        private Workout MapEditViewModelToWorkout(EditWorkoutViewModel workoutViewModel)
        {
            var shoeUsed = _dbContext.GetShoe(this.GetUserId(), workoutViewModel.ShoeUsedId);

            var workout = new Workout
            {
                UserId = this.GetUserId(),
                CreatedAt = DateTime.Now,
                Distance = workoutViewModel.Distance,
                Name = workoutViewModel.Name,
                ShoeUsed = shoeUsed,
                WorkoutDate = workoutViewModel.WorkoutDate,
                ImportedAt = DateTime.Now,
            };
            return workout;
        }
Exemplo n.º 4
0
        private EditWorkoutViewModel MapWorkoutToEditWorkoutViewModel(Workout workout)
        {
            var shoeUsedId = workout.ShoeUsed == null ? (long?) null : workout.ShoeUsed.ShoeId;
            var availableShoes = GetAvailableShoeList();

            var viewModel = new EditWorkoutViewModel
            {
                WorkoutId = workout.WorkoutId,
                WorkoutDate = workout.WorkoutDate,
                Distance = workout.Distance,
                ShoeUsedId = shoeUsedId,
                Name = workout.Name,
                AvailableShoes = availableShoes
            };
            return viewModel;
        }
Exemplo n.º 5
0
        public ActionResult Edit(EditWorkoutViewModel workoutViewModel)
        {
            if (ModelState.IsValid)
            {
                var workout = _dbContext.GetWorkout(this.GetUserId(), workoutViewModel.WorkoutId);

                workout.Name = workoutViewModel.Name;
                workout.WorkoutDate = workoutViewModel.WorkoutDate;
                workout.Distance = workoutViewModel.Distance;

                var shoeUsed = _dbContext.GetShoe(this.GetUserId(), workoutViewModel.ShoeUsedId);
                workout.ShoeUsed = shoeUsed;

                _dbContext.SaveChanges();
                return RedirectToAction("Index");
            }
            return View(workoutViewModel);
        }