示例#1
0
        public IActionResult PostExercise(Guid id, [FromBody] ExerciseModel exercise)
        {
            var newExercise = homeworks.AddExercise(id, ExerciseModel.ToEntity(exercise));

            if (newExercise == null)
            {
                return(BadRequest());
            }
            return(CreatedAtRoute("GetExercise", new { id = newExercise.Id }, ExerciseModel.ToModel(newExercise)));
        }
示例#2
0
        public async Task <IActionResult> Put([FromBody] ExerciseModel model)
        {
            try
            {
                Console.WriteLine("Getting excercises");

                if (model == null)
                {
                    Console.WriteLine("bad request");
                    return(BadRequest("Введите данные"));
                }

                await _exerciseService.AddExercise(model.ToEntity());

                return(StatusCode(StatusCodes.Status201Created));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                return(StatusCode(StatusCodes.Status500InternalServerError, "Произошла ошибка, обратитесь в службу поддержки!"));
            }
        }