Example #1
0
        public bool AtualizarAnuncio(Anuncio anuncio)
        {
            try
            {
                if (!VerificarEntidade(anuncio))
                {
                    return(false);
                }

                var anuncioAtual = _anuncioRepository.Listar().FirstOrDefault(a => a.Id == anuncio.Id);

                if (anuncioAtual == null)
                {
                    Notificar(DomainNotification.DomainNotificationFactory.Criar(DomainNotificationType.BusinessError,
                                                                                 "Nenhum anuncio encontrado para atualização."));
                    return(false);
                }

                anuncioAtual.Marca         = anuncio.Marca;
                anuncioAtual.Modelo        = anuncio.Modelo;
                anuncioAtual.Versao        = anuncio.Versao;
                anuncioAtual.Ano           = anuncio.Ano;
                anuncioAtual.Quilometragem = anuncio.Quilometragem;
                anuncioAtual.Observacao    = anuncio.Observacao;

                _anuncioRepository.Alterar(anuncioAtual);
                return(Commit("Ocorreu um erro ao tentar atualizar o anúncio."));
            }
            catch (Exception ex)
            {
                NotificarException(DomainNotificationType.TechnicalError, ex);
                return(false);
            }
        }
        public async Task Executar(int id, Anuncio anuncio)
        {
            var dadosDoAnuncio = await _anuncioRepository.BuscarPorId(id);

            dadosDoAnuncio.AtualizarDadosDoAnuncio(anuncio.Marca, anuncio.Modelo, anuncio.Versao, anuncio.Ano, anuncio.Quilometragem, anuncio.Observacao);

            await _anuncioRepository.Alterar(dadosDoAnuncio);
        }