Пример #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 IActionResult Get(MuscleKey key)
 {
     try
     {
         var result = _musclesService.GetMuscle(key);
         return new OkObjectResult(result); // Muscle
     }
     catch (Exception exception)
     {
         return BadRequest(new WebApiException("Error", exception));
     }
 }
Пример #3
0
        /// <summary>
        /// Delete data in database
        /// </summary>
        /// <param name="key">Primary Key</param>
        public void Delete(MuscleKey key)
        {
            if (key == null || key.Id == 0)
                return;

            var row = _dbContext.Muscle.Where(m => m.Id == key.Id).FirstOrDefault();
            if (row != null)
            {
                _dbContext.Muscle.Remove(row);
                _dbContext.SaveChanges();
            }
        }
Пример #4
0
 public void DeleteMuscle(MuscleKey key)
 {
     BeginTransaction();
     try
     {
         GetMuscleManager().DeleteMuscle(key);
         CommitTransaction();
         //invalidate cache
         InvalidateCache(_cacheName);
     }
     catch (Exception exception)
     {
         _logger.LogCritical("Unable to delete muscle", exception);
         RollbackTransaction();
         throw exception;
     }
     finally
     {
         EndTransaction();
     }
 }
Пример #5
0
 public IActionResult Delete(int id)
 {
     if (id != 0)
     {
         var key = new MuscleKey() { Id = id };
         var muscle = _musclesService.GetMuscle(key);
         if (muscle != null)
         {
             _musclesService.DeleteMuscle(muscle);
         }
     }
     return RedirectToAction("Index");
 }
Пример #6
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);
        }
Пример #7
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");
        }
Пример #8
0
 public Muscle GetMuscle(MuscleKey key)
 {
     Muscle muscle = null;
     string cacheKey = key == null ? "MuscleKey_null" : key.GetCacheKey();
     if (key != null && !TryGetCacheData(cacheKey, out muscle))
     {
         muscle = GetMuscleManager().GetMuscle(key);
         SetCacheData(_cacheName, cacheKey, muscle);
     }
     return muscle;
 }
Пример #9
0
 internal Muscle GetMuscle(MuscleKey key)
 {
     var result = _muscleModule.Get(key);
     CompleteTranslation(result);
     return result;
 }
Пример #10
0
 internal void DeleteMuscle(MuscleKey key)
 {
     //Update Translation Name
     Translation.DeleteInDB(MuscleTransformer.GetTranslationKey(key.Id), DbContext);
     _muscleModule.Delete(key);
 }
Пример #11
0
        /// <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;
        }