コード例 #1
0
ファイル: HomeController.cs プロジェクト: rebootd/NoSQLIntro1
        public ActionResult Edit(Guid id, Post post)
        {
            //get teh original and update it
            Post original = DataSession.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;
                ClearOldTags(original);
                //update tags
                string taglist = Request.Form["Tags"];
                string[] tags = taglist.Split(',');

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

                DataSession.SaveOrUpdate(original);
                return RedirectToAction("Index", "Home");
            }
            else
            {
                ModelState.AddModelError("", "Some fields are invalid.");
                return View(post);
            }
        }
コード例 #2
0
ファイル: HomeController.cs プロジェクト: rebootd/NoSQLIntro1
        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)
                    post.Tags.Add(new Tag { Name = tag, Post = post });

                DataSession.SaveOrUpdate(post);
                return RedirectToAction("Index", "Home");
            }
            else
            {
                ModelState.AddModelError("", "Some fields are invalid.");
                return View(post);
            }
        }
コード例 #3
0
ファイル: HomeController.cs プロジェクト: rebootd/NoSQLIntro1
 private void ClearOldTags(Post post)
 {
     foreach (Tag tag in post.Tags)
     {
         DataSession.Delete(tag);
     }
     post.Tags.Clear(); //remove old tags
 }