コード例 #1
0
        public IActionResult Post([FromBody] CreateTrainerDto dto)
        {
            var trainer = _trainerService.AddNewTrainer(dto);

            if (trainer == null)
            {
                return(BadRequest("Trainer with such phone already exists!"));
            }

            return(CreatedAtAction(nameof(GetTrainer), new { id = trainer.Id }, trainer));
        }
コード例 #2
0
        public async Task <ActionResult <Trainer> > AddNew(Trainer newTrainer)
        {
            try
            {
                var result = await _trainersService.AddNewTrainer(newTrainer);

                return(Ok(result));
            }
            catch (InvalidOperationException ex)
            {
                return(NotFound(ex.Message));
            }
        }