Пример #1
0
        public ActionResult Edit(Post modifiedPost)
        {

            var blogEntities = new BlogEntities();
            var postID = modifiedPost.ID;
            var originalPost = GetPostByID(postID);
            if (!ModelState.IsValid)
            {
                return View(originalPost);
            }

            blogEntities.Attach(originalPost);
            blogEntities.ApplyCurrentValues(originalPost.EntityKey.EntitySetName, modifiedPost);
            blogEntities.SaveChanges();

            return RedirectToRouteResult(postID);
        }
Пример #2
0
        public ActionResult Create(Post post)
        {
            if (String.IsNullOrEmpty(post.Title) || String.IsNullOrEmpty(post.Text))
            {
                return View();
            }
            post.ID = Guid.NewGuid();
            post.Posted = DateTime.Now;
            post.Index = post.Title;
            var blogEntities = new BlogEntities();
            blogEntities.AddToPosts(post);
            blogEntities.SaveChanges();

            return RedirectToRouteResult(post.ID);
        }
Пример #3
0
 public ActionResult Delete(Guid postID)
 {
     var postByID = GetPostByID(postID);
     var blogEntities = new BlogEntities();
     blogEntities.Attach(postByID);
     blogEntities.DeleteObject(postByID);
     blogEntities.SaveChanges();
     return RedirectToAction("Index");
 }