public ActionResult DeleteConfirmed(int id) { SiteImages siteImages = db.SiteImages.Find(id); db.SiteImages.Remove(siteImages); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit([Bind(Include = "SiteImagesId,ContentDataId,Image_url,Name")] SiteImages siteImages) { if (ModelState.IsValid) { db.Entry(siteImages).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(siteImages)); }
public ActionResult Create([Bind(Include = "SiteImagesId,ContentDataId,Image_url,Name")] SiteImages siteImages) { if (ModelState.IsValid) { db.SiteImages.Add(siteImages); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(siteImages)); }
// GET: SiteImages/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } SiteImages siteImages = db.SiteImages.Find(id); if (siteImages == null) { return(HttpNotFound()); } return(View(siteImages)); }
public ActionResult Editmage(FormCollection fc, HttpPostedFileBase file) { int SiteImagesId; if (!int.TryParse(fc["SiteImagesId"], out SiteImagesId)) { throw new HttpException(404, "Image not found"); } int ContentDataId; if (!int.TryParse(fc["ContentDataId"], out ContentDataId)) { throw new HttpException(404, "ContentDataId not found"); } SiteImages siteImages = db.SiteImages.Find(SiteImagesId); if (file != null) { var fileName = Path.GetFileName(file.FileName); var ext = Path.GetExtension(file.FileName); var allowedExtensions = new[] { ".jpg", ".png", ".jpg", ".jpeg" }; if (allowedExtensions.Contains(ext.ToLower())) { string name = Path.GetFileNameWithoutExtension(fileName); //getting file name without extension string filePath = name + "_" + ContentDataId + ext; //appending the name with id // store the file inside ~/project folder(Img) var path = Path.Combine(Server.MapPath("~/Img"), filePath); file.SaveAs(path); siteImages.Image_url = filePath; } } siteImages.ContentDataId = ContentDataId; siteImages.Name = fc["Name"].ToString(); db.SaveChanges(); return(View()); }
public ActionResult UploadNewImage(FormCollection fc, HttpPostedFileBase file) { int ContentDataId; if (!int.TryParse(fc["ContentDataId"], out ContentDataId)) { ContentDataId = 1; } var fileName = Path.GetFileName(file.FileName); var ext = Path.GetExtension(file.FileName); var allowedExtensions = new[] { ".jpg", ".png", ".jpg", ".jpeg" }; if (allowedExtensions.Contains(ext.ToLower())) //check what type of extension { string name = Path.GetFileNameWithoutExtension(fileName); //getting file name without extension string filePath = name + "_" + ContentDataId + ext; //appending the name with id // store the file inside ~/project folder(Img) var path = Path.Combine(Server.MapPath("~/Img"), filePath); file.SaveAs(path); SiteImages siteImages = new SiteImages(); siteImages.ContentDataId = ContentDataId; siteImages.Image_url = filePath; siteImages.Name = fc["Name"].ToString(); //if (fileName) { db.SiteImages.Add(siteImages); db.SaveChanges(); return(RedirectToAction("Index")); } } else { } return(View()); }
public ActionResult Index(FormCollection fc, HttpPostedFileBase file) { int ContentDataId; if (!int.TryParse(fc["ContentDataId"], out ContentDataId)) { ContentDataId = 1; } var fileName = Path.GetFileName(file.FileName); var ext = Path.GetExtension(file.FileName); var allowedExtensions = new[] { ".Jpg", ".png", ".jpg", "jpeg" }; if (allowedExtensions.Contains(ext)) //check what type of extension { string name = Path.GetFileNameWithoutExtension(fileName); //getting file name without extension string filePath = name + "_" + ContentDataId + ext; //appending the name with id // store the file inside ~/project folder(Img) var path = Path.Combine(Server.MapPath("~/Img"), filePath); file.SaveAs(path); SiteImages siteImages = new SiteImages(); siteImages.ContentDataId = ContentDataId; siteImages.Image_url = filePath; siteImages.Name = fc["Name"].ToString(); //if (fileName) { db.siteImg.Add(siteImages); db.SaveChanges(); return(RedirectToAction("Index")); } } else { } //return View(siteImages); //getting only file name(ex-ganesh.jpg) /* * tbl_details tbl = new tbl_details(); * var allowedExtensions = new[] { * ".Jpg", ".png", ".jpg", "jpeg" * }; * tbl.Id = fc["Id"].ToString(); * tbl.Image_url = file.ToString(); //getting complete url * tbl.Name = fc["Name"].ToString(); * var fileName = Path.GetFileName(file.FileName); //getting only file name(ex-ganesh.jpg) * var ext = Path.GetExtension(file.FileName); //getting the extension(ex-.jpg) * if (allowedExtensions.Contains(ext)) //check what type of extension * { * string name = Path.GetFileNameWithoutExtension(fileName); //getting file name without extension * string myfile = name + "_" + tbl.Id + ext; //appending the name with id * // store the file inside ~/project folder(Img) * var path = Path.Combine(Server.MapPath("~/Img"), myfile); * tbl.Image_url = path; * obj.tbl_details.Add(tbl); * obj.SaveChanges(); * file.SaveAs(path); * } * else * { * ViewBag.message = "Please choose only Image file"; * } */ return(View()); }