public ActionResult Add(PostViewModel postModel) { if (ModelState.IsValid) { var tags = _tagRepository.GetTagEntities(postModel.Tags.Split(',').ToList()); _tagRepository.AddTags(tags); 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 biltyPostUrl = BitlyUrlService.GetBiltyPostUrl(SettingsRepository, postEntity.PostUrl); if (biltyPostUrl != null) { postEntity.BitlyUrl = biltyPostUrl; postEntity.BitlySourceUrl = postEntity.PostUrl; } var postId = _postRepository.AddPost(postEntity); if (postId > 0) { return(RedirectToAction("Edit", new { postID = postId, newlyAdded = true })); } } postModel.Title = SettingsRepository.BlogName; postModel.SharingEnabled = SettingsRepository.BlogSocialSharing; return(View(postModel)); }
public ActionResult Edit(PostViewModel postModel) { if (ModelState.IsValid) { var tags = _tagRepository.GetTagEntities(postModel.Tags.Split(',').ToList()); _tagRepository.AddTags(tags); var postEntity = postModel.ToPostEntity(_tagRepository); postEntity.PostEditedDate = DateTime.Now; if (string.IsNullOrEmpty(postEntity.PostUrl)) { postEntity.PostUrl = UniqueUrlHelper.FindUniqueUrl(_postRepository, postEntity.PostTitle, ItemEntryType, postEntity.PostID); } if (postEntity.PostUrl != postEntity.BitlySourceUrl) { var biltyPostUrl = BitlyUrlService.GetBiltyPostUrl(SettingsRepository, postEntity.PostUrl); if (biltyPostUrl != null) { postEntity.BitlyUrl = biltyPostUrl; postEntity.BitlySourceUrl = postEntity.PostUrl; } } _postRepository.UpdatePost(postEntity); postModel.UpdateStatus = true; postModel.IsNewPostOrPage = false; } postModel.Title = SettingsRepository.BlogName; postModel.SharingEnabled = SettingsRepository.BlogSocialSharing; return(View(postModel)); }
private void SavePostInternal(PostViewModel postModel) { var tags = _tagRepository.GetTagEntities(postModel.Tags.Split(',').ToList()); _tagRepository.AddTags(tags); var postEntity = postModel.ToPostEntity(_tagRepository); postEntity.PostEditedDate = DateTime.Now; if (string.IsNullOrEmpty(postEntity.PostUrl)) { postEntity.PostUrl = UniqueUrlHelper.FindUniqueUrl(_postRepository, postEntity.PostTitle, ItemEntryType, postEntity.PostID); } if (postEntity.PostUrl != postEntity.BitlySourceUrl) { var biltyPostUrl = BitlyUrlService.GetBiltyPostUrl(SettingsRepository, postEntity.PostUrl); if (biltyPostUrl != null) { postEntity.BitlyUrl = biltyPostUrl; postEntity.BitlySourceUrl = postEntity.PostUrl; } } _postRepository.UpdatePost(postEntity); }
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_4() { const string postTitle = "programatic web.config.config"; var postRepository = MockObjectFactory.CreatePostRepository(); var generatedSlug = UniqueUrlHelper.FindUniqueUrl(postRepository, postTitle, 1); Assert.AreEqual("programatic-web-config-config", generatedSlug); }
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 JsonResult VerifyUrlUrlExists(string postTitle, string entryType, int postId) { var post = postId > 0 ? _postRepository.GetPostByID(postId) : null; var finalUrl = post != null?UniqueUrlHelper.FindUniqueUrl(_postRepository, postTitle, byte.Parse(entryType), postId) : UniqueUrlHelper.FindUniqueUrl(_postRepository, postTitle, byte.Parse(entryType)); return(Json(finalUrl, JsonRequestBehavior.AllowGet)); }
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)); }