Beispiel #1
0
 public async Task <ContentEntry> GetContentById(Guid Id, int skipCount = 0, int pageSize = 20)
 {
     return(await ApiMessage.WrapData(async() =>
     {
         return await ContentAccessor.OneAsync <ContentEntry>(x => x.Id == Id, "MediaResource", "Category", "Category.ContentList");
     }));
 }
Beispiel #2
0
        public async Task CreateComment(Comment commentModel)
        {
            //向文章作者发送提示
            var _content = await ContentAccessor.OneAsync <ContentEntry>(x => x.Id == commentModel.ContentEntryId, "ContentEntryInfo");

            if (_content.ContentEntryInfo != null)
            {
                await sandBoxBusiness.SendAlertTo(new SandBoxMessage
                {
                    Content           = $"文章 : <a href='/Forum/PostList?Id={_content.Id}'>{_content.Title}</a> 有新的回复",
                    MessageType       = SandBoxMessageType.PostEntryComment,
                    CreateTime        = DateTime.Now,
                    FromUserAccountId = commentModel.UserAccountId.Value,
                    ToUserAccountId   = _content.ContentEntryInfo.UserAccountId
                });
            }

            //向引用回复作者发送提示
            if (commentModel.ParentComment != null)
            {
                await sandBoxBusiness.SendAlertTo(new SandBoxMessage
                {
                    Content           = $"文章 : <a href='/Forum/PostList?Id={_content.Id}'>{_content.Title}</a> 有新的回复",
                    MessageType       = SandBoxMessageType.PostEntryCommentSubComment,
                    CreateTime        = DateTime.Now,
                    FromUserAccountId = commentModel.UserAccountId.Value,
                    ToUserAccountId   = commentModel.ParentComment.UserAccountId.Value
                });
            }
            await ContentAccessor.Add <Comment>(commentModel);
        }
Beispiel #3
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="Id"></param>
 /// <param name="skipCount"></param>
 /// <param name="pageSize"></param>
 /// <returns>文章内容, 评论总数</returns>
 public async Task <Tuple <ContentEntry, int> > GetContentWityCommentById(Guid Id, int skipCount = 0, int pageSize = 20)
 {
     return(await ApiMessage.WrapData(async() =>
     {
         var contentEnry = await ContentAccessor.OneAsync <ContentEntry>(x => x.Id == Id, "MediaResource");
         var totalNum = await ContentAccessor.Count <Comment>(x => x.ContentEntryId == Id);
         return Tuple.Create(contentEnry, totalNum);
     }));
 }
Beispiel #4
0
        public async Task AppenContentMediaResource(Guid contentId, List <FileEntry> fileEntryList)
        {
            var content = await ContentAccessor.OneAsync <ContentEntry>(x => x.Id == contentId, "MediaResource");

            if (content.MediaResource == null)
            {
                content.MediaResource = new List <FileEntry> {
                };
            }
            content.MediaResource.AddRange(fileEntryList);

            await ContentAccessor.Update(content);
        }
Beispiel #5
0
 public async Task <string> GetPrevContentId(ContentEntry cEntry)
 {
     if (cEntry.Order == 0)
     {
         return(null);
     }
     else
     {
         return(await ApiMessage.WrapData(async() =>
         {
             var prevEntry = await ContentAccessor.OneAsync <ContentEntry>(x => x.Order == cEntry.Order - 1 && x.Category == cEntry.Category);
             return prevEntry.Id.ToString();
         }));
     }
 }
