You've tagged the question as ASP.NET Core; I'm assuming you're using at least v2.1?
Change the action return type to
ActionResult<UserLogins>
, which will let you return either the newly created user, or an HTTP status code.
[HttpPost]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status409Conflict)]
public ActionResult<UserLogins> Post([FromBody] UserLogins userDto)
{
if (_services.CheckUserName(userDto.UserName))
{
return StatusCode(409, $"User '{userDto.UserName}' already exists.");
}
return _services.Create(userDto);
}
Controller action return types in ASP.NET Core web API | Microsoft Docs[
^]