Example #1
0
        public IActionResult Edit(MuscleViewModel viewModel)
        {
            if (ModelState.IsValid && viewModel.Id > 0)
            {
                // Verify not exist on id
                var key = new MuscleKey()
                {
                    Id = viewModel.Id
                };
                var muscle = _musclesService.GetMuscle(key);
                if (muscle != null)
                {
                    muscle.Name            = viewModel.Name;
                    muscle.MuscularGroupId = viewModel.MuscularGroupId;
                    muscle = _musclesService.UpdateMuscle(muscle);
                    return(RedirectToAction("Index"));
                }
            }

            int muscularGroupId = 0;

            if (viewModel != null)
            {
                muscularGroupId = viewModel.MuscularGroupId;
            }

            ViewBag.MuscularGroups = ControllerUtils.CreateSelectMuscularGroupItemList(_muscularGroupsService.FindMuscularGroups(), muscularGroupId);

            return(View(viewModel));
        }
Example #2
0
        public IActionResult Create(MuscleViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var muscle = new Muscle()
                {
                    Name = viewModel.Name, MuscularGroupId = viewModel.MuscularGroupId
                };
                muscle = _musclesService.CreateMuscle(muscle);
                if (muscle == null || muscle.Id == 0)
                {
                    _logger.LogError("Create new muscle fail");
                }

                return(RedirectToAction("Index"));
            }

            ViewBag.MuscularGroups = ControllerUtils.CreateSelectMuscularGroupItemList(_muscularGroupsService.FindMuscularGroups(), 0);

            return(View(viewModel));
        }
Example #3
0
        public IActionResult Edit(int id)
        {
            if (id != 0)
            {
                var key = new MuscleKey()
                {
                    Id = id
                };
                var muscle = _musclesService.GetMuscle(key);
                if (muscle != null)
                {
                    var viewModel = new MuscleViewModel();
                    viewModel.Id              = muscle.Id;
                    viewModel.Name            = muscle.Name;
                    viewModel.MuscularGroupId = muscle.MuscularGroupId;

                    ViewBag.MuscularGroups = ControllerUtils.CreateSelectMuscularGroupItemList(_muscularGroupsService.FindMuscularGroups(), viewModel.MuscularGroupId);

                    return(View(viewModel));
                }
            }

            return(RedirectToAction("Index"));
        }
Example #4
0
        public IActionResult Create()
        {
            ViewBag.MuscularGroups = ControllerUtils.CreateSelectMuscularGroupItemList(_muscularGroupsService.FindMuscularGroups(), 0);

            return(View(new MuscleViewModel()));
        }