/// <summary>
        /// 向数据源中添加帖子。
        /// </summary>
        /// <param name="dataFacade">数据源的外观。</param>
        /// <param name="indexEntity">帖子索引实体对象。</param>
        /// <param name="contentEntity">帖子内容对象。</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="dataFacade"/>为null
        ///     或
        ///     <paramref name="indexEntity"/>为null
        ///     或
        ///     <paramref name="contentEntity"/>为null
        /// </exception>
        /// <exception cref="DataFacadeException">数据源抛出了未经处理的异常</exception>
        public static async Task <int> AddPost(this IDataFacade dataFacade,
                                               PostEntity indexEntity, PostContentEntity contentEntity)
        {
            if (dataFacade == null)
            {
                throw new ArgumentNullException(nameof(dataFacade));
            }
            if (indexEntity == null)
            {
                throw new ArgumentNullException(nameof(indexEntity));
            }
            if (contentEntity == null)
            {
                throw new ArgumentNullException(nameof(contentEntity));
            }

            // 将内容实体对象插入到数据源中。
            await dataFacade.AddPostContentEntity(contentEntity);

            // 将帖子索引实体对象插入到数据源中。
            dataFacade.AddPostIndexEntity(indexEntity);
            await dataFacade.CommitChanges();

            return(indexEntity.Id);
        }
        /// <inheritdoc />
        public async Task AddPostContentEntity(PostContentEntity postContentEntity)
        {
            if (postContentEntity == null)
            {
                throw new ArgumentNullException(nameof(postContentEntity));
            }

            await AccessDataSource(async() => await _mongoDbContext.PostContents.InsertOneAsync(postContentEntity));
        }
        /// <inheritdoc />
        public (PostEntity IndexEntity, PostContentEntity ContentEntity) CreatePostEntities(
            int authorId, PostCreationInfo creationInfoModel)
        {
            if (creationInfoModel == null)
            {
                throw new ArgumentNullException(nameof(creationInfoModel));
            }

            var contentEntity = PostContentEntity.Create();

            contentEntity.Text = creationInfoModel.Text;

            var indexEntity = PostEntity.Create(authorId, creationInfoModel.RegionId, creationInfoModel.Title,
                                                contentEntity.Id.ToByteArray());

            return(indexEntity, contentEntity);
        }
Exemple #4
0
        /// <summary>
        /// 初始化 <see cref="PostListItem"/> 类的新实例。
        /// </summary>
        /// <param name="indexEntity">索引实体对象。</param>
        /// <param name="contentEntity">内容实体对象。</param>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="indexEntity"/>为null
        /// </exception>
        public PostListItem(PostEntity indexEntity, PostContentEntity contentEntity, bool voted)
        {
            if (indexEntity == null)
            {
                throw new ArgumentNullException(nameof(indexEntity));
            }

            Id               = indexEntity.Id;
            RegionId         = indexEntity.PostRegionId;
            Title            = indexEntity.Title;
            CreationTime     = indexEntity.CreationTime;
            UpdateTime       = indexEntity.UpdateTime;
            Text             = contentEntity?.Text ?? string.Empty;
            NumberOfImages   = contentEntity?.ImageIds.Length ?? 0;
            NumberOfVotes    = indexEntity.NumberOfVotes;
            NumberOfComments = indexEntity.NumberOfComments;
            IsVoted          = voted;
        }
Exemple #5
0
        /// <summary>
        /// 初始化 <see cref="PostInfo"/> 类的新实例。
        /// </summary>
        /// <param name="indexEntity">索引实体对象。</param>
        /// <param name="contentEntity">内容实体对象。</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="indexEntity"/>为null
        ///     或
        ///     <paramref name="contentEntity"/>为null
        /// </exception>
        public PostInfo(PostEntity indexEntity, PostContentEntity contentEntity, bool isVoted)
        {
            if (indexEntity == null)
            {
                throw new ArgumentNullException(nameof(indexEntity));
            }
            if (contentEntity == null)
            {
                throw new ArgumentNullException(nameof(contentEntity));
            }

            Title            = indexEntity.Title;
            Text             = contentEntity.Text;
            AuthorId         = indexEntity.AuthorId;
            CreationTime     = indexEntity.CreationTime;
            UpdateTime       = indexEntity.UpdateTime;
            NumberOfImages   = contentEntity.ImageIds.Length;
            NumberOfVotes    = indexEntity.NumberOfVotes;
            NumberOfComments = indexEntity.NumberOfComments;
            IsVoted          = isVoted;
        }
 /// <inheritdoc />
 public async Task AddPostContentEntity(PostContentEntity postContentEntity)
 {
     throw new System.NotImplementedException();
 }