public CategorySingleViewModel LoadBlogsByCategory(String category) { var catModel = new CategorySingleViewModel(); category = ContentUtils.GetFormattedUrl(category); catModel.AllBlogsInCategory = _context.Blogs.Where(x => x.Category.CategoryNameFormatted == category && x.IsActive) .OrderByDescending(blog => blog.Date) .ToList(); catModel.BlogRoll = catModel.AllBlogsInCategory .Take(catModel.MaxBlogCount) .ToList(); catModel.TheCategory = _context.BlogCategories.FirstOrDefault(x => x.CategoryNameFormatted == category); var model = new BlogListModel(_context); catModel.MaxBlogCount = model.GetBlogSettings().MaxBlogsOnHomepageBeforeLoad; catModel.SkipBlogs = catModel.MaxBlogCount; catModel.BlogTitle = model.GetBlogSettings().BlogTitle; catModel.BlogsByCat = catModel.AllBlogsInCategory .Take(catModel.MaxBlogCount) .ToList(); return(catModel); }
public CategorySingleViewModel(string category, HttpServerUtilityBase server) { _server = server; category = ContentUtils.GetFormattedUrl(category); AllBlogsInCategory = Context.Blogs.Where(x => x.Category.CategoryNameFormatted == category && x.IsActive) .OrderByDescending(blog => blog.Date) .ToList(); BlogRoll = AllBlogsInCategory .Take(MaxBlogCount) .ToList(); TheCategory = Context.BlogCategories.FirstOrDefault(x => x.CategoryNameFormatted == category); var model = new BlogListModel(Context); MaxBlogCount = model.GetBlogSettings().MaxBlogsOnHomepageBeforeLoad; SkipBlogs = MaxBlogCount; BlogTitle = model.GetBlogSettings().BlogTitle; BlogsByCat = AllBlogsInCategory .Take(MaxBlogCount) .ToList(); }
public static void SetAutomapperMappings() { Mapper.CreateMap <PageDetails, ContentPage>() .ForAllMembers(p => p.Condition(c => !c.IsSourceValueNull)); Mapper.CreateMap <ContentPage, PageDetails>(); Mapper.CreateMap <ContentPageComplete, ContentPageExtension>() .ForAllMembers(p => p.Condition(c => !c.IsSourceValueNull)); Mapper.CreateMap <ContentPageExtension, ContentPageComplete>() .ForAllMembers(p => p.Condition(c => !c.IsSourceValueNull)); Mapper.CreateMap <Module, ContentModule>().ReverseMap(); Mapper.CreateMap <Settings, SiteSettings>(); Mapper.CreateMap <BlogController.EditBlogModel, Blog>() .ForMember(dest => dest.Category, opts => opts.Ignore()) .ForMember(dest => dest.Tags, opts => opts.Ignore()) .ForMember(dest => dest.Title, opts => opts.MapFrom(src => ContentUtils.ScrubInput(src.Title))) .ForMember(dest => dest.ImageUrl, opts => opts.MapFrom(src => ContentUtils.ScrubInput(src.ImageUrl))) .ForMember(dest => dest.PermaLink, opts => opts.MapFrom(src => ContentUtils.GetFormattedUrl(src.PermaLink))); }
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(); }
/// <summary> /// If no title or category, could be just listing page. /// If no title, but category is set, probably a category listing page /// If title and category are set, individual blog. /// </summary> /// <param name="title"></param> /// <param name="category"></param> /// <param name="date"></param> /// <returns>View</returns> public ActionResult Index(string title, string category, string date) { // Blog Listing Homepage if (String.IsNullOrEmpty(title) && String.IsNullOrEmpty(category)) { var model = new BlogHomeViewModel(date); return(View("~/Views/Home/Blog.cshtml", model)); } // Category if (String.IsNullOrEmpty(title)) { // Category var cats = Context.BlogCategories.ToList().Select(x => ContentUtils.GetFormattedUrl(x.CategoryName)); if (cats.Contains(category)) { var model = new CategorySingleViewModel(category, Server); return(View("~/Views/Blog/CategoriesSingle.cshtml", model)); } // Not a blog category or tags page HttpContext.Response.StatusCode = 404; return(View("~/Views/Home/Error404.cshtml")); } // Tag if (category == "tags" && !string.IsNullOrEmpty(title)) { var model = new TagSingleViewModel(title); return(View("~/Views/Blog/TagSingle.cshtml", model)); } // Blog User if (category == "user" && !string.IsNullOrEmpty(title)) { var model = new BlogsByUserViewModel(title); return(View("~/Views/Blog/BlogsByUser.cshtml", model)); } // Category is set and we are trying to view an individual blog var blog = Context.Blogs.FirstOrDefault(x => x.PermaLink == title); if (blog != null) { var theModel = new BlogSingleHomeViewModel(title); return(View("~/Views/Home/BlogSingle.cshtml", theModel)); } // Not a blog category or a blog HttpContext.Response.StatusCode = 404; return(View("~/Views/Home/Error404.cshtml")); }
public BlogSingleHomeViewModel LoadSingleBlog(String title) { var model = new BlogSingleHomeViewModel { TheBlog = _context.Blogs.FirstOrDefault(x => x.PermaLink == title) }; // If no go then try title as a final back up if (model.TheBlog == null) { title = title.Replace(ContentGlobals.BLOGDELIMMETER, " "); model.TheBlog = _context.Blogs.FirstOrDefault(x => x.Title == title); if (model.TheBlog == null) { return(model); } // Go ahead and set the permalink for future reference if (String.IsNullOrEmpty(model.TheBlog.PermaLink)) { model.TheBlog.PermaLink = ContentUtils.GetFormattedUrl(model.TheBlog.Title); _context.SaveChanges(); } } model.RelatedPosts = new BlogRelatedViewModel(model.TheBlog.Title); model.TheBlogUser = _context.BlogUsers.FirstOrDefault(x => x.UserId == model.TheBlog.AuthorId); model.BlogAuthorModel = new BlogAuthorViewModel(model.TheBlog.BlogAuthor.Username); model.ShowFacebookLikeButton = _settingsUtils.ShowFbLikeButton(); model.ShowFacebookComments = _settingsUtils.ShowFbComments(); model.BlogAbsoluteUrl = HttpContext.Current.Request.Url.AbsoluteUri; model.UseDisqusComments = _settingsUtils.UseDisqusComments(); if (model.UseDisqusComments) { model.DisqusShortName = _settingsUtils.DisqusShortName(); } model.Categories = GetActiveBlogCategories(); return(model); }
public EventSingleHomeViewModel(string title) { // Try permalink first TheEvent = Context.Events.FirstOrDefault(x => x.PermaLink == title); // If no go then try title as a final back up if (TheEvent == null) { title = title.Replace(ContentGlobals.BLOGDELIMMETER, " "); TheEvent = Context.Events.FirstOrDefault(x => x.Title == title); // Go ahead and set the permalink for future reference TheEvent.PermaLink = ContentUtils.GetFormattedUrl(TheEvent.Title); Context.SaveChanges(); } // Absolute Url for FB Like Button EventAbsoluteUrl = HttpContext.Current.Request.Url.AbsoluteUri; }
protected void SetContentPageData(ref ContentPage editedContent, ContentPage entity, bool isRevision, bool isBasic, DateTime?publishDate) { if (isRevision) { editedContent.IsRevision = true; editedContent.ParentContentPageId = entity.ContentPageId; } else { editedContent.IsRevision = false; } if (!isBasic) { editedContent.JSContent = entity.JSContent; editedContent.CSSContent = entity.CSSContent; } editedContent.DraftAuthorName = UserUtils.CurrentMembershipUsername(); editedContent.DisplayName = ContentUtils.ScrubInput(entity.DisplayName); editedContent.Permalink = ContentUtils.GetFormattedUrl(entity.Permalink); editedContent.HTMLContent = entity.HTMLContent; editedContent.HTMLUnparsed = entity.HTMLUnparsed; editedContent.SchemaId = entity.SchemaId; editedContent.SchemaEntryValues = entity.SchemaEntryValues; editedContent.Template = entity.Template; editedContent.Title = entity.Title; editedContent.WasPublished = publishDate.HasValue; editedContent.PublishDate = publishDate ?? DateTime.UtcNow; // SEO Related Info editedContent.MetaDescription = entity.MetaDescription; editedContent.OGTitle = entity.OGTitle; editedContent.OGImage = entity.OGImage; editedContent.OGType = entity.OGType; editedContent.OGUrl = entity.OGUrl; editedContent.Canonical = entity.Canonical; editedContent.NoIndex = entity.NoIndex; editedContent.NoFollow = entity.NoFollow; editedContent.ParentNavigationItemId = entity.ParentNavigationItemId; }
public JsonResult AddCategory(string name) { var result = new JsonResult() { Data = new { success = false, message = "There was an error processing your request." } }; var success = 0; int theId = 0; if (!String.IsNullOrEmpty(name)) { var newCategory = new BlogCategory { CategoryName = name, CreateDate = DateTime.UtcNow, IsActive = true, CategoryNameFormatted = ContentUtils.GetFormattedUrl(name) }; Context.BlogCategories.Add(newCategory); success = Context.SaveChanges(); theId = newCategory.CategoryId; } if (success > 0) { result.Data = new { success = true, message = "Category added successfully.", id = theId }; } return(result); }
public EditEventViewModel(string eventId) { EventId = Int32.Parse(eventId); _memUser = Membership.GetUser(HttpContext.Current.User.Identity.Name); SiteUrl = HTTPUtils.GetFullyQualifiedApplicationPath() + "event/"; ThisEvent = Context.Events.FirstOrDefault(x => x.EventId == EventId); // Make sure we have a permalink set if (String.IsNullOrEmpty(ThisEvent.PermaLink)) { ThisEvent.PermaLink = ContentUtils.GetFormattedUrl(ThisEvent.Title); } EventCategories = Context.EventCategories.Where(x => x.IsActive == true).ToList(); UsersSelectedCategories = new List <string>(); _thisUser = Context.Users.FirstOrDefault(x => x.Username == _memUser.UserName); // Get the admin modules that will be displayed to the user in each column getAdminModules(); }
public BlogSingleHomeViewModel(string title) { // Try permalink first TheBlog = Context.Blogs.FirstOrDefault(x => x.PermaLink == title); // If no go then try title as a final back up if (TheBlog == null) { title = title.Replace(ContentGlobals.BLOGDELIMMETER, " "); TheBlog = Context.Blogs.FirstOrDefault(x => x.Title == title); // Go ahead and set the permalink for future reference TheBlog.PermaLink = ContentUtils.GetFormattedUrl(TheBlog.Title); Context.SaveChanges(); } // Set up the Related Posts Module RelatedPosts = new BlogRelatedViewModel(TheBlog.Title); // Get User based on authorid TheBlogUser = Context.BlogUsers.FirstOrDefault(x => x.UserId == TheBlog.AuthorId); BlogAuthorModel = new BlogAuthorViewModel(TheBlog.BlogAuthor.Username); // Facebook Like button ShowFacebookLikeButton = SettingsUtils.ShowFbLikeButton(); // Facebook Comments ShowFacebookComments = SettingsUtils.ShowFbComments(); // Absolute Url for FB Like Button BlogAbsoluteUrl = HttpContext.Current.Request.Url.AbsoluteUri; // Disqus Comments UseDisqusComments = SettingsUtils.UseDisqusComments(); if (UseDisqusComments) { DisqusShortName = SettingsUtils.DisqusShortName(); } // Tag Listing Tags = new List <string>(); foreach (var tag in TheBlog.Tags) { Tags.Add(tag.BlogTagName); } // Full Category Listing Categories = new List <BlogsCategoriesViewModel.BlogCatExtraData>(); var cats = Context.BlogCategories.Where(x => x.IsActive).ToList(); foreach (var cat in cats) { int count = Context.Blogs.Count(x => x.Category.CategoryId == cat.CategoryId); Categories.Add(new BlogsCategoriesViewModel.BlogCatExtraData() { TheCategory = cat, BlogCount = count }); } }
public JsonResult ModifyBlog(EditBlogModel entity) { if (String.IsNullOrEmpty(entity.Title)) { return(new JsonResult { Data = new { success = false, message = "Your post must have a title" } }); } var editedBlog = Context.Blogs.FirstOrDefault(x => x.BlogId == entity.BlogId); if (editedBlog == null) { return(JsonErrorResult); } // Straight copies from the model editedBlog.AuthorId = entity.AuthorId; editedBlog.HtmlContent = entity.HtmlContent; editedBlog.IsActive = entity.IsActive; editedBlog.IsFeatured = entity.IsFeatured; editedBlog.ShortDesc = entity.ShortDesc; editedBlog.Date = entity.Date; // Meta editedBlog.Canonical = entity.Canonical; editedBlog.OGImage = entity.OGImage; editedBlog.OGTitle = entity.OGTitle; editedBlog.OGType = entity.OGType; editedBlog.OGUrl = entity.OGUrl; editedBlog.MetaDescription = entity.MetaDescription; // Cleaned inpuit editedBlog.Title = ContentUtils.ScrubInput(entity.Title); editedBlog.ImageUrl = ContentUtils.ScrubInput(entity.ImageUrl); editedBlog.PermaLink = ContentUtils.GetFormattedUrl(entity.PermaLink); // Database Nav property mappings editedBlog.Category = utils.GetCategoryOrUncategorized(entity.Category); editedBlog.BlogAuthor = Context.BlogUsers.First(usr => usr.UserId == entity.AuthorId); if (editedBlog.Tags == null) { editedBlog.Tags = new List <BlogTag>(); } if (!String.IsNullOrEmpty(entity.Tags)) { foreach (var tag in entity.Tags.Split(',')) { editedBlog.Tags.Add(utils.GetOrCreateTag(tag)); } } var success = Context.SaveChanges(); CachedObjects.GetCacheContentPages(true); BookmarkUtil.UpdateTitle("/admin/pages/editblog/" + editedBlog.BlogId + "/", entity.Title); if (success > 0) { return(new JsonResult { Data = new { success = true, message = "Blog saved successfully.", id = entity.BlogId } }); } return(JsonErrorResult); }