public ActionResult Create([Bind(Include = "id,title,text,video_url")] cartoon cartoon, HttpPostedFileBase photo) { if (photo.ContentLength > 0) { if (photo.ContentType == "image/jpeg" || photo.ContentType == "image/png" || photo.ContentType == "image/gif") { DateTime now = DateTime.Now; string fileName = now.ToString("yyyyMdHms") + Path.GetFileName(photo.FileName); string path = Path.Combine(Server.MapPath("~/Uploads"), fileName); photo.SaveAs(path); cartoon.photo = fileName; db.cartoons.Add(cartoon); db.SaveChanges(); } else { ViewBag.Message = "You can only jpg,png or gif file upload"; return(View()); } } else { ViewBag.Message = "Errorrr"; return(View()); } return(RedirectToAction("Index")); }
public ActionResult Edit2([Bind(Include = "id,title,photo,text,video_url")] cartoon cartoon) { if (ModelState.IsValid) { db.Entry(cartoon).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(cartoon)); }
public ActionResult Create2([Bind(Include = "id,title,photo,text,video_url")] cartoon cartoon) { if (ModelState.IsValid) { db.cartoons.Add(cartoon); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(cartoon)); }
public IActionResult CreateUser(cartoon x) { if (ModelState.IsValid) { // do somethng! maybe insert into db? then we will redirect return(RedirectToAction("ShowUser", x)); } else { return(View("NewToon")); } }
// GET: cartoon_blog public ActionResult Index(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } dynamic mymodel = new ExpandoObject(); cartoon cartoon_id = db.cartoons.Find(id); mymodel.cartoon_blog = cartoon_id; return(View(mymodel)); }
// GET: cartoonsCrud/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } cartoon cartoon = db.cartoons.Find(id); if (cartoon == null) { return(HttpNotFound()); } return(View(cartoon)); }
public ActionResult DeleteConfirmed(int id) { cartoon cartoon = db.cartoons.Find(id); string fullPath = Request.MapPath("~/Uploads/" + cartoon.photo); if (System.IO.File.Exists(fullPath)) { System.IO.File.Delete(fullPath); } db.cartoons.Remove(cartoon); db.SaveChanges(); return(RedirectToAction("Index")); }
// GET: cartoon_blog public ActionResult Index(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } dynamic mymodel = new ExpandoObject(); cartoon cartoon_id = db.cartoons.Find(id); mymodel.cartoon_blog = cartoon_id; mymodel.othercartoons = db.cartoons.Where(o => o.id != cartoon_id.id).ToList(); mymodel.next = db.blogs.FirstOrDefault(n => n.id > cartoon_id.id); mymodel.prev = db.blogs.OrderByDescending(x => x.id).FirstOrDefault(p => p.id < cartoon_id.id); return(View(mymodel)); }
public IActionResult AllToon() { List <cartoon> x = new List <cartoon>(); cartoon bob = new cartoon("spongebob", 2, "hello", false); cartoon Bugs = new cartoon("Bugs", 3, "wow", false); cartoon Bunny = new cartoon("Bunny", 5, "no", false); cartoon angel = new cartoon("angel", 7, "way", false); x.Add(bob); x.Add(Bugs); x.Add(Bunny); x.Add(angel); return(View("Toons", x)); }
public ActionResult Edit(int id, [Bind(Include = "id,title,photo,text,video_url")] cartoon cartoon, 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") { string fullPath = Request.MapPath("~/Uploads/" + oldfile); if (System.IO.File.Exists(fullPath)) { System.IO.File.Delete(fullPath); } DateTime now = DateTime.Now; string fileName = now.ToString("yyyyMdHms") + Path.GetFileName(gelensekil.FileName); string newfile = Path.Combine(Server.MapPath("~/Uploads"), fileName); gelensekil.SaveAs(newfile); cartoon.photo = fileName; } else { ViewBag.Message = "You can only jpg,png or gif file upload"; return(View()); } } else { cartoon.photo = oldfile; } if (ModelState.IsValid) { db.Entry(cartoon).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(cartoon)); }
public IActionResult ShowUser(cartoon x) { return(View("toon", x)); }
public IActionResult CreateUser(cartoon x) { return(RedirectToAction("ShowUser", x)); }