コード例 #1
0
        public ActionResult EditSingleStaticPage(int id)
        {
            var        ops           = new BlogPostOperations();
            StaticPage newStaticPage = ops.GetStaticPageByID(id);

            return(View("EditSingleStaticPage", newStaticPage));
        }
コード例 #2
0
        //[Authorize(Roles = "PR")]
        public ActionResult AddBlogPost()
        {
            var ops = new BlogPostOperations();
            var vm  = new AddBlogPostViewModel(ops.GetAllCategories());

            return(View(vm)); // Author is currently being populated as the user identity email. Switch to username?
        }
コード例 #3
0
        public ActionResult EditStaticPage(StaticPage editedStaticPage)
        {
            var ops = new BlogPostOperations();

            ops.EditStaticPage(editedStaticPage);
            //what view should be returned?
            return(RedirectToAction("Index", "Home"));
        }
コード例 #4
0
        public ActionResult DeletePost(int id)
        {
            var ops = new BlogPostOperations();

            ops.DeletePost(id);

            return(RedirectToAction("Index", "Home"));
        }
コード例 #5
0
        public ActionResult EditPost(BlogPost editedPost)
        {
            var ops = new BlogPostOperations();

            ops.EditPost(editedPost);

            return(RedirectToAction("Index", "Home"));
        }
コード例 #6
0
        public ActionResult DisplayStaticPage(int id)
        {
            var ops           = new BlogPostOperations();
            var vm            = new HomeIndexViewModel();
            var newStaticPage = ops.GetStaticPageByID(id);

            return(View(newStaticPage));
        }
コード例 #7
0
        public ActionResult ApprovePost(int id)
        {
            var ops = new BlogPostOperations();

            ops.SetPostTo1(id);

            return(RedirectToAction("DisplayPostsWithStatus0"));
        }
コード例 #8
0
        public ActionResult EditPost(int id)
        {
            var ops = new BlogPostOperations();
            var vm  = new EditPostViewModel(ops.GetAllCategories());

            vm.BlogPost = ops.GetPostByID(id).FirstOrDefault();

            return(View(vm));
        }
コード例 #9
0
        public ActionResult EditStaticPage()
        {
            //need a list of static pages
            var ops = new BlogPostOperations();
            var vm  = new HomeIndexViewModel();

            vm.StaticPages = ops.GetAllStaticPages();

            return(View(vm));
        }
コード例 #10
0
        public ActionResult DisplayPostsWithStatus2()
        {
            var ops = new BlogPostOperations();
            var vm  = new HomeIndexViewModel();

            vm.BlogPosts   = ops.GetPostsWithStatus2();
            vm.Categories  = ops.GetAllCategories();
            vm.StaticPages = ops.GetAllStaticPages();

            return(View(vm));
        }
コード例 #11
0
        public ActionResult ListPostsByTag(int id)
        {
            var ops = new BlogPostOperations();
            var vm  = new HomeIndexViewModel();

            vm.BlogPosts   = ops.GetPostsByTagID(id);
            vm.Categories  = ops.GetAllCategories();
            vm.StaticPages = ops.GetAllStaticPages();

            return(View("Index", vm));
        }
コード例 #12
0
        public HttpResponseMessage Post(Category newCategory)
        {
            var ops = new BlogPostOperations();

            ops.AddCategory(newCategory);

            var response = Request.CreateResponse(HttpStatusCode.Created, newCategory);

            string uri = Url.Link("DefaultApi", new { id = newCategory.CategoryID });

            response.Headers.Location = new Uri(uri);

            return(response);
        }
コード例 #13
0
        public ActionResult AddUserComment(AddUserCommentViewModel vm)
        {
            var ops         = new BlogPostOperations();
            var userComment = new UserComment();

            userComment.UserCommentContent  = vm.UserCommentContent;
            userComment.UserCommentDate     = DateTime.Parse(vm.UserCommentDate);
            userComment.UserCommentUserName = vm.UserCommentUserName;


            ops.AddNewUserComment(userComment, vm.PostID);

            return(RedirectToAction("ListSinglePost", new { id = vm.PostID }));
        }
