Пример #1
0
        public async Task <IActionResult> Create([FromForm] WorkoutViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            await _workoutService.CreateAsync(viewModel);

            return(RedirectToAction(nameof(Index)));
        }
Пример #2
0
        public async Task <IActionResult> CreateAsync([FromBody] Workout workout)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var createdWorkout = await _workoutService.CreateAsync(workout);

            return(CreatedAtAction(
                       nameof(ReadOneAsync),
                       new { id = createdWorkout.Id },
                       createdWorkout));
        }