public IActionResult Index()
        {
            var result        = new List <BodyExerciseViewModel>();
            var muscles       = _musclesService.FindMuscles();
            var bodyExercises = _bodyExercisesService.FindBodyExercises();

            if (bodyExercises != null && muscles != null)
            {
                foreach (var muscle in muscles.OrderBy(t => t.Name))
                {
                    foreach (var bodyExercise in bodyExercises)
                    {
                        if (muscle.Id == bodyExercise.MuscleId)
                        {
                            result.Add(new BodyExerciseViewModel()
                            {
                                Id                   = bodyExercise.Id,
                                Name                 = bodyExercise.Name,
                                ImageUrl             = ImageUtils.GetImageUrl(_env.WebRootPath, "bodyexercises", bodyExercise.ImageName),
                                MuscleId             = bodyExercise.MuscleId,
                                ExerciseCategoryType = (int)bodyExercise.ExerciseCategoryType,
                                ExerciseUnitType     = (int)bodyExercise.ExerciseUnitType,
                                MuscleName           = Resources.Translation.GetInDB(MuscleTransformer.GetTranslationKey(bodyExercise.MuscleId))
                            });
                        }
                    }
                }
            }
            return(View(result));
        }
        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"));
        }
Beispiel #3
0
        /// <summary>
        /// Create data in database
        /// </summary>
        /// <param name="muscle">Data</param>
        /// <returns>insert data</returns>
        public Muscle Create(Muscle muscle)
        {
            if (muscle == null)
            {
                return(null);
            }

            if (muscle.Id == 0)
            {
                var key = new MuscleKey();
                var sequencerManager = new SequencerManager();
                do
                {
                    key.Id = sequencerManager.GetNextValue(_dbContext, 4, "muscle");
                }while (Get(key) != null); // Test Record exist
                muscle.Id = key.Id;
            }

            if (muscle.Id == 0)
            {
                return(null);
            }

            var row = new MuscleRow();

            MuscleTransformer.ToRow(muscle, row);
            _dbContext.Muscle.Add(row);
            _dbContext.SaveChanges();

            return(MuscleTransformer.ToBean(row));
        }
Beispiel #4
0
 private void CompleteTranslation(Muscle muscle)
 {
     if (muscle != null)
     {
         string trKey = MuscleTransformer.GetTranslationKey(muscle.Id);
         muscle.Name = Translation.GetInDB(trKey, DbContext);
     }
 }
Beispiel #5
0
        internal Muscle GetMuscle(MuscleKey key)
        {
            var muscle = _module.Get(key);

            if (muscle != null)
            {
                muscle.Name = Translation.GetInDB(MuscleTransformer.GetTranslationKey(muscle.Id));
            }
            return(muscle);
        }
        /// <summary>
        /// Create data in database
        /// </summary>
        /// <param name="muscle">Data</param>
        /// <returns>insert data</returns>
        public Muscle Create(Muscle muscle)
        {
            if (muscle == null || muscle.Id == 0)
            {
                return(null);
            }

            var row = new MuscleRow();

            MuscleTransformer.ToRow(muscle, row);
            _dbContext.Muscle.Add(row);
            _dbContext.SaveChanges();
            return(MuscleTransformer.ToBean(row));
        }
        /// <summary>
        /// Get data in database
        /// </summary>
        /// <param name="key">Primary Key</param>
        /// <returns>read data</returns>
        public Muscle Get(MuscleKey key)
        {
            if (key == null || key.Id == 0)
            {
                return(null);
            }

            var row = _dbContext.Muscle.Where(m => m.Id == key.Id).FirstOrDefault();

            if (row != null)
            {
                return(MuscleTransformer.ToBean(row));
            }
            return(null);
        }
Beispiel #8
0
        public List <Muscle> FindMuscles(MuscleCriteria muscleCriteria = null)
        {
            var muscleList = _module.Find(muscleCriteria);

            if (muscleList != null)
            {
                foreach (var muscle in muscleList)
                {
                    if (muscle != null)
                    {
                        muscle.Name = Translation.GetInDB(MuscleTransformer.GetTranslationKey(muscle.Id));
                    }
                }
            }

            return(muscleList);
        }
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public List <Muscle> Find(MuscleCriteria muscleCriteria = null)
        {
            List <Muscle>          resultList = null;
            TableQuery <MuscleRow> rowList    = _dbContext.Table <MuscleRow>();

            CriteriaTransformer.CompleteQuery(ref rowList, muscleCriteria);

            if (rowList != null && rowList.Count() > 0)
            {
                resultList = new List <Muscle>();
                foreach (var row in rowList)
                {
                    resultList.Add(MuscleTransformer.ToBean(row));
                }
            }
            return(resultList);
        }
        /// <summary>
        /// Update data in database
        /// </summary>
        /// <param name="muscle">data</param>
        /// <returns>updated data</returns>
        public Muscle Update(Muscle muscle)
        {
            if (muscle == null || muscle.Id == 0)
            {
                return(null);
            }

            var row = _dbContext.Muscle.Where(m => m.Id == muscle.Id).FirstOrDefault();

            if (row == null)
            {             // No data in database
                return(Create(muscle));
            }
            else
            {             //Modify Data in database
                MuscleTransformer.ToRow(muscle, row);
                _dbContext.SaveChanges();
                return(MuscleTransformer.ToBean(row));
            }
        }
        /// <summary>
        /// Update data in database
        /// </summary>
        /// <param name="muscle">data</param>
        /// <returns>updated data</returns>
        public Muscle Update(Muscle muscle)
        {
            if (muscle == null || muscle.Id == 0)
            {
                return(null);
            }

            var row = _dbContext.Table <MuscleRow>().Where(m => m.Id == muscle.Id).FirstOrDefault();

            if (row == null)
            {             // No data in database
                return(Create(muscle));
            }
            else
            {                           //Modify Data in database
                MuscleTransformer.ToRow(muscle, row);
                _dbContext.Delete(row); //Update don't work... need delete and insert
                _dbContext.Insert(row);
                return(MuscleTransformer.ToBean(row));
            }
        }
Beispiel #12
0
 internal void DeleteMuscle(MuscleKey key)
 {
     //Update Translation Name
     Translation.DeleteInDB(MuscleTransformer.GetTranslationKey(key.Id), DbContext);
     _muscleModule.Delete(key);
 }