Esempio n. 1
0
        public IActionResult Editar(int id, [Bind] AnuncioMOD anuncio)
        {
            try
            {
                if (id != anuncio.ID)
                {
                    return(NotFound());
                }

                if (ModelState.IsValid)
                {
                    ianuncio.UpdateAnuncio(anuncio);
                    TempData.Add("Mensagem-Sucesso-Alerta", "Anúncio atualizado com sucesso!");
                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(View(anuncio));
                }
            }
            catch (System.Exception)
            {
                TempData["Mensagem-Erro-Alerta"] = "Ops! Ocorreu um erro ao tentar atualizar seu anúncio!";
                return(RedirectToAction("Editar", new { id }));

                throw;
            }
        }
Esempio n. 2
0
        public IActionResult Detalhes(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            AnuncioMOD anuncio = ianuncio.GetAnuncio(id);

            anuncio.marca_nome  = ianuncio.GetMarcas().FirstOrDefault(x => x.ID == anuncio.marca).name;
            anuncio.modelo_nome = ianuncio.GetModelos(anuncio.marca).FirstOrDefault(x => x.ID == anuncio.modelo).name;
            //verifica a versão do veículo
            var versoes = ianuncio.GetVersoes(anuncio.modelo);

            if (versoes.Where(x => x.ID == anuncio.versao).Count() > 0)
            {
                anuncio.versao_nome = versoes.FirstOrDefault(x => x.ID == anuncio.versao).name;
            }

            if (anuncio == null)
            {
                return(NotFound());
            }

            return(View(anuncio));
        }
Esempio n. 3
0
        /// <summary>
        /// edita um anúncio
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public IActionResult Editar(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            AnuncioMOD anuncio = ianuncio.GetAnuncio(id);

            if (anuncio == null)
            {
                return(NotFound());
            }

            GetMarcas();
            GetModelos(anuncio.marca);
            GetVersoes(anuncio.modelo);

            return(View(anuncio));
        }
Esempio n. 4
0
        public IActionResult Cadastrar([Bind] AnuncioMOD anuncio)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    ianuncio.AddAnuncio(anuncio);
                    TempData.Add("Mensagem-Sucesso-Alerta", "Anúncio cadastrado com sucesso!");
                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(View(anuncio));
                }
            }
            catch (System.Exception)
            {
                TempData.Add("Mensagem-Erro-Alerta", "Ops! Ocorreu um erro ao tentar cadastrar seu anúncio!");
                return(View(anuncio));

                throw;
            }
        }