コード例 #1
0
 public void Remover(Models.Anuncio car)
 {
     using (var db = new MainContextFactory().CreateDbContext(null))
     {
         db.tb_Anuncio.Remove(car);
         db.SaveChanges();
     }
 }
コード例 #2
0
 public void Edit(Models.Anuncio car)
 {
     BD.Repo.Anuncio repo = new BD.Repo.Anuncio();
     if (car.ID == 0)
     {
         repo.Incluir(car);
     }
     else
     {
         repo.Atualizar(car);
     }
 }
コード例 #3
0
        public IActionResult Car(int id)
        {
            Models.Anuncio anuncio = new Models.Anuncio();
            if (id != 0)
            {
                anuncio         = new BD.Repo.Anuncio().Consultar(id);
                anuncio.modelos = GetModels(anuncio.marca);
                anuncio.versoes = GetVersions(anuncio.modelo);
            }

            anuncio.marcas = GetMakes();
            return(View(anuncio));
        }
コード例 #4
0
        public bool Del(int id)
        {
            try
            {
                Models.Anuncio  car  = new Models.Anuncio();
                BD.Repo.Anuncio repo = new BD.Repo.Anuncio();
                car = repo.Consultar(id);

                repo.Remover(car);
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
コード例 #5
0
        public ActionResult Create()
        {
            string     url      = "http://desafioonline.webmotors.com.br/api/OnlineChallenge/Make";
            HttpClient client   = new HttpClient();
            var        response = client.GetStringAsync(url).GetAwaiter().GetResult();
            var        marcas   = JsonConvert.DeserializeObject <List <Models.Marca> >(response);

            Models.Anuncio anuncio = new Models.Anuncio();
            anuncio.Marcas = new List <Models.Marca>();
            anuncio.Marcas.Add(new Models.Marca()
            {
                Id = 0, Name = "Selecione"
            });
            anuncio.Marcas = marcas;

            return(View(anuncio));
        }
コード例 #6
0
        public ActionResult Create(Models.Anuncio anuncio)
        {
            if (ModelState.IsValid)
            {
                DTO.Anuncio anuncioDTO = new DTO.Anuncio();
                anuncioDTO.Ano           = anuncio.Ano;
                anuncioDTO.Marca         = anuncio.Marca;
                anuncioDTO.Modelo        = anuncio.Modelo;
                anuncioDTO.Observacao    = anuncio.Observacao;
                anuncioDTO.Quilometragem = anuncio.Quilometragem;
                anuncioDTO.Versao        = anuncio.Versao;

                AnuncioBLL bll = new AnuncioBLL();
                bll.InserirAnuncio(anuncioDTO);
                //Está salvando o ID ao invés do Nome da Marca, Modelo e versão :(
                //Fazer o post por AJAX passando o text dos dropdowns.
                return(RedirectToAction("Index"));
            }

            return(View(anuncio));
        }