public IActionResult Post( [FromBody] RoleDto dto, [FromServices] ICreateRoleCommand command) { _executor.ExecuteCommand(command, dto); return(StatusCode(StatusCodes.Status201Created)); }
public async Task <ActionResult> Create([FromBody] RoleCreateModel roleModel, [FromServices] IValidatorFactory validatorFactory, [FromServices] ICreateRoleCommand createRoleCommand) { try { if (roleModel == null) { return(BadRequest()); } IValidator validator = validatorFactory.Create(); string roleId = await createRoleCommand.Execute(roleModel, validator); if (validator.HasErrors) { return(BadRequest(validator.Errors)); } else { return(Created("", roleId)); } } catch (Exception ex) { //Log error _logger.LogError("RoleController.Create", "Exception was thrown.", new { RoleModel = roleModel, Exception = ex }); return(BadRequest(new Message("Something bad happened. Try again."))); } }
public RolesController(IGetRolesCommand searchRolesCommand, IGetRoleCommand getOneRoleCommand, ICreateRoleCommand createRoleCommand, IEditRoleCommand editRoleCommand, IDeleteRoleCommand deleteRoleCommand) { _searchRolesCommand = searchRolesCommand; _getOneRoleCommand = getOneRoleCommand; _createRoleCommand = createRoleCommand; _editRoleCommand = editRoleCommand; _deleteRoleCommand = deleteRoleCommand; }
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 void Post([FromBody] RoleDto dto, [FromServices] ICreateRoleCommand command) { command.Execute(dto); }
public void Post([FromBody] RoleDto dto, [FromServices] ICreateRoleCommand command) { executor.ExecuteCommand(command, dto); }
public RolesController(ICreateRoleCommand createRole, IGetRolesCommand getRoles) { _createRole = createRole; _getRoles = getRoles; }
public IActionResult Post([FromBody] RoleDto dto, [FromServices] ICreateRoleCommand command) { executor.ExecuteCommand(command, dto); return(Ok(new { StatusCode = HttpStatusCode.OK, Message = "New Role Created" })); }
public IActionResult Post([FromBody] RoleDTO dto, [FromServices] ICreateRoleCommand command) { _executor.ExecuteCommand(command, dto); return(NoContent()); }
public async Task <OperationResultResponse <Guid> > Create( [FromServices] ICreateRoleCommand command, [FromBody] CreateRoleRequest role) { return(await command.ExecuteAsync(role)); }
public void Post([FromBody] RoleDto dto, [FromServices] ICreateRoleCommand command, [FromServices] CreateRoleValidator validator) { _executor.ExecuteCommand(command, dto); }