コード例 #1
0
 public ActionResult Edit(int id, Blog blog)
 {
     try
     {
         _context.Entry(blog).State = System.Data.EntityState.Modified;
         _context.SaveChanges();
         return RedirectToAction("Index");
     }
     catch
     {
         return View();
     }
 }
コード例 #2
0
 public ActionResult Create(Blog newBlog)
 {
     try
     {
         newBlog.DateCreated = DateTime.Now;
         using (_context)
         {
             _context.Blogs.Add(newBlog);
             _context.SaveChanges();
         }
         return RedirectToAction("Index");
     }
     catch
     {
         return View();
     }
 }
コード例 #3
0
        public ActionResult EditwithConcurrencyCheck(int id, Blog blog, string originalName)
        {
            try
            {
                _context.Entry(blog).State = System.Data.EntityState.Modified;

                // Concurrency Check with Blogger name. Change the Edit Get view to send original Blogger name as an hidden Field
                _context.Entry(blog).Property(b => b.BloggerName).OriginalValue = originalName;


                _context.SaveChanges();
                return RedirectToAction("Index");
            }
            catch
            {
                return View();
            }
        }
コード例 #4
0
 public ActionResult Delete(int id, Blog blog)
 {
     try
     {
         using (_context)
         {
             _context.Entry(blog).State = System.Data.EntityState.Deleted;
             _context.SaveChanges();
         }
         return RedirectToAction("Index");
     }
     catch
     {
         return View();
     }
 }