public ActionResult New(Post post) { if (post.Title != null && post.Title.Length > 0 && post.Content != null && post.Content.Length > 0) { post.Id = Guid.NewGuid(); 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 }); var collPosts = CurrentMongoSession.GetCollection<Post>(); collPosts.Insert(post); return RedirectToAction("Index"); } else { ModelState.AddModelError("", "Some fields are invalid."); return View(post); } }
public ActionResult Edit(Guid id, Post post) { var collPosts = CurrentMongoSession.GetCollection<Post>(); Post original = collPosts.FindOne(new { Id = 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 }); collPosts.Save(original); return RedirectToAction("Index", "Home"); } else { ModelState.AddModelError("", "Some fields are invalid."); return View(post); } }