示例#1
0
        public ActionResult Create([Bind(Include = "Id,Animal,Raza,Ubicacion,Sexo,Descripcion,Vacunas,Edad,Status")] Mascotas mascotas, HttpPostedFileBase image1)
        {
            var db = new mascotasEntities1();

            if (image1 != null)
            {
                mascotas.Imagen = new byte[image1.ContentLength];
                image1.InputStream.Read(mascotas.Imagen, 0, image1.ContentLength);
            }

            if (ModelState.IsValid)
            {
                db.Mascotas.Add(mascotas);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(mascotas));
        }
示例#2
0
        public ActionResult Daenadopcion(Mascotas mascotas)
        {
            //[Bind(Include = "Id,Animal,Raza,Ubicacion,Sexo,Descripcion,Vacunas,Edad,Status")]
            //,  HttpPostedFileBase image1



            var db = new mascotasEntities1();

            //string fileName = Path.GetFileNameWithoutExtension(mascotas.ImagenFile.FileName);
            string fileName  = Path.GetFileNameWithoutExtension(mascotas.ImagenFile.FileName);
            string extension = Path.GetExtension(mascotas.ImagenFile.FileName);

            fileName = fileName + DateTime.Now.ToString("yymmssfff") + extension;
            //mascotas.ImagePath = "/Content/Imagenes/" + fileName;
            mascotas.ImagenA = "/Content/Imagenes/Mascotas/" + fileName;
            fileName         = Path.Combine(Server.MapPath("/Content/Imagenes/Mascotas/"), fileName);
            mascotas.ImagenFile.SaveAs(fileName);

            //if (image1 != null)
            //{
            //    mascotas.Imagen = new byte[image1.ContentLength];
            //    image1.InputStream.Read(mascotas.Imagen, 0, image1.ContentLength);

            //}

            if (ModelState.IsValid)
            {
                db.Mascotas.Add(mascotas);
                db.SaveChanges();
                ModelState.Clear();
                return(RedirectToAction("Adopta"));
            }
            else
            {
                return(View());
            }
        }