Ejemplo n.º 1
0
        public BodyExercise GetBodyExercise(BodyExerciseKey key)
        {
            BodyExercise result = _bodyExerciseModule.Get(key);

            CompleteTranslation(result);
            return(result);
        }
Ejemplo n.º 2
0
 public BodyExercise GetBodyExercise(BodyExerciseKey key)
 {
     var bodyExercise = _module.Get(key);
     if (bodyExercise != null)
         bodyExercise.Name = Translation.GetInDB(BodyExerciseTransformer.GetTranslationKey(bodyExercise.Id));
     return bodyExercise;
 }
Ejemplo n.º 3
0
        internal void DeleteBodyExercise(BodyExerciseKey key)
        {
            _bodyExerciseModule.Delete(key);

            //Update Translation Name
            Translation.DeleteInDB(BodyExerciseTransformer.GetTranslationKey(key.Id), DbContext);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Create data in database
        /// </summary>
        /// <param name="bodyExercise">Data</param>
        /// <returns>insert data</returns>
        public BodyExercise Create(BodyExercise bodyExercise)
        {
            if (bodyExercise == null)
            {
                return(null);
            }

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

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

            var bodyExerciseRow = new BodyExerciseRow();

            BodyExerciseTransformer.ToRow(bodyExercise, bodyExerciseRow);
            _dbContext.BodyExercise.Add(bodyExerciseRow);
            _dbContext.SaveChanges();
            return(BodyExerciseTransformer.ToBean(bodyExerciseRow));
        }
Ejemplo n.º 5
0
        internal void DeleteBodyExercise(BodyExerciseKey key)
        {
            _bodyExerciseModule.Delete(key);

            //Update Translation Name
            Translation.DeleteInDB(BodyExerciseTransformer.GetTranslationKey(key.Id), DbContext);
        }
Ejemplo n.º 6
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));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Create data in database
        /// </summary>
        /// <param name="bodyExercise">Data</param>
        /// <returns>insert data</returns>
        public BodyExercise Create(BodyExercise bodyExercise)
        {
            if (bodyExercise == null)
                return null;

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

            if (bodyExercise.Id == 0)
                return null;

            var bodyExerciseRow = new BodyExerciseRow();
            BodyExerciseTransformer.ToRow(bodyExercise, bodyExerciseRow);
            _dbContext.BodyExercise.Add(bodyExerciseRow);
            _dbContext.SaveChanges();
            return BodyExerciseTransformer.ToBean(bodyExerciseRow);
        }
Ejemplo n.º 8
0
        internal void Delete(BodyExerciseKey key)
        {
            //Update Translation Name
            //Translation.DeleteInDB(MuscularGroupTransformer.GetTranslationKey(key.Id), _dbContext);

            _module.Delete(key);
        }
Ejemplo n.º 9
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"));
        }
