public PostIndexModelPost(Blog.Post post) { BlogDataDataContext database = new BlogDataDataContext(); Id = post.Id.ToString(); Title = post.Title.ToString(); Blog.User user = database.Users.FirstOrDefault(x => x.Id == post.Author); Author = new KeyValuePair <Guid, string>(user.Id, user.FirstName + " " + user.LastName); Dictionary <Guid, string> categoriesTemp = new Dictionary <Guid, string>(); List <Blog.PostCategoryMap> categoryMaps = database.PostCategoryMaps.Where(x => x.PostId == post.Id).ToList(); foreach (var categoryMap in categoryMaps) { Blog.PostCategory category = database.PostCategories.FirstOrDefault(x => x.Id == categoryMap.CategoryId); categoriesTemp.Add(category.Id, category.Name); } Categories = categoriesTemp; Dictionary <Guid, string> tagsTemp = new Dictionary <Guid, string>(); List <Blog.PostTagMap> tagMaps = database.PostTagMaps.Where(x => x.PostId == post.Id).ToList(); foreach (var tagMap in tagMaps) { Blog.PostTag tag = database.PostTags.FirstOrDefault(x => x.Id == tagMap.TagId); tagsTemp.Add(tag.Id, tag.Name); } Tags = tagsTemp; Comments = "0"; // todo: add comments table, and do a count of them here Timestamp = post.Timestamp.ToString(); }
public PostEditModel(Blog.Post post, string addOrEdit) { Id = post.Id; Title = post.Title; Body = post.Body; Author = post.Author; Timestamp = post.Timestamp.ToString(); CommentsEnabled = post.CommentsEnabled; Status = post.Status; Visibility = post.Visibility; FeaturedImage = post.FeaturedImage; Slug = post.Slug; AddOrEdit = addOrEdit; List <string> possibleStatusesTemp = new List <string>(); possibleStatusesTemp.Add("Draft"); possibleStatusesTemp.Add("Pending Review"); possibleStatusesTemp.Add("Published"); PossibleStatuses = possibleStatusesTemp; List <string> possibleVisibilitiesTemp = new List <string>(); possibleVisibilitiesTemp.Add("Public"); possibleVisibilitiesTemp.Add("Public Stickied"); possibleVisibilitiesTemp.Add("Password Protected"); possibleVisibilitiesTemp.Add("Private"); PossibleVisibilities = possibleVisibilitiesTemp; }
public static PostIndexTableRow PostToRow(Blog.Post post, BlogDataDataContext database) { PostIndexTableRow row = new PostIndexTableRow(); var commandButtonLeftHtml = ""; commandButtonLeftHtml += "<a href='Post/ViewId?id=" + post.Id + "' class='btn btn-default hl-view' style='margin-right: 3px;'><i class='fa fa-search'></i></span></a>"; commandButtonLeftHtml += "<a href='PostAdmin/Edit?id=" + post.Id + "' class='btn btn-default hl-view' style='margin-right: 3px;'><i class='fa fa-pencil'></i></span></a>"; commandButtonLeftHtml += "<div class='btn btn-default hl-view deletePostButton' postId='" + post.Id + "'><i class='fa fa-trash'></i></div>"; row.Id = commandButtonLeftHtml; row.Title = post.Title; row.Timestamp = post.Timestamp.ToString(); var databaseAuthor = database.Users.FirstOrDefault(x => x.Id == post.Author); if (databaseAuthor != null) { row.Author = databaseAuthor.PublicName; } string tagsTemp = ""; var databaseTagMaps = database.PostTagMaps.Where(x => x.PostId == post.Id); foreach (var tagMap in databaseTagMaps) { var databaseTag = database.PostTags.FirstOrDefault(x => x.Id == tagMap.TagId); tagsTemp += "<a href='" + "#" + "'>" + databaseTag.Name + "</a>, "; } row.Tags = tagsTemp; string categoriesTemp = ""; var databaseCategoryMaps = database.PostCategoryMaps.Where(x => x.PostId == post.Id); foreach (var categoryMap in databaseCategoryMaps) { var databaseCategory = database.PostCategories.FirstOrDefault(x => x.Id == categoryMap.CategoryId); categoriesTemp += "<a href='" + "#" + "'>" + databaseCategory.Name + "</a>, "; } row.Categories = categoriesTemp; row.Comments = database.PostCommentMaps.Count(x => x.PostId == post.Id).ToString(); return(row); }
public static PostEditModel PostEdit(string id) { BlogDataDataContext database = new BlogDataDataContext(); if (id.IsNullOrWhiteSpace()) { Blog.Post post = new Blog.Post(); post.Timestamp = DateTime.Now; PostEditModel model = new PostEditModel(post, "Add"); return(model); } else { Blog.Post post = database.Posts.FirstOrDefault(x => x.Id == new Guid(id)); PostEditModel model = new PostEditModel(post, "Edit"); return(model); } }
public static PostIndexTableModel FromPost(Blog.Post post, BlogDataDataContext database) { var model = new PostIndexTableModel(); var commandButtonLeftHtml = ""; commandButtonLeftHtml += "<a href='Post/ViewId?id=" + post.Id.ToString() + "' class='btn btn-default hl-view' style='margin-right: 3px;'><i class='fa fa-search'></i></span></a>"; commandButtonLeftHtml += "<a href='PostAdmin/Edit?id=" + post.Id.ToString() + "' class='btn btn-default hl-view' style='margin-right: 3px;'><i class='fa fa-pencil'></i></span></a>"; commandButtonLeftHtml += "<div class='btn btn-default hl-view deletePostButton' postId='" + post.Id.ToString() + "'><i class='fa fa-trash'></i></div>"; model.Id = commandButtonLeftHtml; model.Title = post.Title; model.Timestamp = post.Timestamp.ToString(); /* * var databaseAuthor = database.Users.FirstOrDefault(x => x.Id == post.Author); * if (databaseAuthor != null) * { * model.Author = databaseAuthor.PublicName; * }*/ /*string tagsTemp = ""; * var databaseTagMaps = database.PostTagMaps.Where(x => x.PostId == post.Id); * foreach (var tagMap in databaseTagMaps) * { * var databaseTag = database.PostTags.FirstOrDefault(x => x.Id == tagMap.TagId); * tagsTemp += "<a href='" + "#" + "'>" + databaseTag.Name + "</a>, "; * } * model.Tags = tagsTemp; */ /* * string categoriesTemp = ""; * var databaseCategoryMaps = database.PostCategoryMaps.Where(x => x.PostId == post.Id); * foreach (var categoryMap in databaseCategoryMaps) * { * var databaseCategory = database.PostCategories.FirstOrDefault(x => x.Id == categoryMap.CategoryId); * categoriesTemp += "<a href='" + "#" + "'>" + databaseCategory.Name + "</a>, "; * } * model.Categories = categoriesTemp; */ //model.Comments = database.PostCommentMaps.Count(x => x.PostId == post.Id).ToString(); return(model); }
public static PostHomeFeaturedPost PostToFeaturedPost(Blog.Post post, BlogDataDataContext database) { PostHomeFeaturedPost featuredPost = new PostHomeFeaturedPost(); string rootUrl = HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority + HttpContext.Current.Request.ApplicationPath.TrimEnd('/') + "/"; string postUrl = rootUrl + post.Slug; featuredPost.Title = post.Title; featuredPost.Url = postUrl; string imageUrl = Regex.Match(post.Body, "<img.+?src=[\"'](.+?)[\"'].*?>", RegexOptions.IgnoreCase).Groups[1].Value; if (!String.IsNullOrEmpty(imageUrl) && !String.IsNullOrWhiteSpace(imageUrl)) { featuredPost.FeaturedImageUrl = imageUrl; } return(featuredPost); }
public static Blog.Post PostEditPost(PostEditModel model) { BlogDataDataContext database = new BlogDataDataContext(); Blog.Post databaseModel = database.Posts.FirstOrDefault(x => x.Id == model.Id); if (databaseModel != null) { databaseModel.Title = model.Title; databaseModel.Body = model.Body; databaseModel.Author = new Guid("cebe8069-bd64-4dc9-8622-d3de189287b1"); // todo: get current user id databaseModel.Timestamp = Convert.ToDateTime(model.Timestamp); databaseModel.CommentsEnabled = model.CommentsEnabled; databaseModel.Status = model.Status; databaseModel.Visibility = model.Visibility; databaseModel.FeaturedImage = model.FeaturedImage; databaseModel.Slug = model.Slug; } else { databaseModel = new Blog.Post(); databaseModel.Id = Guid.NewGuid(); databaseModel.Title = model.Title; databaseModel.Body = model.Body; databaseModel.Author = new Guid("cebe8069-bd64-4dc9-8622-d3de189287b1"); // todo: get current user id databaseModel.Timestamp = Convert.ToDateTime(model.Timestamp); databaseModel.CommentsEnabled = model.CommentsEnabled; databaseModel.Status = model.Status; databaseModel.Visibility = model.Visibility; databaseModel.FeaturedImage = model.FeaturedImage; databaseModel.Slug = model.Slug; database.Posts.InsertOnSubmit(databaseModel); } database.SubmitChanges(); return(databaseModel); }
// todo: comments list public PostViewModel(Blog.Post post) { BlogDataDataContext database = new BlogDataDataContext(); Id = post.Id.ToString(); Title = post.Title; Body = post.Body; Blog.User user = database.Users.FirstOrDefault(x => x.Id == post.Author); Author = new KeyValuePair <Guid, string>(user.Id, user.FirstName + " " + user.LastName); Dictionary <Guid, string> categoriesTemp = new Dictionary <Guid, string>(); List <Blog.PostCategoryMap> categoryMaps = database.PostCategoryMaps.Where(x => x.PostId == post.Id).ToList(); foreach (var categoryMap in categoryMaps) { Blog.PostCategory category = database.PostCategories.FirstOrDefault(x => x.Id == categoryMap.CategoryId); categoriesTemp.Add(category.Id, category.Name); } Categories = categoriesTemp; Dictionary <Guid, string> tagsTemp = new Dictionary <Guid, string>(); List <Blog.PostTagMap> tagMaps = database.PostTagMaps.Where(x => x.PostId == post.Id).ToList(); foreach (var tagMap in tagMaps) { Blog.PostTag tag = database.PostTags.FirstOrDefault(x => x.Id == tagMap.TagId); tagsTemp.Add(tag.Id, tag.Name); } Tags = tagsTemp; Timestamp = post.Timestamp.ToString(); CommentsEnabled = post.CommentsEnabled; Status = post.Status; Visibility = post.Visibility; Slug = post.Slug; }
public static PostHomeTableRow PostToRow(Blog.Post post, BlogDataDataContext database) { PostHomeTableRow row = new PostHomeTableRow(); string rootUrl = HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority + HttpContext.Current.Request.ApplicationPath.TrimEnd('/') + "/"; string postUrl = rootUrl + post.Slug; var commandButtonLeftHtml = ""; commandButtonLeftHtml += "<a href='Post/ViewId?id=" + post.Id + "' class='btn btn-default hl-view' style='margin-right: 3px;'><i class='fa fa-search'></i></span></a>"; commandButtonLeftHtml += "<a href='PostAdmin/Edit?id=" + post.Id + "' class='btn btn-default hl-view' style='margin-right: 3px;'><i class='fa fa-pencil'></i></span></a>"; commandButtonLeftHtml += "<div class='btn btn-default hl-view deletePostButton' postId='" + post.Id + "'><i class='fa fa-trash'></i></div>"; row.Id = commandButtonLeftHtml; row.Title = "<a href='" + postUrl + "'>" + post.Title + "</a>"; row.Timestamp = post.Timestamp.ToString(); var databaseAuthor = database.Users.FirstOrDefault(x => x.Id == post.Author); if (databaseAuthor != null) { row.Author = databaseAuthor.PublicName; } var bodyText = ScrubHtml(post.Body); if (bodyText.Length > 300) { row.Body = bodyText.Substring(0, 300) + " ... <a href='" + postUrl + "'>[Read more...]</a>"; } else { row.Body = bodyText + " ... <a href='" + postUrl + "'>[Read more...]</a>"; } string tagsTemp = ""; var databaseTagMaps = database.PostTagMaps.Where(x => x.PostId == post.Id); foreach (var tagMap in databaseTagMaps) { var databaseTag = database.PostTags.FirstOrDefault(x => x.Id == tagMap.TagId); tagsTemp += "<a href='" + "#" + "'>" + databaseTag.Name + "</a>, "; } row.Tags = tagsTemp; string categoriesTemp = ""; var databaseCategoryMaps = database.PostCategoryMaps.Where(x => x.PostId == post.Id); foreach (var categoryMap in databaseCategoryMaps) { var databaseCategory = database.PostCategories.FirstOrDefault(x => x.Id == categoryMap.CategoryId); categoriesTemp += "<a href='" + "#" + "'>" + databaseCategory.Name + "</a>, "; } row.Categories = categoriesTemp; row.Comments = database.PostCommentMaps.Count(x => x.PostId == post.Id).ToString(); string imageUrl = Regex.Match(post.Body, "<img.+?src=[\"'](.+?)[\"'].*?>", RegexOptions.IgnoreCase).Groups[1].Value; if (!String.IsNullOrEmpty(imageUrl) && !String.IsNullOrWhiteSpace(imageUrl)) { row.FeaturedImage = "<div class='center-cropped-home'><a href='" + postUrl + "'><img src='" + imageUrl + "'/></a></div>"; } return(row); }