Ejemplo n.º 1
0
        //Create new exercise
        public bool CreateExercise(ExerciseCreate model)
        {
            //Error Handling
            using (var ctx = new ApplicationDbContext())
            {
                var workoutIds = ctx.Workouts.Where(w => w.OwnerId == _userId).Select(w => w.WorkoutId);

                if (workoutIds.Contains(model.WorkoutId))
                {
                    var entity =
                        new Exercise()
                    {
                        Name        = model.Name,
                        Description = model.Description,
                        Repetition  = model.Repetition,
                        Sets        = model.Sets,
                        Length      = model.Length,
                        Type        = model.Type,
                        Muscle      = model.Muscle,
                        OwnerId     = _userId,
                        WorkoutId   = model.WorkoutId
                    };

                    ctx.Exercises.Add(entity);
                    return(ctx.SaveChanges() == 1);
                }
                else
                {
                    return(false);
                }
            }
        }
Ejemplo n.º 2
0
        public IHttpActionResult Post(ExerciseCreate exercise)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreateExerciseService();

            if (!service.CreateExercise(exercise))
            {
                return(InternalServerError());
            }

            return(Ok());
        }
Ejemplo n.º 3
0
        public bool CreateExercise(ExerciseCreate model)
        {
            var entity =
                new Exercise()
            {
                WorkoutPlanId = model.WorkoutPlanId,
                Name          = model.Name,
                Level         = model.Level
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Exercises.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
Ejemplo n.º 4
0
        //Create a Exercise
        public bool CreateExercise(ExerciseCreate model)
        {
            var entity =
                new Exercise()
            {
                UserId              = _userId,
                ExerciseName        = model.ExerciseName,
                ExerciseDescription = model.ExerciseDescription,
                RoutineId           = model.RoutineID,
                CreatedUtc          = DateTimeOffset.UtcNow,
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Exercises.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
Ejemplo n.º 5
0
        public bool CreateExercise(ExerciseCreate model)
        {
            var entity =
                new Exercise()
            {
                OwnerId             = _userId,
                Activity            = model.Activity,
                Date                = model.Date,
                TimeSpentOnActivity = model.TimeSpentOnActivity,
                PersonId            = model.PersonId
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Exercises.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
Ejemplo n.º 6
0
        public bool CreateExercise(ExerciseCreate model)
        {
            var entity =
                new Exercise()
            {
                OwnerId         = _userId,
                NameOfExercise  = model.NameOfExercise,
                Duration        = model.Duration,
                TypeOfExercise  = model.TypeOfExercise,
                DifficultyLevel = model.DifficultyLevel
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Exercises.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
Ejemplo n.º 7
0
        public ActionResult Create(ExerciseCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var userId = Guid.Parse(User.Identity.GetUserId());

            var manager     = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new ApplicationDbContext()));
            var currentUser = manager.FindById(User.Identity.GetUserId());
            var userWeight  = currentUser.Weight;

            var service = new ExerciseService(userId, userWeight);

            service.CreateExercise(model);

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 8
0
        public bool CreateExercise(ExerciseCreate model)
        {
            var entity =
                new Exercise()
            {
                WorkoutId       = model.WorkoutId,
                ExerciseName    = model.ExerciseName,
                Sets            = model.Sets,
                Reps            = model.Reps,
                Weight          = model.Weight,
                DistanceInMiles = model.DistanceInMiles
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Exercises.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
Ejemplo n.º 9
0
        public ActionResult Create(ExerciseCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = CreateExerciseService();

            if (service.CreateExercise(model))
            {
                TempData["SaveResult"] = "Exercise Created.";

                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Unable to create exercise.");

            return(View(model));
        }
Ejemplo n.º 10
0
        public ActionResult Create(ExerciseCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = CreateExerciseService();

            if (service.CreateExercise(model))
            {
                TempData["SaveResult"] = "Your Exercise was Created.";
                return(RedirectToAction("Index"));
            }
            ;

            ModelState.AddModelError("", "Exercise could not be created.");

            return(View(model));
        }
Ejemplo n.º 11
0
        public ActionResult Create(ExerciseCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = CreateExerciseService();

            if (service.CreateExercise(model))
            {
                TempData["SaveResult"] = "Your entry was created.";
                return(RedirectToAction("Index"));
            }
            ;

            ModelState.AddModelError("", "Entry could not be created.");
            ViewBag.PersonId = new SelectList(_db.Persons, "PersonId", "Name", model.PersonId);

            return(View(model));
        }
Ejemplo n.º 12
0
        public bool CreateExercise(ExerciseCreate model)
        {
            var entity =
                new Workout()
            {
                OwnerId        = _userId,
                OwnerWeight    = _userWeightInPounds,
                Type           = model.Type,
                Intensity      = model.Intensity,
                Duration       = model.Duration,
                CaloriesBurned = 0,
                CreatedUtc     = DateTimeOffset.UtcNow,
            };


            CalorieCalculator.GetCalories(entity);

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Workouts.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }