Пример #1
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);
        }
Пример #2
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);
                }
            }));
        }
Пример #3
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);
                }
            }));
        }
Пример #4
0
 public async Task UpdateKnowledgeArticle(ContentEntry contentEntry)
 {
     await ContentAccessor.Update(contentEntry);
 }
Пример #5
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);
        }