public ActionResult Delete(int? id) { try { Blog blog = new Blog(); if(ModelState.IsValid) { if (id == null) return new HttpStatusCodeResult(HttpStatusCode.BadRequest); blog = db.Blogs.Find(id); if (blog == null) return HttpNotFound(); db.Blogs.Remove(blog); db.SaveChanges(); return RedirectToAction("Index"); } return View(blog); } catch { return View(); } }
public ActionResult Create(Blog blog) { try { db.Blogs.Add(blog); db.SaveChanges(); return RedirectToAction("Index"); } catch { return View(); } }
public ActionResult Edit(int id, Blog blog) { /*var query = from Blogs in db.Blogs where blog.BlogId == id select blog; foreach (Blog blogData in query) { blogData.Name = "Gary Clark Jr"; } */ try { Blog blogger = db.Blogs.Where(x => x.BlogId == id).Single<Blog>(); blogger.Name = blog.Name; db.SaveChanges(); return RedirectToAction("Index"); } catch { return View(); } }
// GET: Blog/Details/5 public ActionResult Details(int id, Blog blog) { blog = db.Blogs.Find(id); return View(blog); }
// GET: Blog/Delete/5 public ActionResult Delete(int id) { Blog blog = new Blog(); blog = db.Blogs.Find(id); return View(blog); }
public string getSomeData(int? id) { HttpCookie cookie = new HttpCookie("Color"); cookie.Value = "SomeData"; cookie.Domain = "localhost"; cookie.Expires = DateTime.Now.AddHours(-1); Response.SetCookie(cookie); Session["FirstName"] = "test"; Session["LastName"] = "test2"; Session["City"] = "test3"; Blog blog = new Blog(); blog = db.Blogs.Find(id); return blog.Name; }