public ActionResult CreateAnuncio(AnuncioViewModel anuncio)
        {
            anuncio anuncioNew = new anuncio();

            string guid                   = Guid.NewGuid().ToString().ToUpper();
            var    toPathUpload           = Server.MapPath($"~/images/anuncio/{guid}");
            var    newPathUploadFileName  = $"{toPathUpload}/{anuncio.foto1}";
            var    newPathUploadFileName2 = $"{toPathUpload}/{anuncio.foto2}";

            Directory.CreateDirectory(toPathUpload);
            System.IO.File.Create(newPathUploadFileName);
            System.IO.File.Create(newPathUploadFileName2);

            anuncioNew.idCategoria = anuncio.idcategoria;
            anuncioNew.preco       = anuncio.preco;
            anuncioNew.medida      = anuncio.medida;
            anuncioNew.descricao   = anuncio.descricao;
            anuncioNew.foto1       = anuncio.foto1;
            anuncioNew.foto2       = anuncio.foto2;
            anuncioNew.idUsuario   = anuncio.idUsuario;

            db.anuncio.Add(anuncioNew);
            db.SaveChanges();

            return(RedirectToAction("Index", "Home"));
        }
        public ActionResult EditarAnuncioEscolhido(AnuncioViewModel anuncio)
        {
            try
            {
                AnuncioViewModel anuncioUpdate = new AnuncioViewModel();

                anuncio anunEditar = db.anuncio.FirstOrDefault(x => x.id == anuncio.id);

                anunEditar.descricao   = anuncio.descricao;
                anunEditar.idCategoria = anuncio.idcategoria;
                anunEditar.idUsuario   = anuncio.idUsuario;
                anunEditar.medida      = anuncio.medida;
                anunEditar.preco       = anuncio.preco;
                anunEditar.foto1       = anuncio.foto1;
                anunEditar.foto2       = anuncio.foto2;

                db.SaveChanges();

                return(Json(new { Success = true }));
            }
            catch
            {
                return(Json(new { Success = false, Response = "Falha ao editar o registro" }));
            }
        }
Example #3
0
        public ActionResult DeleteConfirmed(int id)
        {
            anuncio anuncio = db.anuncios.Find(id);

            db.anuncios.Remove(anuncio);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Example #4
0
        //public void Hello()
        //{
        //    Clients.All.hello();
        //}

        public JsonResult MostrarDescricao(anuncio anuncio)
        {
            var list = db.anuncio.Select(x => x.descricao != "");

            Clients.All.Atualizar(anuncio);
            return(new JsonResult {
                Data = list, JsonRequestBehavior = JsonRequestBehavior.AllowGet
            });
        }
Example #5
0
 public ActionResult Edit([Bind(Include = "Id,Nombre,Foto,Descripción,fecha,Dirección,Id_usuario,listaComentario")] anuncio anuncio)
 {
     if (ModelState.IsValid)
     {
         db.Entry(anuncio).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(anuncio));
 }
Example #6
0
 public ActionResult Edit([Bind(Include = "ID,marca,modelo,versao,ano,quilometragem,text")] anuncio anuncio)
 {
     if (ModelState.IsValid)
     {
         db.Entry(anuncio).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(anuncio));
 }
        public ActionResult Edit(int id)
        {
            anuncio anun = new anuncio();

            anun = db.anuncio.Where(x => x.id == id).FirstOrDefault();
            var anunciolista = Mapper.Map <anuncio, AnuncioViewModel>(anun);

            anunciolista.cat     = db.categoria.AsQueryable().Where(x => x.id != 0).FirstOrDefault();
            Session["categoria"] = new SelectList(db.categoria, "id", "titulo");
            return(View(anunciolista));
        }
Example #8
0
        public ActionResult Create([Bind(Include = "Id,Nombre,Foto,Descripción,fecha,Dirección,Id_usuario,listaComentario")] anuncio anuncio)
        {
            if (ModelState.IsValid)
            {
                db.anuncios.Add(anuncio);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(anuncio));
        }
Example #9
0
        public ActionResult Create([Bind(Include = "ID,marca,modelo,versao,ano,quilometragem,text")] anuncio anuncio)
        {
            if (ModelState.IsValid)
            {
                db.Anuncio.Add(anuncio);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(anuncio));
        }
Example #10
0
        // GET: anuncios/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            anuncio anuncio = db.anuncios.Find(id);

            if (anuncio == null)
            {
                return(HttpNotFound());
            }
            return(View(anuncio));
        }
Example #11
0
        public ActionResult ExluirAnuncio(int id)
        {
            try
            {
                anuncio anunEditar = db.anuncio.FirstOrDefault(x => x.id == id);
                db.anuncio.Remove(anunEditar);
                db.SaveChanges();

                return(Json(new { Success = true }));
            }
            catch
            {
                return(Json(new { Success = false, Response = "Falha ao editar o registro" }));
            }
        }