You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In your API, all your controller have to inherit from the Controller class that also inherit from the abstract ControllerBase class. (see aspnet core source file ControllerBase.cs )
The ControllerBase already contains all you need to return automatically the status codes from the given methods like Ok(...), BadRequest(...), NotFound(...), etc.
ex:
[HttpGet]
[Route("{id}")]
public IActionResult GetUser(Guid id)
{
if (id == Guid.Empty)
{
return this.BadRequest();
}
if (!this.UsersServices.UserExists(id))
{
return this.NotFound($"User with id {id} not found");
}
var user = this.UsersServices.GetUserById(id);
var userDto = Mapper.Map<UserDto>(user);
return this.Ok(userDto);
}