Skip to content

Instantly share code, notes, and snippets.

@CoskunKurtuldu
Created August 31, 2020 14:05
Show Gist options
  • Save CoskunKurtuldu/89b3eb7e9f4b7c554eef0e2176a3f15c to your computer and use it in GitHub Desktop.
Save CoskunKurtuldu/89b3eb7e9f4b7c554eef0e2176a3f15c to your computer and use it in GitHub Desktop.
[HttpPost("Roles")]
public async Task<IActionResult> CreateRole(string roleName)
{
if(string.IsNullOrWhiteSpace(roleName))
{
return BadRequest("Role name should be provided.");
}
var newRole = new Role
{
Name = roleName
};
var roleResult = await _roleManager.CreateAsync(newRole);
if (roleResult.Succeeded)
{
return Ok();
}
return Problem(roleResult.Errors.First().Description, null, 500);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment