Beispiel #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));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            Category category = db.Categories.Find(id);

            db.Categories.Remove(category);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #3
0
        public ActionResult DeleteConfirmed(int id)
        {
            Blog blog = db.Blogs.Find(id);

            db.Blogs.Remove(blog);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #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();
        }
Beispiel #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());
     }
 }
Beispiel #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());
            }
        }
Beispiel #7
0
 public void SaveChanges()
 {
     _context.SaveChanges();
 }
Beispiel #8
0
 public void SaveChanges()
 {
     m_Context.SaveChanges();
 }