Beispiel #6
0
        public async Task CreateContentCommentExtPostEntry(Comment comment)
        {
            var contentModel = await ContentAccessor.OneAsync <ContentEntry>(x => x.Id == comment.ContentEntry.Id, "Category");

            var topicTxt = contentModel.Category.Name + "|" + contentModel.Title;
            //设置话题为漫画名
            var topic = new PostEntryTopic()
            {
                CreateTime = DateTime.Now,
                Id         = Guid.NewGuid(),
                Text       = topicTxt,
                PosterId   = comment.UserAccount.Id
            };
            var topicExt = new ContentExtPostEntryTopic()
            {
                Id        = Guid.NewGuid(),
                TopicText = topicTxt,
                LinkId    = contentModel.Id,
                LinkType  = "category"
            };
            //评论
            var postentryModel = new PostEntry()
            {
                Id             = Guid.NewGuid(),
                CreateTime     = DateTime.Now,
                PostEntryTopic = topicTxt,
                UserId         = comment.UserAccount.Id,
                TimeStamp      = TimeStamp.Get(),
                TextContent    = comment.Content
            };

            //目前是一条漫画评论对应一个话题, 为防止以后出现多话题, 保留此表
            var contentPostentryMapping = new ContentPostEntryMapping()
            {
                Id          = Guid.NewGuid(),
                ContentId   = contentModel.Id,
                PostEntryId = postentryModel.Id,
                CreateTime  = DateTime.Now
            };

            await ContentAccessor.Add(topic);

            await ContentAccessor.Add(topicExt);

            await ContentAccessor.Add(postentryModel);

            await ContentAccessor.Add(contentPostentryMapping);
        }
Beispiel #7
0
        //public Task CreateContentWithTag(ContentEntry contentEntry, string v1, string v2)
        //{
        //    throw new NotImplementedException();
        //}
        public async Task <ApiMessage> CreateContentWithTag(ContentEntry content, string tagName)
        {
            return(await ApiMessage.Wrap(async() =>
            {
                //var categoryEntity = await CategoryAccessor.OneAsync<Categories>(x => x.Name == tagName);
                //if (categoryEntity == null)
                //{
                //    categoryEntity = new Categories
                //    {
                //        Name = tagName,
                //        CreateTime = DateTime.Now,
                //        Id = Guid.NewGuid()
                //    };
                //    await CategoryAccessor.Add(categoryEntity);
                //}

                var contentEntry = await ContentAccessor.OneAsync <ContentEntry>(x => x.Id == content.Id);
                if (contentEntry == null)
                {
                    contentEntry = new ContentEntry
                    {
                        Id = Guid.NewGuid(),
                        CategoryId = content.CategoryId,
                        Content = content.Content,
                        CreateTime = DateTime.Now,
                        IsFaq = content.IsFaq,
                        IsTop = content.IsTop,
                        Title = content.Title,
                        Tags = new List <Tags> {
                            new Tags {
                                Name = tagName
                            }
                        }
                    };
                    await ContentAccessor.Add(contentEntry);
                }
                else
                {
                    contentEntry.CategoryId = content.CategoryId;
                    contentEntry.Content = content.Content;
                    contentEntry.IsFaq = content.IsFaq;
                    contentEntry.IsTop = content.IsTop;
                    contentEntry.Title = content.Title;
                    await ContentAccessor.Update(contentEntry);
                }
            }));
        }
Beispiel #8
0
        public async Task <string> GetNextContentId(ContentEntry cEntry)
        {
            var contentCountOfCategory = cEntry.Category.ContentList.Count;

            if (cEntry.Order + 1 == contentCountOfCategory)
            {
                return(null);
            }
            else
            {
                return(await ApiMessage.WrapData(async() =>
                {
                    var nextEntry = await ContentAccessor.OneAsync <ContentEntry>(x => x.Order == cEntry.Order + 1 && x.Category == cEntry.Category);
                    return nextEntry.Id.ToString();
                }));
            }
        }
Beispiel #9
0
        public async Task <ApiMessage> CreateContentWithCategory(ContentEntry content, string categoryName)
        {
            return(await ApiMessage.Wrap(async() =>
            {
                var categoryEntity = await CategoryAccessor.OneAsync <Categories>(x => x.Name == categoryName);
                if (categoryEntity == null)
                {
                    categoryEntity = new Categories
                    {
                        Name = categoryName,
                        CreateTime = DateTime.Now,
                        Id = Guid.NewGuid()
                    };
                    await CategoryAccessor.Add(categoryEntity);
                }

                var contentEntry = await ContentAccessor.OneAsync <ContentEntry>(x => x.Id == content.Id);
                if (contentEntry == null)
                {
                    contentEntry = new ContentEntry
                    {
                        Id = Guid.NewGuid(),
                        Category = categoryEntity,
                        Content = content.Content,
                        CreateTime = DateTime.Now,
                        IsFaq = content.IsFaq,
                        IsTop = content.IsTop,
                        Title = content.Title
                    };
                    await ContentAccessor.Add(contentEntry);
                }
                else
                {
                    contentEntry.Category = categoryEntity;
                    contentEntry.Content = content.Content;
                    contentEntry.IsFaq = content.IsFaq;
                    contentEntry.IsTop = content.IsTop;
                    contentEntry.Title = content.Title;
                    await ContentAccessor.Update(contentEntry);
                }
            }));
        }