Ejemplo n.º 10
0
 public IActionResult Delete([FromBody] BodyExerciseKey key)
 {
     try
     {
         _bodyExercisesService.DeleteBodyExercise(key);
         return(new OkObjectResult(true)); // bool
     }
     catch (Exception exception)
     {
         return(BadRequest(new WebApiException("Error", exception)));
     }
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Delete data in database
        /// </summary>
        /// <param name="key">Primary Key</param>
        public void Delete(BodyExerciseKey key)
        {
            if (key == null || key.Id == 0)
                return;

            var bodyExerciseRow = _dbContext.BodyExercise.Where(m => m.Id == key.Id).FirstOrDefault();
            if (bodyExerciseRow != null)
            {
                _dbContext.BodyExercise.Remove(bodyExerciseRow);
                _dbContext.SaveChanges();
            }
        }
Ejemplo n.º 12
0
 public IActionResult Get(BodyExerciseKey key)
 {
     try
     {
         var result = _bodyExercisesService.GetBodyExercise(key);
         return(new OkObjectResult(result)); // BodyExercise
     }
     catch (Exception exception)
     {
         return(BadRequest(new WebApiException("Error", exception)));
     }
 }
Ejemplo n.º 13
0
        public BodyExercise GetBodyExercise(BodyExerciseKey key)
        {
            BodyExercise bodyExercise = null;
            string       cacheKey     = key == null ? "BodyExerciseKey_null" : key.GetCacheKey();

            if (key != null && !TryGetCacheData(cacheKey, out bodyExercise, _cacheName))
            {
                bodyExercise = GetBodyExerciseManager().GetBodyExercise(key);
                SetCacheData(_cacheName, cacheKey, bodyExercise);
            }
            return(bodyExercise);
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Delete data in database
        /// </summary>
        /// <param name="key">Primary Key</param>
        public void Delete(BodyExerciseKey key)
        {
            if (key == null || key.Id == 0)
            {
                return;
            }

            var bodyExerciseRow = _dbContext.Table <BodyExerciseRow>().Where(m => m.Id == key.Id).FirstOrDefault();

            if (bodyExerciseRow != null)
            {
                _dbContext.Delete(bodyExerciseRow);
            }
        }
        /// <summary>
        /// Delete data in database
        /// </summary>
        /// <param name="key">Primary Key</param>
        public void Delete(BodyExerciseKey key)
        {
            if (key == null || key.Id == 0)
            {
                return;
            }

            var bodyExerciseRow = _dbContext.BodyExercise.Where(m => m.Id == key.Id).FirstOrDefault();

            if (bodyExerciseRow != null)
            {
                _dbContext.BodyExercise.Remove(bodyExerciseRow);
                _dbContext.SaveChanges();
            }
        }
        /// <summary>
        /// Get data in database
        /// </summary>
        /// <param name="key">Primary Key</param>
        /// <returns>read data</returns>
        public BodyExercise Get(BodyExerciseKey key)
        {
            if (key == null || key.Id == 0)
            {
                return(null);
            }

            var bodyExerciseRow = _dbContext.BodyExercise.Where(m => m.Id == key.Id).FirstOrDefault();

            if (bodyExerciseRow != null)
            {
                return(BodyExerciseTransformer.ToBean(bodyExerciseRow));
            }
            return(null);
        }
Ejemplo n.º 17
0
 public IActionResult Delete(int id)
 {
     if (id > 0)
     {
         var key = new BodyExerciseKey()
         {
             Id = id
         };
         var bodyExercise = _bodyExercisesService.GetBodyExercise(key);
         if (bodyExercise != null)
         {
             _bodyExercisesService.DeleteBodyExercise(key);
             DeleteImage(bodyExercise.ImageName);
         }
     }
     return(RedirectToAction("Index"));
 }
Ejemplo n.º 18
0
 public void DeleteBodyExercise(BodyExerciseKey key)
 {
     BeginTransaction();
     try
     {
         GetBodyExerciseManager().Delete(key);
         CommitTransaction();
         //invalidate cache
         InvalidateCache(_cacheName);
     }
     catch
     {
         RollbackTransaction();
         throw;
     }
     finally
     {
         EndTransaction();
     }
 }
Ejemplo n.º 19
0
 public void DeleteBodyExercise(BodyExerciseKey key)
 {
     BeginTransaction();
     try
     {
         GetBodyExerciseManager().DeleteBodyExercise(key);
         CommitTransaction();
         //invalidate cache
         InvalidateCache(_cacheName);
     }
     catch (Exception exception)
     {
         _logger.LogCritical("Unable to delete bodyexercise", exception);
         RollbackTransaction();
         throw exception;
     }
     finally
     {
         EndTransaction();
     }
 }
Ejemplo n.º 20
0
 public void DeleteBodyExercise(BodyExerciseKey key)
 {
     BeginTransaction();
     try
     {
         GetBodyExerciseManager().DeleteBodyExercise(key);
         CommitTransaction();
         //invalidate cache
         InvalidateCache(_cacheName);
     }
     catch (Exception exception)
     {
         _logger.LogCritical("Unable to delete bodyexercise", exception);
         RollbackTransaction();
         throw exception;
     }
     finally
     {
         EndTransaction();
     }
 }
Ejemplo n.º 21
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 = _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");
                }
            }

            int muscleId = 0;
            if (bodyExerciseViewModel != null)
                muscleId = bodyExerciseViewModel.MuscleId;

            ViewBag.Muscles = ControllerUtils.CreateSelectMuscleItemList(_musclesService.FindMuscles(), muscleId);

            return View(bodyExerciseViewModel);
        }
