コード例 #1
0
ファイル: PageController.cs プロジェクト: LByron/BS
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
ファイル: PostController.cs プロジェクト: rinckd/sblog.net
 public ActionResult Add()
 {
     var postModel = new PostViewModel
                         {
                             Post = new PostEntity {EntryType = ItemEntryType, UserCanAddComments = true, CanBeShared = true},
                             Categories = GetModel(_categoryRepository.GetCategories()),
                             Tags = string.Empty,
                             Title = SettingsRepository.BlogName,
                             SharingEnabled =  SettingsRepository.BlogSocialSharing
                         };
     return View(postModel);
 }
コード例 #4
0
ファイル: PageController.cs プロジェクト: LByron/BS
        public ActionResult Add()
        {
            ValidateActionRequest("Unauthorized attempt to add a post");

            var postModel = new PostViewModel
                                {
                                    Post = new PostEntity {EntryType = ItemEntryType, UserCanAddComments = true, CanBeShared = true},
                                    Title = SettingsRepository.BlogName,
                                    SharingEnabled = SettingsRepository.BlogSocialSharing
                                };

            return View(postModel);
        }
コード例 #5
0
        public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            var postModel = new PostViewModel
                                {
                                    Post =
                                        new PostEntity
                                            {
                                                PostID = int.Parse(bindingContext.GetValue("Post.PostID")),
                                                PostTitle = bindingContext.GetValue("Post.PostTitle"),
                                                PostContent = bindingContext.GetValue("Post.PostContent"),
                                                PostUrl = bindingContext.GetValue("Post.PostUrl"),
                                                PostAddedDate = DateTime.Parse(bindingContext.GetValue("Post.PostAddedDate")),
                                                UserCanAddComments = bool.Parse(bindingContext.GetValue("Post.UserCanAddComments")),
                                                CanBeShared = bool.Parse(bindingContext.GetValue("Post.CanBeShared")),
                                                IsPrivate = bool.Parse(bindingContext.GetValue("Post.IsPrivate")),
                                                EntryType = byte.Parse(bindingContext.GetValue("Post.EntryType")),
                                                BitlyUrl = bindingContext.GetValue("Post.BitlyUrl"),
                                                BitlySourceUrl = bindingContext.GetValue("Post.BitlySourceUrl"),                                                
                                            }
                                };

            postModel.Post.Order = postModel.Post.EntryType == 2 ? (int?)GetOrder(bindingContext.GetValue("Post.Order")) : null;

            IModelBinder ckBinder = new CheckBoxListViewModelBinder();
            postModel.Categories = (CheckBoxListViewModel)ckBinder.BindModel(controllerContext, bindingContext);

            if (postModel.Post.EntryType == 1)
            {
                if (!postModel.Categories.Items.Any(c => c.IsChecked))
                {
                    var general = postModel.Categories.Items.SingleOrDefault(c => c.Value == "1");
                    if (general != null)
                    {
                        general.IsChecked = true;
                    }
                }

                postModel.Tags = bindingContext.GetValue("hdnAddedTags");
            }

            postModel.AjaxSaved = bool.Parse(bindingContext.GetValue("AjaxSaved"));

            return postModel;
        }
コード例 #6
0
ファイル: PostController.cs プロジェクト: rinckd/sblog.net
        public ActionResult Edit(PostViewModel postModel)
        {
            if (ModelState.IsValid)
            {
                SavePostInternal(postModel);

                if (Request.IsAjaxRequest())
                {
                    var status = new PostOrPageSaveStatus { PostId = postModel.Post.PostID, IsValid = true };
                    return Json(status, JsonRequestBehavior.AllowGet);
                }

                postModel.UpdateStatus = true;
                postModel.IsNewPostOrPage = false;
            }
            postModel.Title = SettingsRepository.BlogName;
            postModel.SharingEnabled = SettingsRepository.BlogSocialSharing;

            return View(postModel);
        }
コード例 #7
0
ファイル: PostController.cs プロジェクト: rinckd/sblog.net
        public ActionResult Edit(int postID, [DefaultValue(false)] bool newlyAdded)
        {
            var post = _postRepository.GetPostByID(postID);

            ValidateEditRequest(post);

            var postModel = new PostViewModel
                {
                    Post = post,
                    Categories = GetModel(_categoryRepository.GetCategories(), post.Categories),
                    Tags = string.Join(",",_tagRepository.GetTagsByPostID(postID).Select(t => t.TagName).ToArray()),
                    Title = SettingsRepository.BlogName,
                    SharingEnabled = SettingsRepository.BlogSocialSharing,
                };

            if (newlyAdded)
            {
                postModel.UpdateStatus = true;
                postModel.IsNewPostOrPage = true;
            }

            return View(postModel);
        }
コード例 #8
0
ファイル: PostController.cs プロジェクト: rinckd/sblog.net
        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);
        }
コード例 #9
0
ファイル: PostController.cs プロジェクト: rinckd/sblog.net
 public ActionResult SaveAndRedirect(PostViewModel postModel)
 {
     SavePostInternal(postModel);
     return RedirectToAction("Edit", new { postID = postModel.Post.PostID });
 }
コード例 #10
0
        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);
        }
コード例 #11
0
ファイル: PageController.cs プロジェクト: LByron/BS
        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);
        }
コード例 #12
0
ファイル: PageController.cs プロジェクト: LByron/BS
        public ActionResult Edit(int postID, [DefaultValue(false)] bool newlyAdded)
        {
            ValidateActionRequest("Unauthorized attempt to edit the page");
            var post = _postRepository.GetPostByID(postID);

            var postModel = new PostViewModel
                                {
                                    Post = post,
                                    Title = SettingsRepository.BlogName,
                                    SharingEnabled = SettingsRepository.BlogSocialSharing
                                };

            if (newlyAdded)
            {
                postModel.UpdateStatus = true;
                postModel.IsNewPostOrPage = true;
            }

            return View(postModel);
        }