Example #1
0
 public Post GetNewPost()
 {
     Post post = new Post { Title = "new title", Hash = "new-title", Content = "test content", Published = DateTime.Now, Created = DateTime.Now };
     post.Tags.Add(new Tag { Name = "yours" });
     post.Tags.Add(new Tag { Name = "mine" });
     return post;
 }
Example #2
0
 public TagTests()
 {
     //ensure there's at least one post
     _post = GetNewPost();
     DocumentSession.Store(_post);
     DocumentSession.SaveChanges();
 }
Example #3
0
        public ActionResult Edit(string id, Post post)
        {
            //get teh original and update it
            Post original = DocumentSession.Load<Post>(id);
            if (post.Title != null && post.Title.Length > 0 && post.Content != null && post.Content.Length > 0)
            {
                original.Hash = post.Hash;
                original.Title = post.Title;
                original.Content = post.Content;
                //update tags
                string taglist = Request.Form["Tags"];
                string[] tags = taglist.Split(',');
                original.Tags.Clear();
                foreach (string tag in tags)
                    if (tag != null && tag.Length > 0) original.Tags.Add(new Tag { Name = tag });

                DocumentSession.SaveChanges();
                return RedirectToAction("Index", "Home");
            }
            else
            {
                ModelState.AddModelError("", "Some fields are invalid.");
                return View(post);
            }
            //return View();
        }
Example #4
0
        public ActionResult New(Post post)
        {
            if (post.Title != null && post.Title.Length > 0 && post.Content != null && post.Content.Length > 0)
            {
                post.Published = DateTime.Now;
                post.Created = DateTime.Now;
                //update tags
                string taglist = Request.Form["Tags"];
                string[] tags = taglist.Split(',');

                foreach (string tag in tags)
                    if (tag != null && tag.Length > 0) post.Tags.Add(new Tag { Name = tag });

                DocumentSession.Store(post);
                DocumentSession.SaveChanges();
                return RedirectToAction("Index", "Home");
            }
            else
            {
                ModelState.AddModelError("", "Some fields are invalid.");
                return View(post);
            }
            //return View();
        }