public ActionResult Add(PostViewModel postModel) { if (ModelState.IsValid) { var postEntity = postModel.ToPostEntity(_tagRepository); postEntity.PostAddedDate = DateTime.Now; postEntity.PostEditedDate = postEntity.PostAddedDate; postEntity.OwnerUserID = GetUserId(); if (string.IsNullOrEmpty(postEntity.PostUrl)) { postEntity.PostUrl = UniqueUrlHelper.FindUniqueUrl(_postRepository, postEntity.PostTitle, ItemEntryType); } var pageID = _postRepository.AddPost(postEntity); if (pageID > 0) { return(RedirectToAction("Edit", new { postID = pageID, newlyAdded = true })); } } postModel.Title = SettingsRepository.BlogName; postModel.SharingEnabled = SettingsRepository.BlogSocialSharing; return(View(postModel)); }
public void Can_Generate_Slug_For_Non_Duplicate_Url_2() { const string postTitle = "a test url 20"; var postRepository = MockObjectFactory.CreatePostRepository(); var generatedSlug = UniqueUrlHelper.FindUniqueUrl(postRepository, postTitle, 1); Assert.AreEqual("a-test-url-20-2", generatedSlug); }
public ActionResult Edit(PostViewModel postModel) { if (ModelState.IsValid) { var postEntity = postModel.ToPostEntity(_tagRepository); postEntity.PostEditedDate = DateTime.Now; if (string.IsNullOrEmpty(postEntity.PostUrl)) { postEntity.PostUrl = UniqueUrlHelper.FindUniqueUrl(_postRepository, postEntity.PostTitle, ItemEntryType, postEntity.PostID); } _postRepository.UpdatePost(postEntity); postModel.UpdateStatus = true; postModel.IsNewPostOrPage = false; } postModel.Title = SettingsRepository.BlogName; postModel.SharingEnabled = SettingsRepository.BlogSocialSharing; return(View(postModel)); }