예제 #1
0
        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));
            }
        }
예제 #2
0
 public async Task <OperationResultResponse <Guid> > Create(
     [FromServices] ICreateRoleCommand command,
     [FromBody] CreateRoleRequest role)
 {
     return(await command.ExecuteAsync(role));
 }