Exemplo n.º 1
0
        public Int32 ExcerciseCategoryWrite(ExerciseCategory mainExcercise, SQLiteConnection db)
        {
            // var maxPK = db.Table<ExcerciseCategory>().OrderByDescending(c => c.ExerciseCategoryID).FirstOrDefault();

            ExerciseCategory exc;

            //if (maxPK != null)

            //{

            //    exc = new ExcerciseCategory()
            //    {
            //        ExerciseCategoryID = (maxPK == null ? 1 : (maxPK.ExerciseCategoryID + 1)),
            //        Name = mainExcercise.Name,
            //        Description = mainExcercise.Description

            //    };
            //}
            //else
            //{
            //db.CreateTable<ExcerciseCategory>();
            exc = new ExerciseCategory()
            {
                ExerciseCategoryID = 1,
                Name        = mainExcercise.Name,
                Description = mainExcercise.Description
            };
            //  }
            return(db.Insert(exc));
        }
Exemplo n.º 2
0
        //[Authorize]
        public async Task <IActionResult> AddExercise(ExerciseForCreationDto exerciseForCreationDto)
        {
            var exerciseToReturn = _mapper.Map <Exercise>(exerciseForCreationDto);

            exerciseToReturn.Subject = await _subjectRepository.GetSubjectByIdAsync(exerciseForCreationDto.SubjectId);

            _exerciseRepository.Add <Exercise>(exerciseToReturn);
            await _exerciseCategoriesRepository.SaveAll();

            // Add categories to exercise
            var id = exerciseToReturn.Id;

            foreach (var categoryId in exerciseForCreationDto.CategoriesIds)
            {
                var exerciseCategory = new ExerciseCategory {
                    ExerciseId = id,
                    CategoryId = categoryId
                };
                _exerciseCategoriesRepository.Add <ExerciseCategory>(exerciseCategory);
            }

            if (await _exerciseCategoriesRepository.SaveAll())
            {
                var exerciseToReturnDto = _mapper.Map <ExerciseDto>(exerciseToReturn);
                return(CreatedAtRoute("GetExercise", new { exerciseToReturn.Id }, exerciseToReturnDto));
            }

            throw new Exception("Nie udało się dodać zadania");
        }
Exemplo n.º 3
0
 public MaxWeightCalculator(IDataManager storage)
 {
     this.storage = storage;
     weight       = 100;
     repeats      = 1;
     exercise     = ExerciseCategory.BenchPress;
     Load();
 }
 public PercentageCalculator(IDataManager storage)
 {
     this.storage = storage;
     weight       = 100;
     percentage   = 100;
     exercise     = ExerciseCategory.BenchPress;
     Load();
 }
Exemplo n.º 5
0
        public void Post(string exerciseCategoryName)
        {
            var exerciseCategoryEntity = new ExerciseCategory
            {
                Name = exerciseCategoryName
            };

            _exerciseCategoryRepository.Create(exerciseCategoryEntity);
        }
        private void button1_Click(object sender, EventArgs e)
        {
            string catString = tabControl1.SelectedTab.Name;
            //https://stackoverflow.com/questions/23563960/how-to-get-enum-value-by-string-or-int
            ExerciseCategory category = (ExerciseCategory)Enum.Parse(typeof(ExerciseCategory), catString);
            var show = new ShowExerciseForm(new Exercise(category, "My new exercise"), book, this);

            show.NameImmune(true);
            show.Show();
        }
Exemplo n.º 7
0
        public IActionResult Index()
        {
            string exerciseCategoryUrl = $"{Constants.BaseWorkoutApiUrl}/exercisecategory/?format=json&language=2";

            string jsonReponse = WorkoutApiHelper.GetJsonStringFromApi(exerciseCategoryUrl);

            ExerciseCategory exerciseCategory = ExerciseCategory.FromJson(jsonReponse);

            var homeViewModel = new HomeViewModel {
                ExerciseCategoryList = exerciseCategory
            };

            return(View(homeViewModel));
        }
Exemplo n.º 8
0
        public static string ExerciseDescription(ExerciseCategory exercise)
        {
            switch (exercise)
            {
            case ExerciseCategory.BenchPress:
                return("Bench Press");

            case ExerciseCategory.Deadlift:
                return("Deadlift");

            case ExerciseCategory.Squat:
                return("Squat");

            default:
                return("");
            }
        }
Exemplo n.º 9
0
        public IActionResult Add(AddCategoryViewModel addCategoryViewModel)
        {
            if (ModelState.IsValid)
            {
                // Add the new cheese to my existing cheeses
                ExerciseCategory newCategory = new ExerciseCategory
                {
                    Name = addCategoryViewModel.Name,
                };

                context.Categories.Add(newCategory);
                context.SaveChanges();

                return(Redirect("/Category"));
            }

            return(View(addCategoryViewModel));
        }
Exemplo n.º 10
0
        public IActionResult Add(AddExerciseViewModel addExerciseViewModel)
        {
            if (ModelState.IsValid)
            {
                ExerciseCategory newExerciseCategory =
                    context.Categories.Single(c => c.ID == addExerciseViewModel.CategoryID);
                Exercise newExercise = new Exercise
                {
                    Name     = addExerciseViewModel.Name,
                    Duration = addExerciseViewModel.Duration,
                    Category = newExerciseCategory
                };

                context.Exercises.Add(newExercise);
                context.SaveChanges();

                return(Redirect("/Exercise"));
            }
            return(View(addExerciseViewModel));
        }
Exemplo n.º 11
0
        //[Authorize]
        public async Task <IActionResult> EditExercise(int id, ExerciseForCreationDto exerciseForCreationDto)
        {
            var exerciseToEdit = await _exerciseRepository.GetExerciseByIdAsync(id);

            var exerciseToReturn = _mapper.Map(exerciseForCreationDto, exerciseToEdit);

            exerciseToReturn.Subject = await _subjectRepository.GetSubjectByIdAsync(exerciseForCreationDto.SubjectId);

            _exerciseRepository.Edit(exerciseToReturn);

            await _exerciseRepository.SaveAll();

            // delete exercise categories
            var exerciseCategories = await _exerciseCategoriesRepository.GetExerciseCategoriesForExerciseAsync(id);

            foreach (var exerciseCategory in exerciseCategories)
            {
                _exerciseCategoriesRepository.Delete(exerciseCategory);
            }
            await _exerciseCategoriesRepository.SaveAll();


            // Edit exercise categories
            foreach (var categoryId in exerciseForCreationDto.CategoriesIds)
            {
                var exerciseCategory = new ExerciseCategory {
                    ExerciseId = id,
                    CategoryId = categoryId
                };
                _exerciseCategoriesRepository.Add(exerciseCategory);
            }

            if (await _exerciseCategoriesRepository.SaveAll())
            {
                return(NoContent());
            }
            return(BadRequest("Nie udało się edytować zadania"));
        }
 public Exercise(ExerciseCategory category, string name, int sets, int timesInSet) : this(category, name)
 {
     this.sets       = sets;
     this.timesInSet = timesInSet;
 }
 public Exercise(ExerciseCategory category, string name)
 {
     this.category       = category;
     this.NameOfExercise = name;
     this.Description    = "No description yet";
 }
        public List <Exercise> FindByCategory(ExerciseCategory category)
        {
            List <Exercise> res = Exercises.Where(ex => ex.category == category).ToList();

            return(res);
        }