Exemplo n.º 1
0
 public IActionResult Create(string returnUrl = null)
 {
     ViewBag.Muscles            = ControllerUtils.CreateSelectMuscleItemList(_musclesService.FindMuscles(), 0);
     ViewBag.ExerciseCategories = ControllerUtils.CreateSelectExerciseCategoryTypeItemList(0);
     ViewBag.ExerciseUnitTypes  = ControllerUtils.CreateSelectExerciseUnitTypeItemList(0);
     return(View(new BodyExerciseViewModel()));
 }
Exemplo n.º 2
0
        public IActionResult Edit(int id)
        {
            if (id > 0)
            {
                var key = new BodyExerciseKey()
                {
                    Id = id
                };
                var bodyExercise = _bodyExercisesService.GetBodyExercise(key);
                if (bodyExercise != null)
                {
                    var bodyExerciseViewModel = new BodyExerciseViewModel();
                    bodyExerciseViewModel.Id                   = bodyExercise.Id;
                    bodyExerciseViewModel.Name                 = bodyExercise.Name;
                    bodyExerciseViewModel.MuscleId             = bodyExercise.MuscleId;
                    bodyExerciseViewModel.MuscleName           = Translation.GetInDB(MuscleTransformer.GetTranslationKey(bodyExercise.MuscleId));
                    bodyExerciseViewModel.ExerciseCategoryType = (int)bodyExercise.ExerciseCategoryType;
                    bodyExerciseViewModel.ExerciseUnitType     = (int)bodyExercise.ExerciseUnitType;
                    bodyExerciseViewModel.ImageUrl             = ImageUtils.GetImageUrl(_env.WebRootPath, "bodyexercises", bodyExercise.ImageName);

                    ViewBag.Muscles            = ControllerUtils.CreateSelectMuscleItemList(_musclesService.FindMuscles(), bodyExercise.MuscleId);
                    ViewBag.ExerciseCategories = ControllerUtils.CreateSelectExerciseCategoryTypeItemList((int)bodyExercise.ExerciseCategoryType);
                    ViewBag.ExerciseUnitTypes  = ControllerUtils.CreateSelectExerciseUnitTypeItemList((int)bodyExercise.ExerciseUnitType);

                    return(View(bodyExerciseViewModel));
                }
            }
            return(RedirectToAction("Index"));
        }
Exemplo n.º 3
0
        public IActionResult Edit(BodyExerciseViewModel bodyExerciseViewModel, IFormFile imageFile)
        {
            if (ModelState.IsValid)
            {
                // Verify not exist on bodyExercise name
                var key = new BodyExerciseKey()
                {
                    Id = bodyExerciseViewModel.Id
                };
                var bodyExercise = _bodyExercisesService.GetBodyExercise(key);
                if (bodyExercise != null)
                {
                    string oldImageName = bodyExercise.ImageName;
                    bodyExercise.Name                 = bodyExerciseViewModel.Name;
                    bodyExercise.MuscleId             = bodyExerciseViewModel.MuscleId;
                    bodyExercise.ExerciseCategoryType = Utils.IntToEnum <TExerciseCategoryType>(bodyExerciseViewModel.ExerciseCategoryType);
                    bodyExercise.ExerciseUnitType     = Utils.IntToEnum <TExerciseUnitType>(bodyExerciseViewModel.ExerciseUnitType);
                    bodyExercise = _bodyExercisesService.UpdateBodyExercise(bodyExercise);
                    //Save a new Image if it's correct
                    if (ImageUtils.CheckUploadedImageIsCorrect(imageFile, "png"))
                    {
                        ImageUtils.SaveImage(imageFile, Path.Combine(_env.WebRootPath, "images", "bodyexercises"), bodyExercise.ImageName);
                    }

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

            ViewBag.Muscles            = ControllerUtils.CreateSelectMuscleItemList(_musclesService.FindMuscles(), bodyExerciseViewModel?.MuscleId ?? 0);
            ViewBag.ExerciseCategories = ControllerUtils.CreateSelectExerciseCategoryTypeItemList(bodyExerciseViewModel?.ExerciseCategoryType ?? 0);
            ViewBag.ExerciseUnitTypes  = ControllerUtils.CreateSelectExerciseUnitTypeItemList(bodyExerciseViewModel?.ExerciseUnitType ?? 0);

            return(View(bodyExerciseViewModel));
        }
Exemplo n.º 4
0
        public IActionResult Create(BodyExerciseViewModel bodyExerciseViewModel, IFormFile imageFile)
        {
            if (ModelState.IsValid)
            {
                var bodyExercise = new BodyExercise()
                {
                    Name                 = bodyExerciseViewModel.Name,
                    MuscleId             = bodyExerciseViewModel.MuscleId,
                    ExerciseCategoryType = Utils.IntToEnum <TExerciseCategoryType>(bodyExerciseViewModel.ExerciseCategoryType),
                    ExerciseUnitType     = Utils.IntToEnum <TExerciseUnitType>(bodyExerciseViewModel.ExerciseUnitType)
                };
                bodyExercise = _bodyExercisesService.CreateBodyExercise(bodyExercise);
                if (bodyExercise == null || bodyExercise.Id == 0)
                {
                    _logger.LogError("Create new Body Exercise fail");
                }
                else if (ImageUtils.CheckUploadedImageIsCorrect(imageFile, "png"))
                {
                    ImageUtils.SaveImage(imageFile, Path.Combine(_env.WebRootPath, "images", "bodyexercises"), bodyExercise.ImageName);
                }

                return(RedirectToAction("Index"));
            }

            ViewBag.Muscles            = ControllerUtils.CreateSelectMuscleItemList(_musclesService.FindMuscles(), 0);
            ViewBag.ExerciseCategories = ControllerUtils.CreateSelectExerciseCategoryTypeItemList(0);
            ViewBag.ExerciseUnitTypes  = ControllerUtils.CreateSelectExerciseUnitTypeItemList(0);

            return(View(bodyExerciseViewModel));
        }