コード例 #14
0
        public ActionResult ListSinglePost(int id)
        {
            // Added a new view in order to view the whole post without the truncation from dotdotdot.
            // Also for viewing comments
            var ops = new BlogPostOperations();
            //var vm = new HomeIndexViewModel();
            var vm = new ListSinglePostViewModel();

            vm.BlogPost    = ops.GetPostByID(id).FirstOrDefault();
            vm.Categories  = ops.GetAllCategories();
            vm.StaticPages = ops.GetAllStaticPages();
            //vm.RouteID = ; can we use this to go back to the right routed page on the home index?

            return(View(vm));
        }
コード例 #15
0
ファイル: BlogTests.cs プロジェクト: samandmattea/projects
        public void ParseTagsTest()
        {
            var ops = new BlogPostOperations();

            string body = "This is a #test of how well my #METHOD parses #Tags.";

            string tagList = "here, Are more#tags # to# TEST #now";

            var result = ops.ParseTags(body, tagList);

            List <string> expected = new List <string> {
                "test", "METHOD", "Tags", "here", "Are", "more", "tags", "to", "TEST", "now"
            };

            Assert.AreEqual(expected, result);
        }
コード例 #16
0
        public ActionResult AddBlogEntry(BlogViewModel vm /*, IEnumerable<HttpPostedFileBase> images*/)
        {
            var repo = RepositoryFactory.CreateRepository();
            var ops  = new BlogPostOperations();

            var blog = new BlogEntry()
            {
                Title      = vm.Title,
                Body       = vm.Body,
                DateExpire = vm.ExpireDate,
                //Images = new List<Image>(),
                User       = repo.GetUserbyAspId(User.Identity.GetUserId()),
                IsApproved = User.IsInRole("Admin")
            };

            #region Commented-out, multi-image upload method
            //TODO: MULTI-IMAGE, EVENTUALLY
            //foreach (var img in images)
            //{
            //    if (img != null && img.ContentLength > 0 && img.ContentType.Contains("image"))
            //    {
            //        try
            //        {
            //            string path = Path.Combine(Server.MapPath("~/App_Data"), Path.GetFileName(img.FileName));
            //            img.SaveAs(path);
            //            blog.Images.Add(new Image {ImgPath = path});
            //        }
            //        catch (Exception ex)
            //        {
            //            ViewBag.Message = "ERROR:" + ex.Message.ToString();
            //        }
            //    }
            //}
            #endregion

            var tags = ops.ParseTags(vm.Body, vm.TagInput);
            foreach (var tag in tags)
            {
                blog.Tags.Add(new Tag {
                    Name = tag
                });
            }

            repo.AddBlogEntry(blog);

            return(RedirectToAction("Index", "Admin"));
        }
コード例 #17
0
        public ActionResult Index(int id = 0)
        {
            var ops = new BlogPostOperations();
            var vm  = new HomeIndexViewModel();

            //vm.BlogPosts = ops.GetBlogPosts();
            vm.Categories  = ops.GetAllCategories();
            vm.StaticPages = ops.GetAllStaticPages();
            // paging
            var posts = ops.GetBlogPosts();

            vm.PostTotal = posts.Count;
            vm.RouteID   = id;
            vm.BlogPosts = posts.Skip(id * 5).Take(5).ToList();

            return(View(vm));
        }
コード例 #18
0
        public ActionResult AddBlogPost(BlogPost blogPost)
        {
            var ops = new BlogPostOperations();

            if (User.IsInRole("Admin"))
            {
                // Admin add post, post goes to table with status of 1
                ops.AddNewBlogPost(blogPost);
                return(RedirectToAction("Index", "Home"));
            }
            if (User.IsInRole("PR"))
            {
                // PR add post, post goes to table with status of 0
                ops.PRAddNewBlogPost(blogPost);
                return(RedirectToAction("Index", "Home"));
            }

            // somehow a non-authenticated add. nothing goes to data. (necessary?)
            return(RedirectToAction("Index", "Home"));
        }
コード例 #19
0
        public List <Tag> Get()
        {
            var ops = new BlogPostOperations();

            return(ops.GetAllTags());
        }
コード例 #20
0
        public List <Category> Get()
        {
            var ops = new BlogPostOperations();

            return(ops.GetAllCategories());
        }