public async Task <bool> AddItemAsync(BlogComment data) { data.DateCreated = DateTime.UtcNow; data.EntryIdentity = EntryIdentity; using (BlogEntryDataProvider entryDP = new BlogEntryDataProvider()) { BlogEntry entry = await entryDP.GetItemAsync(EntryIdentity); if (entry == null) { throw new InternalError("Entry with id {0} not found", EntryIdentity); } data.CategoryIdentity = entry.CategoryIdentity; } using (BlogCategoryDataProvider categoryDP = new BlogCategoryDataProvider()) { BlogCategory cat = await categoryDP.GetItemAsync(data.CategoryIdentity); if (cat == null) { throw new InternalError("Category {0} not found", data.CategoryIdentity); } if (cat.CommentApproval == BlogCategory.ApprovalType.None) { data.Approved = true; } else if (cat.CommentApproval == BlogCategory.ApprovalType.AnonymousUsers) { if (Manager.HaveUser) { data.Approved = true; } } } return(await DataProvider.AddAsync(data)); }
public async Task <MultiString> GetCategoryAsync() { using (BlogCategoryDataProvider categoryDP = new BlogCategoryDataProvider()) { BlogCategory blogCategory = await categoryDP.GetItemAsync(CategoryIdentity); if (blogCategory != null) { return(blogCategory.Category); } return(new MultiString()); } }
internal static async Task <string> GetCategoryCanonicalNameAsync(int blogCategory = 0) { using (BlogCategoryDataProvider categoryDP = new BlogCategoryDataProvider()) { BlogConfigData config = await BlogConfigDataProvider.GetConfigAsync(); string canon = config.BlogUrl; if (blogCategory != 0) { BlogCategory cat = await categoryDP.GetItemAsync(blogCategory); if (cat != null) { canon = string.Format("{0}/Title/{1}/?BlogCategory={2}", config.BlogUrl, Utility.UrlEncodeSegment(cat.Category.ToString().Truncate(80)), blogCategory); } } else { canon = config.BlogUrl; } return(canon); } }