Beispiel #10
0
        /// <summary>
        /// 阅读时写入用户阅读记录
        /// </summary>
        /// <param name="Id"></param>
        /// <param name="userId"></param>
        /// <param name="skipCount"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public async Task <ContentEntry> GetContentByIdSetLog(Guid Id, string userId, int skipCount = 0, int pageSize = 20)
        {
            return(await ApiMessage.WrapData(async() =>
            {
                var contentEntry = await ContentAccessor.OneAsync <ContentEntry>(x => x.Id == Id, "MediaResource", "Category", "Category.ContentList");

                if (!string.IsNullOrEmpty(userId))
                {
                    await ContentAccessor.Add(new ContentUserReadLog
                    {
                        CreateTime = DateTime.Now,
                        Id = Guid.NewGuid(),
                        Categories = contentEntry.Category,
                        UserId = Guid.Parse(userId),
                        ContentEntry = contentEntry
                    });
                }
                return contentEntry;
            }));
        }
Beispiel #11
0
        public async Task CreateMultiContent(Guid pid, string contentName, int count)
        {
            var category = await ContentAccessor.OneAsync <Categories>(x => x.Status != ContentStatus.Close && x.Id == pid);

            var contentList = new List <ContentEntry>();

            for (int i = 1; i <= count; i++)
            {
                contentList.Add(new ContentEntry
                {
                    Category   = category,
                    Title      = $"{contentName} 第{i}话",
                    Order      = i,
                    CreateTime = DateTime.Now,
                    Id         = Guid.NewGuid()
                });
            }
            await ContentAccessor.All <ContentEntry>().AddRangeAsync(contentList);

            await ContentAccessor.SaveAsync();
        }
Beispiel #12
0
 public async Task <ContentEntry> GetKnowledgeArticle(Guid Id)
 {
     return(await ContentAccessor.OneAsync <ContentEntry>(x => x.Id == Id));
 }
Beispiel #13
0
        public async Task CreateCategoryCommentExtPostEntry(CategoryComment comment)
        {
            var categoryModel = await ContentAccessor.OneAsync <Categories>(x => x.Status != ContentStatus.Close && x.Id == comment.CategoryId);

            //设置话题为漫画名
            var topic = new PostEntryTopic()
            {
                CreateTime = DateTime.Now,
                Id         = Guid.NewGuid(),
                Text       = categoryModel.Name,
                PosterId   = comment.UserAccountId
            };
            var topicExt = new ContentExtPostEntryTopic()
            {
                Id        = Guid.NewGuid(),
                TopicText = categoryModel.Name,
                LinkId    = categoryModel.Id,
                LinkType  = "category"
            };
            //评论
            var postentryModel = new PostEntry()
            {
                Id             = Guid.NewGuid(),
                CreateTime     = DateTime.Now,
                PostEntryTopic = categoryModel.Name,
                UserId         = comment.UserAccountId,
                TimeStamp      = TimeStamp.Get(),
                TextContent    = comment.Content,
            };

            //目前是一条漫画评论对应一个话题, 为防止以后出现多话题, 保留此表
            var categoryPostentryMapping = new CategoryPostEntryMapping()
            {
                Id          = Guid.NewGuid(),
                CategoryId  = categoryModel.Id,
                PostEntryId = postentryModel.Id,
                CreateTime  = DateTime.Now
            };

            await ContentAccessor.Add(topic);

            await ContentAccessor.Add(topicExt);

            await ContentAccessor.Add(postentryModel);

            await ContentAccessor.Add(categoryPostentryMapping);

            var sandBoxMsg = new SandBoxMessage()
            {
                Content           = $"您在漫画{topic}的回复,收到了新的评论.",
                CreateTime        = DateTime.Now,
                FromUserAccountId = comment.UserAccountId,
                ToUserAccountId   = postentryModel.UserId,
                Id           = Guid.NewGuid(),
                IsRead       = false,
                MessageType  = SandBoxMessageType.PostEntryComment,
                TimeStamp    = TimeStamp.Get(),
                RecieveToken = ""
            };
            await sandBoxBusiness.SendAlertTo(sandBoxMsg);
        }
