public ActionResult Create([Bind(Include = "ImageId,LivestockID,Image,UploadtDate")] LivestockImage livestockImage, HttpPostedFileBase image1) { if (ModelState.IsValid) { //if an image is selected if (image1 != null && image1.ContentLength > 0) { livestockImage.UploadtDate = DateTime.Now; livestockImage.Image = livestockImage.setImage(image1); var path = Path.Combine(Server.MapPath("~/App_Data"), livestockImage.FileName(image1)); //byte[] data = null; //data = new byte[image1.ContentLength]; //image1.InputStream.Read(data, 0, image1.ContentLength); //livestockImage.Image = data; image1.SaveAs(path); } else { TempData["Message"] = "<script>alert('No Image was selected!');</script>"; return(RedirectToAction("Index", "LivesStocks")); } db.LivestockImages.Add(livestockImage); db.SaveChanges(); TempData["Message"] = "<script>alert('Livestock image added!');</script>"; return(RedirectToAction("Index", "LivesStocks")); } return(View(livestockImage)); }
public ActionResult DeleteConfirmed(int id) { LivestockImage livestockImage = db.LivestockImages.Find(id); db.LivestockImages.Remove(livestockImage); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Create(LivesStock livestock) { LivestockImage livestockImage = new LivestockImage(); //links the image to be uploaded, with the selected livestock livestockImage.LivestockID = livestock.LivestockID; //takes the livestockImage with the livestockID to the image upload screen return(View(livestockImage)); }
// GET: LivestockImages/Delete/5 public ActionResult Delete(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } LivestockImage livestockImage = db.LivestockImages.Find(id); if (livestockImage == null) { return(HttpNotFound()); } return(View(livestockImage)); }