Example #1
0
        public ActionResult Create([Bind(Include = "Id,Title,Content,Image,CreationDate,Author")] Entry entry)
        {
            if (ModelState.IsValid)
            {
                db.Entry.Add(entry);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(entry));
        }
Example #2
0
        public ActionResult Comment(int id, string name, string email, string body)
        {
            Post    post    = GetPost(id);
            Comment comment = new Comment();

            //Point the comment at the post
            comment.Post     = post;
            comment.DateTime = DateTime.Now;
            comment.Name     = name;
            comment.Email    = email;
            comment.Body     = body;
            model.AddToComments(comment);
            model.SaveChanges();
            return(RedirectToAction("Details", new { id = id }));
        }
Example #3
0
        public ActionResult Update(int?id, string title, string body, DateTime dateTime, string tags)
        {
            if (!IsAdmin)
            {
                return(RedirectToAction("Index"));
            }

            Post post = GetPost(id);

            post.Title    = title;
            post.Body     = body;
            post.DateTime = dateTime;
            post.Tag.Clear();

            tags = tags ?? string.Empty;
            string[] tagNames = tags.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            foreach (string tagName in tagNames)
            {
                post.Tag.Add(GetTag(tagName));
            }

            if (!id.HasValue)
            {
                model.AddToPosts(post);
            }
            model.SaveChanges();
            return(RedirectToAction("Details", new { id = post.ID }));
        }
Example #4
0
 public void Insert(Entry entry)
 {
     using (BlogModel ctx = new BlogModel())
     {
         ctx.Entry.Add(entry);
         ctx.SaveChanges();
     }
 }
Example #5
0
        // POST: Update Post Action.
        public ActionResult Edit([Bind(Include = "Id, Title, Content, TypeOfPost")] Post post)
        {
            var current  = HttpContext.User.Identity.Name;
            var original = db.Posts.Where(i => i.Id == post.Id).FirstOrDefault();

            if (ModelState.IsValid && current == original.AccountEmail)
            {
                original.Title      = post.Title;
                original.Content    = post.Content;
                original.TypeOfPost = post.TypeOfPost;
                db.SaveChanges();
                return(RedirectToAction("Detail", "Posts", new { id = post.Id }));
            }

            return(View(post));
        }
Example #6
0
 public int Complete()
 {
     return(_context.SaveChanges());
 }