public ActionResult Create([Bind(Include = "id,title,description,text,video_url")] gym_blog gym_blog, HttpPostedFileBase photo) { if (ModelState.IsValid) { if (photo.ContentType == "image/jpeg" || photo.ContentType == "image/png" || photo.ContentType == "image/gif") { // WebImage img = new WebImage(photo.InputStream); DateTime now = DateTime.Now; string fileName = now.ToString("yyyyMdHms") + Path.GetFileName(photo.FileName); string path = Path.Combine(Server.MapPath("~/Uploads"), fileName); photo.SaveAs(path); //if (img.Width > 1000) //img.Resize(500, 500); //img.Save(path); gym_blog.photo = fileName; db.gym_blog.Add(gym_blog); db.SaveChanges(); } else { ViewBag.Message = "You can only jpg,png or gif file upload"; return(View()); } } else { ViewBag.Message = "Error"; return(View()); } return(RedirectToAction("Index")); }
public ActionResult Create2([Bind(Include = "id,title,photo,description,text,video_url")] gym_blog gym_blog) { if (ModelState.IsValid) { db.gym_blog.Add(gym_blog); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(gym_blog)); }
// GET: gym_blog public ActionResult Index(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } dynamic mymodel = new ExpandoObject(); gym_blog gym_id = db.gym_blog.Find(id); mymodel.gym_blog = gym_id; return(View(mymodel)); }
public ActionResult DeleteConfirmed(int id) { gym_blog gym_blog = db.gym_blog.Find(id); string fullPath = Request.MapPath("~/Uploads/" + gym_blog.photo); if (System.IO.File.Exists(fullPath)) { System.IO.File.Delete(fullPath); } db.gym_blog.Remove(gym_blog); db.SaveChanges(); return(RedirectToAction("Index")); }
// GET: gym_blog/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } gym_blog gym_blog = db.gym_blog.Find(id); if (gym_blog == null) { return(HttpNotFound()); } return(View(gym_blog)); }
// GET: gym_blog public ActionResult Index(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } dynamic mymodel = new ExpandoObject(); gym_blog gym_id = db.gym_blog.Find(id); mymodel.gym_blog = gym_id; mymodel.other_sports = db.gym_blog.Where(s => s.id != gym_id.id).ToList(); mymodel.next = db.blogs.FirstOrDefault(n => n.id > gym_id.id); mymodel.prev = db.blogs.OrderByDescending(x => x.id).FirstOrDefault(p => p.id < gym_id.id); return(View(mymodel)); }
public ActionResult Edit([Bind(Include = "id,title,photo,description,text,video_url")] gym_blog gym_blog, string oldfile) { var gelensekil = HttpContext.Request.Files["photo"]; if (gelensekil.FileName.Length > 0) { if (gelensekil.ContentType == "image/jpeg" || gelensekil.ContentType == "image/png" || gelensekil.ContentType == "image/gif") { DateTime now = DateTime.Now; string fileName = now.ToString("yyyyMdHms") + Path.GetFileName(gelensekil.FileName); string newfile = Path.Combine(Server.MapPath("~/Uploads"), fileName); gelensekil.SaveAs(newfile); gym_blog.photo = fileName; string fullPath = Request.MapPath("~/Uploads/" + oldfile); if (System.IO.File.Exists(fullPath)) { System.IO.File.Delete(fullPath); } } else { ViewBag.Message = "You can only jpg,png or gif file upload"; return(View()); } } else { gym_blog.photo = oldfile; } if (ModelState.IsValid) { db.Entry(gym_blog).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(gym_blog)); }