Esempio n. 1
0
        public NoteCommentContent AddCommentContent(NoteCommentContent commentContent)
        {
            try
            {
                if (commentContent == null)
                {
                    return(null);
                }

                DbParameter[] parameters = new DbParameter[]
                {
                    new SqlParameter()
                    {
                        ParameterName = SpParamsOfCommentContent.Sp_Insert_CommentContent_CommentId,
                        Value         = commentContent.CommentId
                    },
                    new SqlParameter()
                    {
                        ParameterName = SpParamsOfCommentContent.Sp_Insert_CommentContent_Type,
                        Value         = commentContent.Type
                    },
                    new SqlParameter()
                    {
                        ParameterName = SpParamsOfCommentContent.Sp_Insert_CommentContent_Content,
                        Value         = commentContent.Content
                    }
                };

                using (DataSet dataSet = DbHelper.Instance.RunProcedureGetDataSet(SpNamesOfCommentContent.Sp_Insert_CommentContent, parameters))
                {
                    CommentContentEntity entity = null;

                    if (dataSet != null && dataSet.Tables != null && dataSet.Tables.Count != 0 && dataSet.Tables[0].Rows != null && dataSet.Tables[0].Rows.Count != 0)
                    {
                        DataRow dataRow = dataSet.Tables[0].Rows[0];
                        DataColumnCollection dataColumns = dataSet.Tables[0].Columns;

                        entity = new CommentContentEntity()
                        {
                            Id         = (int)dataRow[dataColumns[0]],
                            CommentId  = (int)dataRow[dataColumns[1]],
                            Type       = (int)dataRow[dataColumns[2]],
                            Content    = (string)dataRow[dataColumns[3]],
                            CreateTime = (DateTime)dataRow[dataColumns[4]]
                        };
                    }

                    if (entity == null)
                    {
                        return(null);
                    }

                    return(entity.ToModel());
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 2
0
        public NoteCommentContent AddCommentContent(NoteCommentContent commentContent)
        {
            CommentContentEntity entity = commentContent.ToEntity();

            this.dbContext.CommentContents.Add(entity);
            this.dbContext.SaveChanges();
            return(entity.ToModel());
        }
Esempio n. 3
0
        /// <inheritdoc />
        public async Task AddCommentContentEntity(CommentContentEntity contentEntity)
        {
            if (contentEntity == null)
            {
                throw new ArgumentNullException(nameof(contentEntity));
            }

            await AccessDataSource(async() => await _mongoDbContext.CommentContents.InsertOneAsync(contentEntity));
        }
Esempio n. 4
0
 public static NoteCommentContent ToModel(this CommentContentEntity entity)
 {
     return(new NoteCommentContent()
     {
         Id = entity.Id,
         CommentId = entity.CommentId,
         Type = entity.Type,
         CreateTime = entity.CreateTime,
         Content = entity.Content
     });
 }
Esempio n. 5
0
        public List <NoteCommentContent> GetCommentContentByCommentId(int commentId)
        {
            try
            {
                if (commentId <= 0)
                {
                    return(null);
                }

                DbParameter[] parameters = new DbParameter[]
                {
                    new SqlParameter()
                    {
                        ParameterName = SpParamsOfCommentContent.Sp_Select_CommentContentByCommentId_CommentId,
                        Value         = commentId
                    }
                };

                using (DataSet dataSet = DbHelper.Instance.RunProcedureGetDataSet(SpNamesOfCommentContent.Sp_Select_CommentContentByCommentId, parameters))
                {
                    List <NoteCommentContent> commentContents = new List <NoteCommentContent>();

                    if (dataSet != null && dataSet.Tables != null && dataSet.Tables.Count != 0 && dataSet.Tables[0].Rows != null && dataSet.Tables[0].Rows.Count != 0)
                    {
                        DataRowCollection    dataRows    = dataSet.Tables[0].Rows;
                        DataColumnCollection dataColumns = dataSet.Tables[0].Columns;

                        foreach (DataRow dataRow in dataRows)
                        {
                            CommentContentEntity entity = new CommentContentEntity()
                            {
                                Id         = (int)dataRow[dataColumns[0]],
                                CommentId  = (int)dataRow[dataColumns[1]],
                                Type       = (int)dataRow[dataColumns[2]],
                                Content    = (string)dataRow[dataColumns[3]],
                                CreateTime = (DateTime)dataRow[dataColumns[4]]
                            };

                            commentContents.Add(entity.ToModel());
                        }
                    }

                    return(commentContents);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        /// <summary>
        /// 向数据源添加评论索引实体对象及其对应的内容实体对象。
        /// </summary>
        /// <param name="dataFacade"></param>
        /// <param name="indexEntity">要添加的索引实体对象。</param>
        /// <param name="contentEntity">要添加的内容实体对象。</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="indexEntity"/>为null
        ///     或
        ///     <paramref name="contentEntity"/>为null
        /// </exception>
        public static async Task AddPostComment(this IDataFacade dataFacade,
                                                CommentEntity indexEntity, CommentContentEntity contentEntity)
        {
            if (indexEntity == null)
            {
                throw new ArgumentNullException(nameof(indexEntity));
            }
            if (contentEntity == null)
            {
                throw new ArgumentNullException(nameof(contentEntity));
            }

            dataFacade.AddCommentIndexEntity(indexEntity);
            await dataFacade.CommitChanges();

            await dataFacade.AddCommentContentEntity(contentEntity);
        }
Esempio n. 7
0
        /// <summary>
        /// 初始化 <see cref="PostCommentInfo"/> 类的新实例。
        /// </summary>
        /// <param name="indexEntity">索引实体对象。</param>
        /// <param name="contentEntity">内容实体对象。</param>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="indexEntity"/>为null
        ///     或
        ///     <paramref name="contentEntity"/>为null
        /// </exception>
        public PostCommentInfo(CommentEntity indexEntity, CommentContentEntity contentEntity)
        {
            if (indexEntity == null)
            {
                throw new ArgumentNullException(nameof(indexEntity));
            }
            if (contentEntity == null)
            {
                throw new ArgumentNullException(nameof(contentEntity));
            }

            Id           = indexEntity.Id;
            AuthorId     = indexEntity.AuthorId;
            CreationTime = indexEntity.CreationTime;
            Text         = contentEntity.Text;
            Comments     = new List <PostCommentInfo>();
        }
Esempio n. 8
0
        /// <summary>
        /// 初始化 <see cref="UserCommentInfo"/> 类的新实例。
        /// </summary>
        /// <param name="indexEntity">评论索引实体对象。</param>
        /// <param name="contentEntity">评论内容实体对象。</param>
        /// <param name="postId">评论所属帖子 ID。</param>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="indexEntity"/>为null
        ///     或
        ///     <paramref name="contentEntity"/>为null
        ///     或
        ///     <paramref name="postEntity"/>为null
        /// </exception>
        public UserCommentInfo(CommentEntity indexEntity, CommentContentEntity contentEntity, PostEntity postEntity)
        {
            if (indexEntity == null)
            {
                throw new ArgumentNullException(nameof(indexEntity));
            }
            if (contentEntity == null)
            {
                throw new ArgumentNullException(nameof(contentEntity));
            }
            if (postEntity == null)
            {
                throw new ArgumentNullException(nameof(postEntity));
            }

            Id           = indexEntity.Id;
            AuthorId     = indexEntity.AuthorId;
            PostId       = postEntity.Id;
            PostTitle    = postEntity.Title;
            CreationTime = indexEntity.CreationTime;
            Text         = contentEntity.Text;
        }
Esempio n. 9
0
 /// <inheritdoc />
 public async Task AddCommentContentEntity(CommentContentEntity contentEntity)
 {
     throw new System.NotImplementedException();
 }
Esempio n. 10
0
        public NoteCommentContent GetCommentContentById(int id)
        {
            CommentContentEntity entity = this.dbContext.CommentContents.FirstOrDefault(cc => cc.Id == id);

            return(entity == null ? null : entity.ToModel());
        }