Esempio n. 1
0
        public ActionResult AddNewBlogPost(AddBlogPostVM newPost)
        {
            if (ModelState.IsValid)
            {

                newPost.BlogPost.User.UserName = User.Identity.GetUserName();
                newPost.BlogPost.TimeCreated = DateTime.Now;
                newPost.BlogPost.Status = PageStatus.Pending;

                if (User.IsInRole("Admin"))
                {
                    newPost.BlogPost.Status = PageStatus.Approved;
                }

                foreach (var ht in newPost.hashtags)
                {
                    var newTag = new Hashtag();
                    newTag.HashtagTitle = ht;
                    newPost.BlogPost.Hashtags.Add(newTag);
                }

                var post = _ops.AddNewBlogPost(newPost.BlogPost).BlogPost;

                return View("BlogPostDetails", post);

                //Ajax API call for confirmation modal
            }

            newPost.InitializeCategoriesList(_ops.GetAllCategories().Categories);

            return View(newPost);
        }
Esempio n. 2
0
        public ActionResult AddNewBlogPost()
        {
            var newBlogPostVM = new AddBlogPostVM();
            newBlogPostVM.BlogPost.User.Id = User.Identity.GetUserId();

            newBlogPostVM.InitializeCategoriesList(_ops.GetAllCategories().Categories);

            return View(newBlogPostVM);
        }
Esempio n. 3
0
        public ActionResult EditBlogPost(AddBlogPostVM vm)
        {
            if (ModelState.IsValid)
            {
                foreach (var ht in vm.hashtags)
                {
                    var newTag = new Hashtag();
                    newTag.HashtagTitle = ht;
                    vm.BlogPost.Hashtags.Add(newTag);
                }

                var oldHashtags = _jss.Serialize(_ops.GetHashtagsByBlogPostId(vm.BlogPost.BlogPostId).Hashtags.OrderBy(h => h.HashtagTitle).Select(h => h.HashtagTitle));

                var newHashtags = _jss.Serialize(vm.BlogPost.Hashtags.OrderBy(h => h.HashtagTitle).Select(h => h.HashtagTitle));

                if (oldHashtags != newHashtags)
                {
                    vm.BlogPost.HashtagsUpdated = true;
                }

                var blogPost = _ops.EditBlogPost(vm.BlogPost).BlogPost;

                return View("BlogPostDetails", blogPost);

            }

            vm.InitializeCategoriesList(_ops.GetAllCategories().Categories);

            return View(vm);
        }
Esempio n. 4
0
        public ActionResult EditBlogPost(int id)
        {
            var editVm = new AddBlogPostVM();
            editVm.BlogPost = _ops.GetBlogPostById(id).BlogPost;
            editVm.InitializeCategoriesList(_ops.GetAllCategories().Categories);

            return View(editVm);
        }