Beispiel #1
0
        public ActionResult Edit(int id, BlogPostViewModel vmdl)
        {
            IBlogPostViewModel blogpost = new BlogPostViewModel(_bl.GetPost(id));

            if (Session == null || (string)Session["email"] == null || blogpost.CreatedBy.EMail == null || (string)Session["email"] != blogpost.CreatedBy.EMail)
            {
                return(Json(new
                {
                    Success = false,
                    Message = "Not Allowed to edit this Post"
                }, JsonRequestBehavior.AllowGet));
            }

            if (ModelState.IsValid)
            {
                _bl.DeletePost(_bl.GetPost(id));
                _bl.SaveChanges();

                IBlogPost blogPost = new BlogPost();
                blogPost.CreatedBy = _bl.GetUser((string)Session["email"]);;
                blogPost.CreatedOn = DateTime.Now;
                vmdl.ApplyChanges(blogPost);

                _bl.AddPost(blogPost);
                _bl.SaveChanges();

                CacheController.UpdateBlogPosts(_bl);

                return(RedirectToAction("Index", "BlogPosts"));
            }

            return(View(vmdl));
        }
Beispiel #2
0
        public ActionResult Create(BlogPostViewModel vmdl)
        {
            if (ModelState.IsValid)
            {
                IBlogPost blogPost = new BlogPost();
                blogPost.CreatedBy = _bl.GetUser((string)Session["email"]);;
                blogPost.CreatedOn = DateTime.Now;
                vmdl.ApplyChanges(blogPost);

                _bl.AddPost(blogPost);
                _bl.SaveChanges();

                CacheController.UpdateBlogPosts(_bl);

                return(RedirectToAction("Index", "BlogPosts"));
            }

            return(View(vmdl));
        }