public ICommandResult Handle(UsuarioDeleteCommand command, IServiceProvider service) { //Regras e Fluxo command.Validate(); if (command.Invalid) { AddNotifications(command); var message = "Não foi possível deletar o registro. \n"; foreach (var notification in command.Notifications) { message += $"{notification.Property} - {notification.Message}" + "\n"; } return(new CommandResult <bool>(false, message)); } var usuarioRepository = (IUsuarioRepository)service.GetService(typeof(IUsuarioRepository)); var result = usuarioRepository.Delete(command.Id); if (!result) { return(new CommandResult <bool>(false, "Registro não encontrado.")); } return(new CommandResult <bool>(true, "Registro excluído com sucesso.")); }
public async Task <IActionResult> Delete(int id, [FromBody] UsuarioDeleteCommand command) { command.Codigo = id; var response = await _mediator.Send(command); return(Ok(response)); }
public Result Validar(UsuarioDeleteCommand command) { ValidationResult results = _usuarioDeleteCommandValidators.Validate(command); if (!results.IsValid) { _result.Invalidar(); _result.AdicionarMensagem(results.Errors); } if (!Existir(command.Codigo)) { _result.Invalidar(); _result.AdicionarMensagem("Banco", "Usuario não encontrado"); } if (_result.Valido) { _result.AdicionarMensagem("Suceeso", "Comando executado com sucesso"); } _result.AdicionarObjeto(command); return(_result); }
public ActionResult Delete(int id) { try { var handler = new UsuarioHandler(); var command = new UsuarioDeleteCommand() { Id = id }; var result = (CommandResult <bool>)handler.Handle(command, Service); return(Ok(result)); } catch (ArgumentNullException e) { return(NotFound(new CommandResult <bool>() { Message = e.Message })); } catch (Exception e) { return(NotFound(new CommandResult <bool>() { Message = e.Message })); } }
public void DeleteSucesso() { var handler = new UsuarioHandler(); var command = new UsuarioDeleteCommand() { Id = 1 }; var result = (CommandResult <bool>)handler.Handle(command, Service); Assert.AreEqual(true, result.Success); }
public void DeleteRegistroInexistenteErro() { var handler = new UsuarioHandler(); var command = new UsuarioDeleteCommand() { Id = 0 }; var result = (CommandResult <bool>)handler.Handle(command, Service); Assert.AreEqual(false, result.Success); }
public async Task <Result> Handle(UsuarioDeleteCommand command, CancellationToken cancellationToken) { var result = _usuarioService.Validar(command); if (!result.Valido) { return(await Task.FromResult(result)); } var domain = UsuarioFactory.Excluir(command); domain.Excluir(); _usuarioRepository.Alterar(_usuarioService.ToEntity(domain)); _unitOfWork.SaveChanges(); return(await Task.FromResult(result)); }
public IHttpActionResult Eliminar(UsuarioDeleteCommand command) { command.usuario.Id = GetUsuarioLogueado().Id; _result = _commandDispatcher.Dispatch(command); return(Ok(_result)); }
public static UsuarioDomain Excluir(UsuarioDeleteCommand command) { return(UpdateBase(command, command.Codigo)); }