コード例 #1
0
        public ActionResult Create([Bind(Include = "Id,Body,CreateTime,BlogId,PosterId")] Comment comment)
        {
            if (ModelState.IsValid)
            {
                db.Comments.Add(comment);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.BlogId   = new SelectList(db.Blogs, "Id", "Title", comment.BlogId);
            ViewBag.PosterId = new SelectList(db.Users, "Id", "UserName", comment.PosterId);
            return(View(comment));
        }
コード例 #2
0
        public ActionResult DeleteConfirmed(int id)
        {
            Category category = db.Categories.Find(id);

            db.Categories.Remove(category);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #3
0
ファイル: BlogsController.cs プロジェクト: zzl1010/ZhaoCode
        public ActionResult DeleteConfirmed(int id)
        {
            Blog blog = db.Blogs.Find(id);

            db.Blogs.Remove(blog);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
コード例 #4
0
        public void DeleteUserPosts(string userId)
        {
            var myPosts = _context.Posts.Where(r => userId.Contains(r.AuthorId));

            foreach (var post in myPosts)
            {
                _context.Posts.Remove(post);
            }
            _context.SaveChanges();
        }
コード例 #5
0
 public ActionResult Edit(int id, User model)
 {
     try
     {
         // TODO: Add update logic here
         using (BlogAppContext context = new BlogAppContext())
         {
             Repository <User> r = new Repository <User>(context);
             r.Update(model);
             context.SaveChanges();
         }
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
コード例 #6
0
        public ActionResult Create(User model)
        {
            try
            {
                using (BlogAppContext context = new BlogAppContext())
                {
                    Repository <User> r = new Repository <User>(context);
                    r.Insert(model);
                    context.SaveChanges();
                }
                // TODO: Add insert logic here

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
コード例 #7
0
ファイル: UnitOfWork.cs プロジェクト: tianfengs/AbpPractice
 public void SaveChanges()
 {
     _context.SaveChanges();
 }
コード例 #8
0
ファイル: UnitOfWork.cs プロジェクト: gwowen/TestBlog2
 public void SaveChanges()
 {
     m_Context.SaveChanges();
 }