public ActionResult DeleteConfirmed(int id)
        {
            AnimalPicture animalPicture = db.AnimalPictures.Find(id);

            db.AnimalPictures.Remove(animalPicture);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
示例#2
0
        private void grcAnimalList_Click(object sender, EventArgs e)
        {
            if (Application.OpenForms.OfType <AnimalPicture>().Count() > 0)
            {
                Application.OpenForms.OfType <AnimalPicture>().First().Close();
            }

            animalPicture = new AnimalPicture(homelessAnimalBindingSource.Current as HomelessAnimal);
            animalPicture.ShowDialog();
        }
 public ActionResult Edit([Bind(Include = "id,animalId,imageUrl")] AnimalPicture animalPicture)
 {
     if (ModelState.IsValid)
     {
         db.Entry(animalPicture).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.animalId = new SelectList(db.Animals, "id", "animalType", animalPicture.animalId);
     return(View(animalPicture));
 }
        public ActionResult Create([Bind(Include = "id,animalId,imageUrl")] AnimalPicture animalPicture)
        {
            if (ModelState.IsValid)
            {
                db.AnimalPictures.Add(animalPicture);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.animalId = new SelectList(db.Animals, "id", "animalType", animalPicture.animalId);
            return(View(animalPicture));
        }
        // GET: AnimalPictures/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            AnimalPicture animalPicture = db.AnimalPictures.Find(id);

            if (animalPicture == null)
            {
                return(HttpNotFound());
            }
            return(View(animalPicture));
        }
        // GET: AnimalPictures/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            AnimalPicture animalPicture = db.AnimalPictures.Find(id);

            if (animalPicture == null)
            {
                return(HttpNotFound());
            }
            ViewBag.animalId = new SelectList(db.Animals, "id", "animalType", animalPicture.animalId);
            return(View(animalPicture));
        }
示例#7
0
        public async Task <Reply> Photo([FromUri] AnimalPicture model)
        {
            Reply oR = new Reply();

            oR.result = 0;

            string root     = HttpContext.Current.Server.MapPath("~/App_Data");
            var    provider = new MultipartFormDataStreamProvider(root);

            if (!Verify(model.token))
            {
                oR.message = "No autorizado";
                return(oR);
            }

            //validacion multipart
            if (!Request.Content.IsMimeMultipartContent())
            {
                oR.message = "No hay imagen";
                return(oR);
            }

            await Request.Content.ReadAsMultipartAsync(provider);

            FileInfo fileInfoPicture = null;

            foreach (MultipartFileData fileData in provider.FileData)
            {
                if (fileData.Headers.ContentDisposition.Name.Replace("\\", "").Replace("\"", "").Equals("Picture"))
                {
                    fileInfoPicture = new FileInfo(fileData.LocalFileName);
                }
            }

            if (fileInfoPicture != null)
            {
                using (FileStream fs = fileInfoPicture.Open(FileMode.Open, FileAccess.Read))
                {
                    byte[]       b    = new byte[fileInfoPicture.Length];
                    UTF8Encoding temp = new UTF8Encoding(true);
                    while (fs.Read(b, 0, b.Length) > 0)
                    {
                        ;
                    }

                    try
                    {
                        using (BDApiWebEntities bd = new BDApiWebEntities())
                        {
                            var oAnimal = bd.Animales.Find(model.idPicture);
                            oAnimal.Picture         = b;
                            bd.Entry(oAnimal).State = System.Data.Entity.EntityState.Modified;
                            bd.SaveChanges();
                            oR.result = 1;
                        }
                    }
                    catch (Exception ex)
                    {
                        oR.message = "Error al agregar la imagen";
                    }
                }
            }

            return(oR);
        }