Exemplo n.º 1
0
        public ActionResult Add(PostViewModel postModel)
        {
            if (ModelState.IsValid)
            {
                if (postModel.AjaxSaved)
                {
                    return SaveAndRedirect(postModel);
                }

                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)
                {
                    if (Request.IsAjaxRequest())
                    {
                        var status = new PostOrPageSaveStatus { PostId = postId, IsValid = true };
                        return Json(status, JsonRequestBehavior.AllowGet);
                    }

                    return RedirectToAction("Edit", new {postID = postId, newlyAdded = true });
                }
            }

            if (Request.IsAjaxRequest())
            {
                var status = new PostOrPageSaveStatus { PostId = 0, IsValid = false };
                return Json(status, JsonRequestBehavior.AllowGet);
            }

            postModel.Title = SettingsRepository.BlogName;
            postModel.SharingEnabled = SettingsRepository.BlogSocialSharing;
            
            return View(postModel);
        }
Exemplo n.º 2
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);
        }