示例#1
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);
        }
示例#2
0
        public static void ToRow(Muscle bean, MuscleRow row)
        {
            if (bean == null)
                return;

            row.Id = bean.Id;
            row.MuscularGroupId = bean.MuscularGroupId;
        }
示例#3
0
 private void CompleteTranslation(Muscle muscle)
 {
     if (muscle != null)
     {
         string trKey = MuscleTransformer.GetTranslationKey(muscle.Id);
         muscle.Name = Translation.GetInDB(trKey, DbContext);
     }
 }
示例#4
0
        internal Muscle UpdateMuscle(Muscle muscle)
        {
            SaveTranslation(muscle);

            Muscle result = _muscleModule.Update(muscle);
            CompleteTranslation(result);
            return result;
        }
示例#5
0
        internal static Muscle ToBean(MuscleRow row)
        {
            if (row == null)
                return null;

            var bean = new Muscle();
            bean.Id = row.Id;
            bean.MuscularGroupId = row.MuscularGroupId;
            return bean;
        }
示例#6
0
 internal Muscle CreateMuscle(Muscle muscle)
 {
     string name = muscle != null ? muscle.Name : null;
     var result = _muscleModule.Create(muscle);
     if(result != null && result.Id != 0)
     {
         result.Name = name;
         SaveTranslation(result);
         CompleteTranslation(result);
     }
     return result;
 }
示例#7
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);
        }
示例#8
0
 public Muscle CreateMuscle(Muscle muscle)
 {
     Muscle result = null;
     BeginTransaction();
     try
     {
         result = GetMuscleManager().CreateMuscle(muscle);
         CommitTransaction();
         //invalidate cache
         InvalidateCache(_cacheName);
     }
     catch (Exception exception)
     {
         _logger.LogCritical("Unable to create muscle", exception);
         RollbackTransaction();
         throw exception;
     }
     finally
     {
         EndTransaction();
     }
     return result;
 }
示例#9
0
 private void SaveTranslation(Muscle muscle)
 {
     if (muscle != null)
     {
         string trKey = BodyExerciseTransformer.GetTranslationKey(muscle.Id);
         Translation.UpdateInDB(trKey, muscle.Name, DbContext);
     }
 }
示例#10
0
        /// <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);
            }
        }