Пример #1
0
        public async Task UpdateExercise(int exerciseId, MakeOrUpdateExerciseVM makeOrUpdateExerciseVM)
        {
            var exercise = await GetExerciseById(exerciseId);

            exercise.Title       = makeOrUpdateExerciseVM.Title;
            exercise.Description = makeOrUpdateExerciseVM.Description;
            exercise.MaxPoints   = makeOrUpdateExerciseVM.MaxPoints;
            await context.SaveChangesAsync();
        }
Пример #2
0
        public async Task <IActionResult> UpdateExercise(int ExerciseId)
        {
            MakeOrUpdateExerciseVM makeOrUpdateExerciseVM = new MakeOrUpdateExerciseVM();
            var exercise = await exerciseRepository.GetExerciseById(ExerciseId);

            makeOrUpdateExerciseVM.Description = exercise.Description;
            makeOrUpdateExerciseVM.Title       = exercise.Title;
            makeOrUpdateExerciseVM.MaxPoints   = exercise.MaxPoints;
            return(View(makeOrUpdateExerciseVM));
        }
Пример #3
0
        public async Task <int> AddExercise(MakeOrUpdateExerciseVM makeExerciseVM)
        {
            var userId      = userService.GetUserId();
            var User        = context.Users.FirstOrDefault(x => x.Id == userId);
            var newExercise = new Exercise
            {
                Title       = makeExerciseVM.Title,
                Description = makeExerciseVM.Description,
                CreatedAt   = DateTime.Now,
                MaxPoints   = makeExerciseVM.MaxPoints,
                Creator     = User,
                CreatorId   = userId,
            };
            await context.Exercises.AddAsync(newExercise);

            await context.SaveChangesAsync();

            return(newExercise.ExerciseId);
        }
Пример #4
0
        public async Task <IActionResult> UpdateExercise(int ExerciseId, MakeOrUpdateExerciseVM makeOrUpdateExerciseVM)
        {
            await exerciseRepository.UpdateExercise(ExerciseId, makeOrUpdateExerciseVM);

            return(RedirectToAction("Index"));
        }
Пример #5
0
        public async Task <IActionResult> AddExercise(MakeOrUpdateExerciseVM makeExerciseVM)
        {
            int id = await exerciseRepository.AddExercise(makeExerciseVM);

            return(RedirectToAction("Index"));
        }