public String CreateLabel(String blogGuid, String title) { using (DataContext db = new DataContext(ServiceConfiguration.ConnectionString)) { //+ ensure blog exists BlogLINQ blogLinq; Validator.EnsureBlogExists(blogGuid, out blogLinq, db); //+ LabelLINQ labelLinq; String labelGuid; labelLinq = db.Labels.SingleOrDefault(p => p.BlogId == blogLinq.BlogId && p.LabelTitle == title); if (labelLinq != null) { labelGuid = labelLinq.LabelGuid; } else { labelLinq = new LabelLINQ(); labelLinq.LabelTitle = title; labelLinq.BlogId = blogLinq.BlogId; labelLinq.LabelGuid = Themelia.GuidCreator.GetNewGuid(); db.Labels.InsertOnSubmit(labelLinq); //+ db.SubmitChanges(); labelGuid = labelLinq.LabelGuid; } //+ return(labelGuid); } }
public List <Comment> GetCommentList(String blogEntryGuid, Boolean showEveryComment) { String commentGuid = String.Empty; using (DataContext db = new DataContext(ServiceConfiguration.ConnectionString)) { //+ validate BlogEntryLINQ blogEntryLinq; Validator.EnsureBlogEntryExists(blogEntryGuid, out blogEntryLinq, db); //+ Func <CommentLINQ, Boolean> commentStatus; if (showEveryComment) { commentStatus = p => true; } else { commentStatus = p => p.CommentModerated == false; } return(blogEntryLinq.Comments.Where(commentStatus) .Select(p => new Comment { Text = p.CommentText, DateTime = p.CommentPostDate, Website = p.CommentWebsite, Guid = p.CommentGuid, Email = p.CommentEmail, Name = p.CommentAuthor }).ToList()); } }
public BlogMetaData GetBlogMetaData(String blogGuid) { using (DataContext db = new DataContext(ServiceConfiguration.ConnectionString)) { //+ ensure blog exists BlogLINQ blogLinq; Validator.EnsureBlogExists(blogGuid, out blogLinq, db); //+ return(new BlogMetaData { Description = blogLinq.BlogDescription, FeedTitle = blogLinq.BlogFeedTitle, FeedUri = new Uri(blogLinq.BlogFeedUrl), Guid = blogLinq.BlogGuid, Title = blogLinq.BlogTitle, Uri = new Uri(blogLinq.BlogPrimaryUrl), CreateDateTime = blogLinq.BlogCreateDate, LabelList = new List <Label>( blogLinq.Labels.Select(p => new Label { Guid = p.LabelGuid, FriendlyTitle = p.LabelFriendlyTitle, Title = p.LabelTitle }) ) }); } }
//- $GetBlogEntryByUrlMapping -// private BlogEntryLINQ GetBlogEntryByUrlMapping(Int32 blogId, String link, DataContext db) { return((from be in db.BlogEntries join beum in db.BlogEntryUrlMappings on be.BlogEntryId equals beum.BlogEntryId where beum.BlogEntryUrlMappingName == link.ToLower() && be.BlogId == blogId select be).FirstOrDefault()); }
//- @GetBlogEntryListByDateRange -// public List <BlogEntry> GetBlogEntryListByDateRange(String blogGuid, DateTime startDateTime, DateTime endDateTime, Boolean ignoreFooter, Boolean metaDataOnly) { using (DataContext db = new DataContext(ServiceConfiguration.ConnectionString)) { //+ ensure blog exists BlogLINQ blogLinq; Validator.EnsureBlogExists(blogGuid, out blogLinq, db); //+ Func <BlogEntryLINQ, BlogEntry> blogEntryTransformation = be => new BlogEntry { Title = be.BlogEntryTitle, Content = metaDataOnly ? String.Empty : CheckFooter(ignoreFooter, be.BlogEntryText), Guid = be.BlogEntryGuid, Status = be.BlogEntryStatusId, BlogEntryTypeGuid = be.BlogEntryType.BlogEntryTypeGuid, AllowCommentStatus = (AllowCommentStatus)be.BlogEntryCommentAllowStatusId, PostDateTime = be.BlogEntryPostDateTime, ModifyDateTime = be.BlogEntryModifyDateTime, MappingNameList = new List <String>( be.BlogEntryUrlMappings.Select(p => p.BlogEntryUrlMappingName) ), LabelList = new List <Label>( be.LabelBlogEntries.Select(p => new Label { Guid = p.Label.LabelGuid, FriendlyTitle = p.Label.LabelFriendlyTitle, Title = p.Label.LabelTitle }) ), AuthorList = new List <Author>( be.BlogEntryAuthors.Select(p => new Author { Name = p.Author.AuthorName, Email = p.Author.AuthorEmail }) ), CommentList = metaDataOnly ? new List <Comment>() : new List <Comment>( be.Comments.Where(p => p.CommentModerated == false) .Select(p => new Comment { Text = p.CommentText, DateTime = p.CommentPostDate, Website = p.CommentWebsite, Guid = p.CommentGuid, Email = p.CommentEmail, Name = p.CommentAuthor }) ) }; //+ Func <BlogEntryLINQ, Boolean> blogEntryListInRange = be => be.BlogId == blogLinq.BlogId && (be.BlogEntryStatusId == 1 || be.BlogEntryStatusId == 4) && (be.BlogEntryPostDateTime >= startDateTime && be.BlogEntryPostDateTime <= endDateTime); //+ return(db.BlogEntries.Where(blogEntryListInRange) .Select(blogEntryTransformation) .OrderByDescending(be => be.PostDateTime) .ToList()); } }
public BlogEntry GetSingleBlogEntryByLink(String blogGuid, String link, Boolean ignoreFooter, Boolean metaDataOnly) { using (DataContext db = new DataContext(ServiceConfiguration.ConnectionString)) { //+ ensure blog entry exists BlogLINQ blogLinq; Validator.EnsureBlogExists(blogGuid, out blogLinq, db); //+ BlogEntryLINQ blogEntryLinq = this.GetBlogEntryByUrlMapping(blogLinq.BlogId, link, db); if (blogEntryLinq != null) { return(new BlogEntry { Title = blogEntryLinq.BlogEntryTitle, Content = metaDataOnly ? String.Empty : CheckFooter(ignoreFooter, blogEntryLinq.BlogEntryText), Guid = blogEntryLinq.BlogEntryGuid, Status = blogEntryLinq.BlogEntryStatusId, BlogEntryTypeGuid = blogEntryLinq.BlogEntryType.BlogEntryTypeGuid, AllowCommentStatus = (AllowCommentStatus)blogEntryLinq.BlogEntryCommentAllowStatusId, PostDateTime = blogEntryLinq.BlogEntryPostDateTime, ModifyDateTime = blogEntryLinq.BlogEntryModifyDateTime, MappingNameList = new List <String>( blogEntryLinq.BlogEntryUrlMappings.Select(p => p.BlogEntryUrlMappingName) ), LabelList = new List <Label>( blogEntryLinq.LabelBlogEntries.Select(p => new Label { Guid = p.Label.LabelGuid, FriendlyTitle = p.Label.LabelFriendlyTitle, Title = p.Label.LabelTitle }) ), AuthorList = new List <Author>( blogEntryLinq.BlogEntryAuthors.Select(p => new Author { Name = p.Author.AuthorName, Email = p.Author.AuthorEmail }) ), CommentList = metaDataOnly ? new List <Comment>() : new List <Comment>( blogEntryLinq.Comments.Where(p => p.CommentModerated == false) .Select(p => new Comment { Text = p.CommentText, DateTime = p.CommentPostDate, Website = p.CommentWebsite, Guid = p.CommentGuid, Email = p.CommentEmail, Name = p.CommentAuthor }) ) }); } //+ return(null); } }
public void PingTechnorati(String blogGuid) { using (DataContext db = new DataContext(ServiceConfiguration.ConnectionString)) { //+ ensure blog entry exists BlogLINQ blogLinq; Validator.EnsureBlogExists(blogGuid, out blogLinq, db); //+ TechnoratiNotifier.Ping(blogLinq.BlogTitle, new Uri(blogLinq.BlogPrimaryUrl)); } }
public void UpdateLabel(String labelGuid, String title) { using (DataContext db = new DataContext(ServiceConfiguration.ConnectionString)) { //+ ensure label exists LabelLINQ labelLinq; Validator.EnsureLabelExists(labelGuid, out labelLinq, db); //+ labelLinq.LabelTitle = title; //+ db.SubmitChanges(); } }
public void DeleteComment(String commentGuid) { using (DataContext db = new DataContext(ServiceConfiguration.ConnectionString)) { //+ validate CommentLINQ commentLinq; Validator.EnsureCommentExists(commentGuid, out commentLinq, db); //+ db.Comments.DeleteOnSubmit(commentLinq); //+ db.SubmitChanges(); } }
public void DisableBlogEntry(String blogEntryGuid) { using (DataContext db = new DataContext(ServiceConfiguration.ConnectionString)) { //+ ensure blog entry exists BlogEntryLINQ blogEntryLinq; Validator.EnsureBlogEntryExists(blogEntryGuid, out blogEntryLinq, db); //+ blogEntryLinq.BlogEntryStatusId = 2; //+ db.SubmitChanges(); } }
public void AuthorizeComment(String commentGuid) { using (DataContext db = new DataContext(ServiceConfiguration.ConnectionString)) { //+ validate CommentLINQ commentLinq; Validator.EnsureCommentExists(commentGuid, out commentLinq, db); //+ commentLinq.CommentModerated = false; //+ db.SubmitChanges(); } }
public void UpdateAuthor(String authorEmail, String authorName) { using (DataContext db = new DataContext(ServiceConfiguration.ConnectionString)) { //+ ensure author exists AuthorLINQ authorLinq; Validator.EnsureAuthorExists(authorEmail, out authorLinq, db); //+ authorLinq.AuthorName = authorName; //+ db.SubmitChanges(); } }
//- ~ByLabelGuid -// internal static String ByLabelGuid(String labelGuid) { using (MinimaServiceLINQDataContext db = new MinimaServiceLINQDataContext(ServiceConfiguration.ConnectionString)) { DataLoadOptions options = new DataLoadOptions(); options.LoadWith <LabelLINQ>(p => p.Blog); db.LoadOptions = options; //+ ensure blog exists LabelLINQ labelLinq; Validator.EnsureLabelExists(labelGuid, out labelLinq, db); //+ return(labelLinq.Blog.BlogGuid); } }
//- ~ByBlogImageGuid -// internal static String ByBlogImageGuid(String blogImageGuid) { using (MinimaServiceLINQDataContext db = new MinimaServiceLINQDataContext(ServiceConfiguration.ConnectionString)) { DataLoadOptions options = new DataLoadOptions(); options.LoadWith <BlogImageLINQ>(p => p.Blog); db.LoadOptions = options; //+ ensure blog exists BlogImageLINQ blogImageLinq; Validator.EnsureBlogImageExists(blogImageGuid, out blogImageLinq, db); //+ return(blogImageLinq.Blog.BlogGuid); } }
//- ~ValidateUserNameAndPassword -// internal static void ValidateUserNameAndPassword(String userName, String password) { using (MinimaServiceLINQDataContext db = new MinimaServiceLINQDataContext(ServiceConfiguration.ConnectionString)) { String authorEmail = userName; //+ validate AuthorLINQ authorLinq; Validator.EnsureAuthorExists(authorEmail, out authorLinq, db); //+ if (authorLinq == null || authorLinq.AuthorPassword != password) { throw new SecurityException(Message.Invalid); } } }
public List <ArchiveCount> GetArchivedEntryList(String blogGuid) { using (DataContext db = new DataContext(ServiceConfiguration.ConnectionString)) { //+ ensure blog exists BlogLINQ blogLinq; Validator.EnsureBlogExists(blogGuid, out blogLinq, db); //+ return(db.GetArchivedEntryList(blogLinq.BlogId).Select(p => new ArchiveCount { ArchiveDate = DateTime.Parse(p.Month), Count = (Int32)p.Count }).ToList()); } }
//- ~ByCommentGuid -// internal static String ByCommentGuid(String commentGuid) { using (MinimaServiceLINQDataContext db = new MinimaServiceLINQDataContext(ServiceConfiguration.ConnectionString)) { DataLoadOptions options = new DataLoadOptions(); options.LoadWith <CommentLINQ>(p => p.BlogEntry); options.LoadWith <BlogEntryLINQ>(p => p.Blog); db.LoadOptions = options; //+ CommentLINQ commentLinq; Validator.EnsureCommentExists(commentGuid, out commentLinq, db); //+ return(commentLinq.BlogEntry.Blog.BlogGuid); } }
public BlogImage GetImage(String blogImageGuid) { using (DataContext db = new DataContext(ServiceConfiguration.ConnectionString)) { //+ ensure blog image exists BlogImageLINQ blogImageLinq; Validator.EnsureBlogImageExists(blogImageGuid, out blogImageLinq, db); //+ Binary imageBinary = blogImageLinq.BlogImageData; //+ return(new BlogImage { ContentType = blogImageLinq.BlogImageContentType, Data = imageBinary.ToArray() }); } }
public void RemoveAuthor(String blogEntryGuid, String authorEmail) { using (DataContext db = new DataContext(ServiceConfiguration.ConnectionString)) { //+ validate BlogEntryLINQ blogEntryLinq; Validator.EnsureBlogEntryExists(blogEntryGuid, out blogEntryLinq, db); AuthorLINQ authorLinq; Validator.EnsureAuthorExists(authorEmail, out authorLinq, db); //+ BlogEntryAuthorLINQ blogEntryAuthorLinq = db.BlogEntryAuthors.SingleOrDefault(p => p.AuthorId == authorLinq.AuthorId && p.BlogEntryId == blogEntryLinq.BlogEntryId); if (blogEntryAuthorLinq == null) { db.BlogEntryAuthors.DeleteOnSubmit(blogEntryAuthorLinq); db.SubmitChanges(); } } }
public List <Label> GetBlogEntryLabelList(String blogEntryGuid) { using (DataContext db = new DataContext(ServiceConfiguration.ConnectionString)) { //+ validate BlogEntryLINQ blogEntryLinq; Validator.EnsureBlogEntryExists(blogEntryGuid, out blogEntryLinq, db); //+ return(blogEntryLinq.LabelBlogEntries.Select(p => new Label { BlogEntryCount = -1, Title = p.Label.LabelTitle, Guid = p.Label.LabelGuid, BlogGuid = p.BlogEntry.Blog.BlogGuid, FriendlyTitle = p.Label.LabelFriendlyTitle }).ToList()); } }
public void RemoveLabel(String labelGuid, String blogEntryGuid) { using (DataContext db = new DataContext(ServiceConfiguration.ConnectionString)) { //+ validate BlogEntryLINQ blogEntryLinq; Validator.EnsureBlogEntryExists(blogEntryGuid, out blogEntryLinq, db); LabelLINQ labelLinq; Validator.EnsureLabelExists(labelGuid, out labelLinq, db); //+ LabelBlogEntryLINQ labelBlogEntryLinq = db.LabelBlogEntries.SingleOrDefault(p => p.LabelId == labelLinq.LabelId && p.BlogEntryId == blogEntryLinq.BlogEntryId); if (labelBlogEntryLinq != null) { db.LabelBlogEntries.DeleteOnSubmit(labelBlogEntryLinq); db.SubmitChanges(); } } }
//- ~ValidateSystemPermission -// internal static void ValidateSystemPermission(BlogPermission blogPermission) { Char databasePermissionCode = GetDatabasePermissionCode(blogPermission); //+ using (MinimaServiceLINQDataContext db = new MinimaServiceLINQDataContext(ServiceConfiguration.ConnectionString)) { String authorEmail = OperationContext.Current.ServiceSecurityContext.PrimaryIdentity.Name; //+ validate AuthorLINQ authorLinq; Validator.EnsureAuthorExists(authorEmail, out authorLinq, db); //+ if (!authorLinq.UserRights.Any(ur => ur.UserRightLevel == PermissionLevel.System && ur.UserRightType == databasePermissionCode)) { throw new SecurityException(Message.Invalid); } } }
public String PostNewComment(String blogEntryGuid, String text, String author, String email, String website, DateTime dateTime, String emailBodyTemplate, String emailSubject) { String commentGuid = String.Empty; String blogEntryTitle = String.Empty; using (DataContext db = new DataContext(ServiceConfiguration.ConnectionString)) { //+ validate BlogEntryLINQ blogEntryLinq; Validator.EnsureBlogEntryExists(blogEntryGuid, out blogEntryLinq, db); //+ CommentLINQ commentLinq = new CommentLINQ(); commentLinq.CommentEmail = email; commentLinq.CommentAuthor = author; commentLinq.CommentText = text; if (website.ToLower().StartsWith("http://") || website.ToLower().StartsWith("https://")) { commentLinq.CommentWebsite = website; } commentLinq.CommentPostDate = dateTime; commentLinq.CommentModerated = true; commentLinq.BlogEntryId = blogEntryLinq.BlogEntryId; commentLinq.CommentGuid = Themelia.GuidCreator.GetNewGuid(); //+ db.Comments.InsertOnSubmit(commentLinq); db.SubmitChanges(); //+ commentGuid = commentLinq.CommentGuid; //+ blogEntryTitle = blogEntryLinq.BlogEntryTitle; } //+ email Themelia.Map map = new Themelia.Map(); map.Add("BlogEntryTitle", blogEntryTitle); map.Add("CommentGuid", commentGuid); String body = new Themelia.Template(emailBodyTemplate).Interpolate(map); //+ this could be sent from the person, but those e-mails will more than likely be caught by a spam filter. Emailer.Send(MailConfiguration.GeneralFromEmailAddress, MailConfiguration.GeneralToEmailAddress, emailSubject, body, MailOptions.IsHtml); //+ return(commentGuid); }
public List <Label> GetBlogLabelList(String blogGuid) { using (DataContext db = new DataContext(ServiceConfiguration.ConnectionString)) { //+ ensure blog exists BlogLINQ blogLinq; Validator.EnsureBlogExists(blogGuid, out blogLinq, db); //+ return(blogLinq.Labels .Where(p => p.BlogId == blogLinq.BlogId) .Select(p => new Label { BlogGuid = blogLinq.BlogGuid, Guid = p.LabelGuid, FriendlyTitle = p.LabelFriendlyTitle, Title = p.LabelTitle, BlogEntryCount = GetEntryCount(p, db) }).ToList()); } }
public void ApplyLabel(String blogEntryGuid, String labelGuid) { using (DataContext db = new DataContext(ServiceConfiguration.ConnectionString)) { //+ ensure blog exists BlogEntryLINQ blogEntryLinq; Validator.EnsureBlogEntryExists(blogEntryGuid, out blogEntryLinq, db); LabelLINQ labelLinq; Validator.EnsureLabelExists(labelGuid, out labelLinq, db); //+ if (!db.LabelBlogEntries.Any(p => p.LabelId == labelLinq.LabelId && p.BlogEntryId == blogEntryLinq.BlogEntryId)) { LabelBlogEntryLINQ labelBlogEntryLinq = new LabelBlogEntryLINQ(); labelBlogEntryLinq.BlogEntryId = blogEntryLinq.BlogEntryId; labelBlogEntryLinq.LabelId = labelLinq.LabelId; //+ db.LabelBlogEntries.InsertOnSubmit(labelBlogEntryLinq); db.SubmitChanges(); } } }
public void ApplyAuthor(String blogEntryGuid, String authorEmail) { using (DataContext db = new DataContext(ServiceConfiguration.ConnectionString)) { //+ validate BlogEntryLINQ blogEntryLinq; Validator.EnsureBlogEntryExists(blogEntryGuid, out blogEntryLinq, db); AuthorLINQ authorLinq; Validator.EnsureAuthorExists(authorEmail, out authorLinq, db); //+ if (!db.BlogEntryAuthors.Any(p => p.AuthorId == authorLinq.AuthorId && p.BlogEntryId == blogEntryLinq.BlogEntryId)) { BlogEntryAuthorLINQ blogEntryAuthorLinq = new BlogEntryAuthorLINQ(); blogEntryAuthorLinq.AuthorId = authorLinq.AuthorId; blogEntryAuthorLinq.BlogEntryId = blogEntryLinq.BlogEntryId; //+ db.BlogEntryAuthors.InsertOnSubmit(blogEntryAuthorLinq); db.SubmitChanges(); } } }
public String CreateAuthor(String authorEmail, String authorName) { using (DataContext db = new DataContext(ServiceConfiguration.ConnectionString)) { String authorGuid = String.Empty; if (!db.Authors.Any(p => p.AuthorEmail == authorEmail)) { AuthorLINQ authorLinq = new AuthorLINQ(); authorLinq.AuthorEmail = authorEmail; authorLinq.AuthorName = authorName; authorLinq.AuthorGuid = Themelia.GuidCreator.GetNewGuid(); authorLinq.AuthorCreateDate = DateTime.Now; //+ db.Authors.InsertOnSubmit(authorLinq); db.SubmitChanges(); //+ authorGuid = authorLinq.AuthorGuid; } //+ return(authorGuid); } }
//- @GetBlogEntryTypeList -// public List <BlogEntryType> GetBlogEntryTypeList(String blogGuid, List <String> guidList) { using (DataContext db = new DataContext(ServiceConfiguration.ConnectionString)) { List <BlogEntryType> blogEntryTypeList = new List <BlogEntryType>(); var blogEntryData = db.BlogEntryTypes.Select(p => p); foreach (BlogEntryTypeLINQ blogEntryTypeLinq in blogEntryData) { if (guidList.Contains(blogEntryTypeLinq.BlogEntryTypeGuid)) { blogEntryTypeList.Add(new BlogEntryType { Extra = blogEntryTypeLinq.BlogEntryTypeExtra, Name = blogEntryTypeLinq.BlogEntryTypeName, Guid = blogEntryTypeLinq.BlogEntryTypeGuid }); } } //+ return(blogEntryTypeList); } }
//- @GetLabelByNetTitle-// public Label GetLabelByNetTitle(String netTitle) { using (DataContext db = new DataContext(ServiceConfiguration.ConnectionString)) { DataLoadOptions options = new DataLoadOptions(); options.LoadWith <LabelLINQ>(p => p.Blog); LabelLINQ labelLinq = db.Labels.SingleOrDefault(p => p.LabelNetTitle == netTitle); if (labelLinq == null) { return(null); } //+ return(new Label { BlogGuid = labelLinq.Blog.BlogGuid, FriendlyTitle = labelLinq.LabelFriendlyTitle, Guid = labelLinq.LabelGuid, Title = labelLinq.LabelTitle, BlogEntryCount = GetEntryCount(labelLinq, db) }); } }
public List <BlogMetaData> GetBlogListForAssociatedAuthor(String authorEmail) { using (DataContext db = new DataContext(ServiceConfiguration.ConnectionString)) { //+ ensure blog exists AuthorLINQ authorLinq; Validator.EnsureAuthorExists(authorEmail, out authorLinq, db); //+ List <Int32> blogEntryIdList = db.AuthorBlogAssociations .Where(p => p.AuthorId == authorLinq.AuthorId) .Select(p => p.BlogId) .ToList(); List <BlogMetaData> blogMetaDataList = new List <BlogMetaData>(); foreach (Int32 blogId in blogEntryIdList) { BlogMetaData blogMetaData = new BlogMetaData(); BlogLINQ blogLinq = db.Blogs.Single(p => p.BlogId == blogId); blogMetaData.Description = blogLinq.BlogDescription; blogMetaData.FeedTitle = blogLinq.BlogFeedTitle; blogMetaData.FeedUri = new Uri(blogLinq.BlogFeedUrl); blogMetaData.Guid = blogLinq.BlogGuid; blogMetaData.Title = blogLinq.BlogTitle; blogMetaData.Uri = new Uri(blogLinq.BlogPrimaryUrl); blogMetaData.CreateDateTime = blogLinq.BlogCreateDate; blogMetaData.LabelList = new List <Label>( blogLinq.Labels.Select(p => new Label { Guid = p.LabelGuid, FriendlyTitle = p.LabelFriendlyTitle, Title = p.LabelTitle }) ); blogMetaDataList.Add(blogMetaData); } //+ return(blogMetaDataList); } }