Пример #1
0
        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));
        }
Пример #2
0
 public async Task <bool> RemoveItemAsync(int identity)
 {
     if (!await DataProvider.RemoveAsync(identity))
     {
         return(false);
     }
     using (BlogEntryDataProvider entryDP = new BlogEntryDataProvider()) {
         await entryDP.RemoveEntriesAsync(identity);// remove all entries for this category
     }
     return(true);
 }
        public static async Task <string> GetEntryCanonicalNameAsync(int blogEntry)
        {
            BlogConfigData config = await BlogConfigDataProvider.GetConfigAsync();

            string canon = string.Format("{0}/?BlogEntry={1}", config.BlogEntryUrl, blogEntry);

            using (BlogEntryDataProvider entryDP = new BlogEntryDataProvider()) {
                BlogEntry data = await entryDP.GetItemAsync(blogEntry);

                if (data != null)
                {
                    canon = string.Format("{0}/Title/{1}/?BlogEntry={2}", config.BlogEntryUrl, Utility.UrlEncodeSegment(data.Title.ToString().Truncate(80)), blogEntry);
                }
                return(canon);
            }
        }