コード例 #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Marca,Modelo,versao, Observacao, Ano, Quilometragem")] AnuncioWebmotors anuncioWebmotors)
        {
            if (id != anuncioWebmotors.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(anuncioWebmotors);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!AnuncioWebmotorsExists(anuncioWebmotors.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(anuncioWebmotors));
        }
コード例 #2
0
        public async Task <ActionResult <AnuncioWebmotors> > PostAnuncioWebmotors(AnuncioWebmotors anuncioWebmotors)
        {
            _context.AnuncioWebmotors.Add(anuncioWebmotors);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetAnuncioWebmotors", new { id = anuncioWebmotors.ID }, anuncioWebmotors));
        }
コード例 #3
0
        public async Task <IActionResult> PutAnuncioWebmotors(int id, AnuncioWebmotors anuncioWebmotors)
        {
            if (id != anuncioWebmotors.ID)
            {
                return(BadRequest());
            }

            _context.Entry(anuncioWebmotors).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!AnuncioWebmotorsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
コード例 #4
0
        // GET: Anuncio/Delete/5
        public ActionResult Delete(int id)
        {
            AnuncioWebmotors anuncio = new AnuncioWebmotors();

            anuncio = anuncioRepo.GetAnuncioById(id);
            return(View(anuncio));
        }
コード例 #5
0
        public AnuncioWebmotors GetAnuncioById(int id)
        {
            AnuncioWebmotors anuncio = new AnuncioWebmotors();
            var query = "Select * from tb_AnuncioWebmotors Where Id = @Id";

            anuncio = db.Query <AnuncioWebmotors>(query, new { @id = id }).FirstOrDefault();
            return(anuncio);
        }
コード例 #6
0
        public async Task <IActionResult> Create([Bind("Id,Marca,Modelo,versao, Observacao, Ano, Quilometragem")] AnuncioWebmotors anuncioWebmotors)
        {
            if (ModelState.IsValid)
            {
                _context.Add(anuncioWebmotors);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(anuncioWebmotors));
        }
コード例 #7
0
        public async Task <IActionResult> PostAnuncioWebmotors([FromBody] AnuncioWebmotors anuncioWebmotors)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            _context.Anuncios.Add(anuncioWebmotors);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetAnuncioWebmotors", new { id = anuncioWebmotors.Id }, anuncioWebmotors));
        }
コード例 #8
0
        private async Task <AnuncioWebmotorsViewModel> CarregarInformacoes(AnuncioWebmotors model)
        {
            var makes = await _anuncioWebmotorsService.GetMakes();

            return(new AnuncioWebmotorsViewModel()
            {
                ID = model.ID,
                Ano = model.Ano,
                Marca = model.Marca ?? string.Empty,
                Modelo = model.Modelo ?? string.Empty,
                Versao = model.Versao ?? string.Empty,
                Quilometragem = model.Quilometragem,
                Observacao = model.Observacao,
                Marcas = makes.Select(x => x.Name),
                Modelos = new List <string>(),
                Versoes = new List <string>()
            });
        }
コード例 #9
0
 public ActionResult Edit(AnuncioWebmotors anuncio, FormCollection collection)
 {
     if (ModelState.IsValid)
     {
         try
         {
             // TODO: Add update logic here
             anuncioRepo.UpdateAnuncio(anuncio);
             return(RedirectToAction("Index"));
         }
         catch
         {
             return(View());
         }
     }
     anuncio.Marca  = String.Empty;
     anuncio.Modelo = String.Empty;
     anuncio.Versao = String.Empty;
     return(View(anuncio));
 }
コード例 #10
0
        public ActionResult Create(AnuncioWebmotors anuncio)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    // TODO: Add insert logic here
                    anuncioRepo.AddAnuncio(anuncio);


                    return(RedirectToAction("Index"));
                }
                catch
                {
                    return(View());
                }
            }
            anuncio.Marca  = String.Empty;
            anuncio.Modelo = String.Empty;
            anuncio.Versao = String.Empty;
            return(View(anuncio));
        }
コード例 #11
0
 public void Remove(AnuncioWebmotors obj)
 {
     throw new NotImplementedException();
 }
コード例 #12
0
 public void Update(AnuncioWebmotors obj) => _repository.Update(obj);
コード例 #13
0
 public Task AddAsync(AnuncioWebmotors obj) => _repository.AddAsync(obj);
コード例 #14
0
 public void UpdateAnuncio(AnuncioWebmotors anuncio)
 {
     var query        = "Update tb_AnuncioWebmotors set Marca = @Marca,Modelo = @Modelo,Versao = @Versao,Ano = @Ano,Quilometragem = @Quilometragem,Observacao = @Observacao Where Id = @Id";
     int rowsAffected = db.Execute(query, anuncio);
 }
コード例 #15
0
 public void AddAnuncio(AnuncioWebmotors anuncio)
 {
     var query        = "Insert into tb_AnuncioWebmotors (Marca,Modelo,Versao,Ano,Quilometragem,Observacao) values (@Marca,@Modelo,@Versao,@Ano,@Quilometragem,@Observacao)";
     int rowsAffected = db.Execute(query, anuncio);
 }
コード例 #16
0
        public async Task <bool> AtualizarAnuncio(AnuncioWebmotors anuncio)
        {
            _repository.Update(anuncio);

            return(await _repository.SaveChangesAsync());
        }
コード例 #17
0
        public async Task <bool> DeletarAnuncio(AnuncioWebmotors anuncio)
        {
            _repository.Delete(anuncio);

            return(await _repository.SaveChangesAsync());
        }