Esempio n. 1
0
        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);
        }
Esempio n. 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);
        }
Esempio n. 3
0
 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);
 }
Esempio n. 4
0
        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);
        }
Esempio n. 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;
        }
Esempio n. 6
0
        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);
        }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
        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);
        }
Esempio n. 9
0
 public ActionResult SaveAndRedirect(PostViewModel postModel)
 {
     SavePostInternal(postModel);
     return RedirectToAction("Edit", new { postID = postModel.Post.PostID });
 }
Esempio n. 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);
        }
Esempio n. 11
0
        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);
        }
Esempio n. 12
0
        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);
        }