예제 #1
0
        private async Task <Retorno> Excluir(EscritorDTO command)
        {
            if (command.Invalid)
            {
                return(new Retorno(false, "Dados Inválidos!", command.Notifications));
            }

            return(await _repository.Excluir(command.Id));
        }
예제 #2
0
        private async Task <Retorno> Cadastrar(EscritorDTO command)
        {
            command.Validate();
            if (command.Invalid)
            {
                return(new Retorno(false, "Dados Inválidos!", command.Notifications));
            }

            var escritor = new Escritor
            {
                Nome = command.Nome
            };

            return(await _repository.Cadastrar(escritor));
        }
        public async Task <IActionResult> Put([FromBody] EscritorDTO escritor)
        {
            try
            {
                var retorno = (Retorno)await _rep.Persistir(escritor, ELogin.ATUALIZAR);

                if (retorno.Sucesso == false)
                {
                    return(BadRequest(retorno));
                }

                return(Ok(retorno));
            }
            catch (Exception ex)
            {
                GerarLog("Erro ao Atualizar o escritores", ex: ex);
                return(StatusCode(500, ex.ToString()));
            }
        }
예제 #4
0
        public async Task <ICommandResult> Persistir(EscritorDTO command, ELogin acoes)
        {
            var retorno = new Retorno();

            switch (acoes)
            {
            case ELogin.CADASTRAR:
                retorno = await Cadastrar(command);

                break;

            case ELogin.ATUALIZAR:
                retorno = await Atualizar(command);

                break;

            case ELogin.EXCLUIR:
                retorno = await Excluir(command);

                break;
            }

            return(retorno);
        }