Ejemplo n.º 22
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.ImageUrl = ImageUtils.GetImageUrl(_env.WebRootPath, "bodyexercises", bodyExercise.ImageName);

                    ViewBag.Muscles = ControllerUtils.CreateSelectMuscleItemList(_musclesService.FindMuscles(), bodyExercise.MuscleId);

                    return View(bodyExerciseViewModel);
                }
            }
            return RedirectToAction("Index");
        }
Ejemplo n.º 23
0
 public IActionResult Delete(int id)
 {
     if (id > 0)
     {
         var key = new BodyExerciseKey() { Id = id };
         var bodyExercise = _bodyExercisesService.GetBodyExercise(key);
         if (bodyExercise != null)
         {
             _bodyExercisesService.DeleteBodyExercise(key);
             DeleteImage(bodyExercise.ImageName);
         }
     }
     return RedirectToAction("Index");
 }
Ejemplo n.º 24
0
 public IActionResult Get(BodyExerciseKey key)
 {
     try
     {
         var result = _bodyExercisesService.GetBodyExercise(key);
         return new OkObjectResult(result); // BodyExercise
     }
     catch (Exception exception)
     {
         return BadRequest(new WebApiException("Error", exception));
     }
 }
Ejemplo n.º 25
0
        public static async Task <BodyExercise> GetAsync(WebApiWrapper webApiWrapper, string userId, Cookie cookie, BodyExerciseKey key)
        {
            Dictionary <string, string> datas = new Dictionary <string, string>();

            datas.Add("Id", key.Id.ToString());
            return(await webApiWrapper.HttpClientPoolManager.GetAsync <BodyExercise>(userId, cookie, _baseUrl + "Get", datas));
        }
Ejemplo n.º 26
0
 public BodyExercise GetBodyExercise(BodyExerciseKey key)
 {
     BodyExercise result = _bodyExerciseModule.Get(key);
     CompleteTranslation(result);
     return result;
 }
Ejemplo n.º 27
0
 public BodyExercise GetBodyExercise(BodyExerciseKey key)
 {
     BodyExercise bodyExercise = null;
     string cacheKey = key == null ? "BodyExerciseKey_null" : key.GetCacheKey();
     if (key != null && !TryGetCacheData(cacheKey, out bodyExercise))
     {
         bodyExercise = GetBodyExerciseManager().GetBodyExercise(key);
         SetCacheData(_cacheName, cacheKey, bodyExercise);
     }
     return bodyExercise;
 }
Ejemplo n.º 28
0
 public static async Task <bool> DeleteAsync(WebApiWrapper webApiWrapper, string userId, Cookie cookie, BodyExerciseKey key)
 {
     return(await webApiWrapper.HttpClientPoolManager.PostAsync <BodyExerciseKey, bool>(userId, cookie, _baseUrl + "Delete", key));
 }
Ejemplo n.º 29
0
        /// <summary>
        /// Get data in database
        /// </summary>
        /// <param name="key">Primary Key</param>
        /// <returns>read data</returns>
        public BodyExercise Get(BodyExerciseKey key)
        {
            if (key == null || key.Id == 0)
                return null;

            var bodyExerciseRow = _dbContext.BodyExercise.Where(m => m.Id == key.Id).FirstOrDefault();
            if (bodyExerciseRow != null)
            {
                return BodyExerciseTransformer.ToBean(bodyExerciseRow);
            }
            return null;
        }