示例#1
0
        public ActionResult AddBlog()
        {
            // Create a new blog to be passed to the edit blog action
            Blog blog = new Blog
            {
                IsActive = false,
                Title    = "New Blog",
                Date     = DateTime.UtcNow,
                Tags     = new List <BlogTag> {
                    Utils.GetNewBlogTag()
                },
                BlogAuthor = Context.BlogUsers.First(usr => usr.UserId == 1) // This is anonymous and can't be deleted
            };

            var cat = Utils.GetUncategorizedCategory();

            blog.Category = cat;

            Context.Blogs.Add(blog);
            Context.SaveChanges();

            // Update the blog title / permalink with the new id we now have
            var blogId = blog.BlogId.ToString();

            blog.Title = blog.Title + " " + blogId;
            Context.SaveChanges();

            return(RedirectToAction("EditBlog", "Blog", new { id = blogId }));
        }
        public EditBlogViewModel(string blogId)
        {
            var utils = new BlogUtils(Context);

            BlogId   = Int32.Parse(blogId);
            _memUser = Membership.GetUser(HttpContext.Current.User.Identity.Name);
            SiteUrl  = HTTPUtils.GetFullyQualifiedApplicationPath() + "blog/";

            ThisBlog = Context.Blogs.FirstOrDefault(x => x.BlogId == BlogId);

            if (ThisBlog == null)
            {
                throw new KeyNotFoundException();
            }

            if (ThisBlog.Category == null)
            {
                ThisBlog.Category = utils.GetUncategorizedCategory();
            }

            // Make sure we have a permalink set
            if (String.IsNullOrEmpty(ThisBlog.PermaLink))
            {
                ThisBlog.PermaLink = ContentUtils.GetFormattedUrl(ThisBlog.Title);
                Context.SaveChanges();
            }

            // Get the list of Authors for the drop down select
            BlogUsers = Context.BlogUsers.Where(x => x.IsActive).OrderBy(x => x.DisplayName).ToList();

            Categories = Context.BlogCategories.Where(x => x.IsActive).ToList();

            UsersSelectedCategories = new List <string>();

            _thisUser = Context.Users.FirstOrDefault(x => x.Username == _memUser.UserName);

            // Get and parse tags for unqiue count
            var tagList = Context.Blogs.Select(x => x.Tags).ToList();
            var tagStr  = String.Join(",", tagList);
            var tags    = tagStr.Split(',').Select(x => x.Trim()).ToList();

            TagCounts = new List <TagMetric>();

            TagCounts = Context.BlogTags.Select(t => new TagMetric()
            {
                Tag   = t.BlogTagName,
                Count = t.Blogs.Count()
            }).ToList();

            BookmarkTitle = ThisBlog.Title;

            // Get the admin modules that will be displayed to the user in each column
            getAdminModules();
        }
示例#3
0
        public EditBlogViewModel(string blogId)
        {
            var utils = new BlogUtils(Context);
            BlogId = Int32.Parse(blogId);
            _memUser = Membership.GetUser(HttpContext.Current.User.Identity.Name);
            SiteUrl = HTTPUtils.GetFullyQualifiedApplicationPath() + "blog/";

            ThisBlog = Context.Blogs.FirstOrDefault(x => x.BlogId == BlogId);

            if (ThisBlog == null)
            {
               throw new KeyNotFoundException();
            }

            if (ThisBlog.Category == null)
            {
                ThisBlog.Category = utils.GetUncategorizedCategory();
            }

            // Make sure we have a permalink set
            if (String.IsNullOrEmpty(ThisBlog.PermaLink))
            {
                ThisBlog.PermaLink = ContentUtils.GetFormattedUrl(ThisBlog.Title);
                Context.SaveChanges();
            }

            // Get the list of Authors for the drop down select
            BlogUsers = Context.BlogUsers.Where(x => x.IsActive).OrderBy(x => x.DisplayName).ToList();

            Categories = Context.BlogCategories.Where(x => x.IsActive).ToList();

            UsersSelectedCategories = new List<string>();

            _thisUser = Context.Users.FirstOrDefault(x => x.Username == _memUser.UserName);

            // Get and parse tags for unqiue count
             var tagList = Context.Blogs.Select(x => x.Tags).ToList();
            var tagStr = String.Join(",", tagList);
            var tags = tagStr.Split(',').Select(x => x.Trim()).ToList();

            TagCounts = new List<TagMetric>();

            TagCounts = Context.BlogTags.Select(t => new TagMetric()
            {
                Tag = t.BlogTagName,
                Count = t.Blogs.Count()
            }).ToList();

            BookmarkTitle = ThisBlog.Title;

            // Get the admin modules that will be displayed to the user in each column
            getAdminModules();
        }
示例#4
0
        public JsonResult DeleteCategory(string id)
        {
            var result = new JsonResult()
            {
                Data = new
                {
                    success = false,
                    message = "There was an error processing your request."
                }
            };

            var success = 0;

            if (!String.IsNullOrEmpty(id))
            {
                int catId = Int32.Parse(id);

                var cat   = Context.BlogCategories.FirstOrDefault(x => x.CategoryId == catId);
                var uncat = utils.GetUncategorizedCategory();
                Context.SaveChanges();

                // did we find a category
                if (cat != null)
                {
                    // find all posts with this category and change to Uncategorized
                    foreach (var x in Context.Blogs.Where(x => x.Category.CategoryName == cat.CategoryName))
                    {
                        x.Category = uncat;
                    }

                    Context.BlogCategories.Remove(cat);
                    success = Context.SaveChanges();
                }
            }

            if (success > 0)
            {
                result.Data = new
                {
                    success = true,
                    message = "Category removed successfully. Blog posts changed: " + (success - 1)
                };
            }
            return(result);
        }