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."));
        }
示例#2
0
        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);
        }
示例#4
0
 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
         }));
     }
 }
示例#5
0
        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);
        }
示例#6
0
        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));
        }
示例#8
0
 public IHttpActionResult Eliminar(UsuarioDeleteCommand command)
 {
     command.usuario.Id = GetUsuarioLogueado().Id;
     _result            = _commandDispatcher.Dispatch(command);
     return(Ok(_result));
 }
示例#9
0
 public static UsuarioDomain Excluir(UsuarioDeleteCommand command)
 {
     return(UpdateBase(command, command.Codigo));
 }