public async Task <List <MaterialMessageItem> > GetAllAsync(int messageId)
        {
            var items = await _repository.GetAllAsync(Q
                                                      .Where(nameof(MaterialMessageItem.MessageId), messageId)
                                                      .OrderBy(nameof(MaterialMessageItem.Taxis))
                                                      .CachingGet(GetCacheKey(messageId))
                                                      );

            foreach (var item in items)
            {
                if (item.MaterialType == MaterialType.Article)
                {
                    var article = await _materialArticleRepository.GetAsync(item.MaterialId);

                    item.ThumbMediaId     = article.ThumbMediaId;
                    item.Author           = article.Author;
                    item.Title            = article.Title;
                    item.ContentSourceUrl = article.ContentSourceUrl;
                    item.Content          = article.Content;
                    item.Digest           = article.Digest;
                    item.ShowCoverPic     = article.ShowCoverPic;
                    item.ThumbUrl         = article.ThumbUrl;
                    item.CommentType      = article.CommentType;
                }
                //else if (item.MaterialType == MaterialType.Image)
                //{
                //    var image = await _materialImageRepository.GetAsync(item.MaterialId);
                //    item.Title = image.Title;
                //    item.ImageUrl = image.Url;
                //}
                //else if (item.MaterialType == MaterialType.Video)
                //{
                //    var video = await _materialVideoRepository.GetAsync(item.MaterialId);
                //    item.Title = video.Title;
                //}
                //else if (item.MaterialType == MaterialType.Audio)
                //{
                //    var audio = await _materialAudioRepository.GetAsync(item.MaterialId);
                //    item.Title = audio.Title;
                //}
                //else if (item.MaterialType == MaterialType.File)
                //{
                //    var file = await _materialFileRepository.GetAsync(item.MaterialId);
                //    item.Title = file.Title;
                //}
            }

            return(items);
        }
예제 #2
0
        public async Task <int> InsertAsync(int groupId, string mediaId, List <MaterialMessageItem> items)
        {
            var messageId = await _repository.InsertAsync(
                new MaterialMessage
            {
                GroupId = groupId,
                MediaId = mediaId
            },
                Q.CachingRemove(CacheKey)
                );

            var taxis = 1;

            foreach (var item in items)
            {
                var materialId = item.MaterialId;
                if (materialId > 0)
                {
                    var article = await _materialArticleRepository.GetAsync(materialId);

                    article.ThumbMediaId     = item.ThumbMediaId;
                    article.Author           = item.Author;
                    article.Title            = item.Title;
                    article.ContentSourceUrl = item.ContentSourceUrl;
                    article.Content          = item.Content;
                    article.Digest           = item.Digest;
                    article.ShowCoverPic     = item.ShowCoverPic;
                    article.ThumbUrl         = item.ThumbUrl;
                    article.CommentType      = item.CommentType;

                    await _materialArticleRepository.UpdateAsync(article);
                }
                else
                {
                    materialId = await _materialArticleRepository.InsertAsync(new MaterialArticle
                    {
                        GroupId          = groupId,
                        ThumbMediaId     = item.ThumbMediaId,
                        Author           = item.Author,
                        Title            = item.Title,
                        ContentSourceUrl = item.ContentSourceUrl,
                        Content          = item.Content,
                        Digest           = item.Digest,
                        ShowCoverPic     = item.ShowCoverPic,
                        ThumbUrl         = item.ThumbUrl,
                        CommentType      = item.CommentType
                    });
                }

                await _materialMessageItemRepository.InsertAsync(new MaterialMessageItem
                {
                    MessageId    = messageId,
                    MaterialType = MaterialType.Article,
                    MaterialId   = materialId,
                    Taxis        = taxis++
                });
            }

            await _repository.RemoveCacheAsync(CacheKey);

            return(messageId);
        }
예제 #3
0
 public async Task <ActionResult <MaterialArticle> > Get([FromQuery] int id)
 {
     return(await _materialArticleRepository.GetAsync(id));
 }