public async Task <IActionResult> CreateRole(CreateRoleRequest role, [FromServices] ICreateRoleCommand command) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { RoleResponse response = await command.ExecuteAsync(role); return(CreatedAtRoute("GetSingleRole", new { roleId = response.Id }, response)); } catch (CannotCreateRoleExeption exception) { foreach (var error in exception.Errors) { ModelState.AddModelError(exception.Message, error.Description); } return(BadRequest(ModelState)); } }
public async Task <OperationResultResponse <Guid> > Create( [FromServices] ICreateRoleCommand command, [FromBody] CreateRoleRequest role) { return(await command.ExecuteAsync(role)); }