Beispiel #14
0
 public async Task <Categories> GetCategoryByName(string name)
 {
     return(await ContentAccessor.OneAsync <Categories>(x => x.Name == name));
 }
Beispiel #15
0
        public async Task DeleteContent(Guid Id)
        {
            var contentEntry = await ContentAccessor.OneAsync <ContentEntry>(x => x.Id == Id, "Tags", "ContentEntryInfo", "Comments");

            await ContentAccessor.Delete <ContentEntry>(contentEntry);
        }
Beispiel #16
0
        public async Task <ContentEntry> CreateContentWithCategoryAndTag(ContentEntry content, string categoryName, string tag)
        {
            var categoryEntity = await CategoryAccessor.OneAsync <Categories>(x => x.Name == categoryName);

            if (categoryEntity == null)
            {
                categoryEntity = new Categories
                {
                    Name       = categoryName,
                    CreateTime = DateTime.Now,
                    Id         = Guid.NewGuid()
                };
                await CategoryAccessor.Add(categoryEntity);
            }

            var contentEntry = await ContentAccessor.OneAsync <ContentEntry>(x => x.Id == content.Id);



            if (contentEntry == null)
            {
                contentEntry = new ContentEntry
                {
                    Id         = Guid.NewGuid(),
                    Category   = categoryEntity,
                    Content    = content.Content,
                    CreateTime = DateTime.Now,
                    IsFaq      = content.IsFaq,
                    IsTop      = content.IsTop,
                    Title      = content.Title,
                    Tags       = new List <Tags> {
                        new Tags {
                            Name       = tag,
                            Id         = Guid.NewGuid(),
                            CreateTime = DateTime.Now
                        }
                    },
                    ContentEntryInfo = new ContentEntryInfo
                    {
                        Id            = content.ContentEntryInfo.Id,
                        Author        = content.ContentEntryInfo.Author,
                        Source        = content.ContentEntryInfo.Source,
                        Type          = content.ContentEntryInfo.Type,
                        UserAccountId = content.ContentEntryInfo.UserAccountId
                    }
                };
                await ContentAccessor.Add(contentEntry);

                //if (contentEntry.MediaResource == null)
                //{
                //    contentEntry.MediaResource = new List<FileEntry>();
                //}
                if (content.MediaResource != null)
                {
                    foreach (var item in content.MediaResource)
                    {
                        item.ContentEntryId = contentEntry.Id;
                    }

                    await ContentAccessor.UpdateRange(content.MediaResource);
                }

                ////var mediaResource = ContentAccessor.Entry(content.MediaResource);
                ////contentEntry.MediaResource = mediaResource;
                //await ContentAccessor.Update(contentEntry);
            }
            else
            {
                contentEntry.Category = categoryEntity;
                contentEntry.Content  = content.Content;
                contentEntry.IsFaq    = content.IsFaq;
                contentEntry.IsTop    = content.IsTop;
                contentEntry.Title    = content.Title;
                if (content.MediaResource != null)
                {
                    foreach (var item in content.MediaResource)
                    {
                        item.ContentEntryId = contentEntry.Id;
                    }

                    await ContentAccessor.UpdateRange(content.MediaResource);
                }
                //contentEntry.MediaResource = content.MediaResource;
                await ContentAccessor.Update(contentEntry);
            }

            return(contentEntry);
        }
Beispiel #17
0
 public async Task <ContentEntry> GetNewsDetail(Guid id)
 {
     return(await ContentAccessor.OneAsync <ContentEntry>(x => x.Id == id));
 }