예제 #1
0
        //[Authorize(Policy = "PodeGravarEmpresa")]
        public IActionResult Delete(string id)
        {
            var command = new ExcluirEmpresaCommand(id);

            var result = _handler.Handle(command);

            return(Response(result, _handler.Notifications));
        }
예제 #2
0
        public ICommandResult Handle(ExcluirEmpresaCommand command)
        {
            //Verificar se a empresa existe
            var registro = _empresaRepository.Buscar(e => e.CodEmpresa == command.CodEmpresa).FirstOrDefault();



            if (registro == null)
            {
                return(new CommandResult(false, "Não foi possível realizar esta operação. O cód. informado não existe"));
            }



            var relacionamento = _empresaRepository.ExisteRelacionamento(nameof(command.CodEmpresa).ToString(), command.CodEmpresa.ToString());

            if (relacionamento)
            {
                return(new CommandResult(false, "Não foi possível realizar esta operação. Empresa possui vínculo com outras entidades da APP"));
            }



            //Auditoria
            //var auditoria = new LogAuditoria("Cadastro", registro.GetType().Name, EAcao.Excluir, registro.GetType().Namespace, JsonConvert.SerializeObject(registro));



            // Agrupar as Validações
            AddNotifications(registro);



            // Checar as notificações
            if (Invalid)
            {
                return(new CommandResult(false, "Não foi possível realizar esta operação"));
            }


            // Salvar as Informações
            _empresaRepository.RemoverString(command.CodEmpresa);



            //_auditoriaRepository.Adicionar(auditoria);



            // Retornar informações
            return(new CommandResult(true, "Operação realizada com sucesso"));
        }
예제 #3
0
        public void Handle(ExcluirEmpresaCommand cmd)
        {
            Empresa empresa = EmpresaExistente(cmd.Id, cmd.MessageType);

            if (empresa != null)
            {
                _repository.Remover(cmd.Id);

                if (Commit())
                {
                    _mediator.PublicarEvento(new EmpresaExcluidaEvent(empresa.Id));
                }
            }
        }
예제 #4
0
        public ICommandResult Handle(ExcluirEmpresaCommand command)
        {
            if (!command.IsValidCommand())
            {
                return(new CommandResult(false, "Por favor, corrigir os campos abaixo", command.Notifications));
            }

            var empresa = _repository.Empresa(command.Id);

            if (empresa == null)
            {
                return(new CommandResult(false, $"A empresa não existe na base de dados. Código informado: { command.Id }", new { }));
            }

            _repository.Excluir(command.Id);

            return(new CommandResult(true, "Empresa excluída com sucesso", new
            {
                Id = empresa.Id,
                Fantasia = empresa.Fantasia
            }));
        }
예제 #5
0
        public ICommandResult Excluir([FromBody] ExcluirEmpresaCommand command)
        {
            var result = (CommandResult)_handler.Handle(command);

            return(result);
        }
예제 #6
0
        public async Task <ValidationResultModel <CommandResult> > Excluir([FromRoute] ExcluirEmpresaCommand command)
        {
            var cResult = await handler.SendCommand <ExcluirEmpresaCommand, CommandResult>(command);

            return(await _validationResultBuilder.BuildAsync(cResult));
        }