예제 #1
0
        public async Task Execute(ConsultarAnuncioInput consultarAnuncioInput)
        {
            if (consultarAnuncioInput.Id == 0)
            {
                _outputHandler.NotFound($"Codigo do anuncio inválido.");
                return;
            }

            IAnuncio anuncio     = null;
            string   anuncioJson = _cache.GetString($"Anuncio:{consultarAnuncioInput.Id}");

            if (anuncioJson == null)
            {
                anuncio = await _anuncioRepository.Get(consultarAnuncioInput.Id);
            }

            if (anuncio == null)
            {
                _outputHandler.NotFound($"Anuncio não encontrado.");
                return;
            }

            if (anuncioJson == null)
            {
                anuncioJson = JsonConvert.SerializeObject(anuncio);
                DistributedCacheEntryOptions opcoesCache = new DistributedCacheEntryOptions();
                opcoesCache.SetAbsoluteExpiration(TimeSpan.FromMinutes(5));
                _cache.SetString($"Anuncio:{anuncio.ID}", anuncioJson, opcoesCache);
            }

            ConsultarAnuncioOutput consultarAnuncioOutput = new ConsultarAnuncioOutput(anuncio);

            _outputHandler.Default(consultarAnuncioOutput);
        }
예제 #2
0
        public async Task Add(IAnuncio anuncio)
        {
            await _context.Anuncios.AddAsync((Anuncio)anuncio);

            await _context.SaveChangesAsync();

            await Task.CompletedTask;
        }
예제 #3
0
 public AtualizarAnuncioOutput(IAnuncio anuncio)
 {
     Anuncio = anuncio;
 }
예제 #4
0
 public ConsultarAnuncioOutput(IAnuncio anuncio)
 {
     Anuncio = anuncio;
 }
예제 #5
0
 public IncluirAnuncioOutput(IAnuncio anuncio)
 {
     Anuncio = anuncio;
 }
예제 #6
0
        //public async Task Delete(IAnuncio anuncio)
        //{
        //    string deleteSQL = @"DELETE FROM tb_anunciowebmotors WHERE id = @Id;";
        //    var id = new SqlParameter("@Id", anuncio.ID);
        //    int affectedRows = await _context.Database.ExecuteSqlCommandAsync(deleteSQL, id);
        //}

        // Alterado para EFCore para poder realizar teste unitario com banco em memoria
        public async Task Delete(IAnuncio anuncio)
        {
            _context.Anuncios.Remove((Anuncio)anuncio);
            await _context.SaveChangesAsync();
        }
예제 #7
0
 public async Task Update(IAnuncio anuncio)
 {
     _context.Anuncios.Update((Anuncio)anuncio);
     await _context.SaveChangesAsync();
 }
예제 #8
0
 public AnuncioController(IAnuncio ianuncio, IMapper mapper)
 {
     _ianuncio = ianuncio;
     _mapper   = mapper;
 }
예제 #9
0
 public AppAnuncio(IAnuncio IAnuncio)
 {
     _IAnuncio = IAnuncio;
 }