Ejemplo n.º 1
0
        /// <summary>
        /// Saves an entity.
        /// </summary>
        /// <param name="entity">The resource entity to save.</param>
        /// <param name="cancellationToken">The optional token to monitor for cancellation requests.</param>
        /// <returns>The changing result information.</returns>
        public override async Task <ChangingResultInfo> SaveAsync(BlogCommentEntity entity, CancellationToken cancellationToken = default)
        {
            if (entity == null)
            {
                return(new ChangingResultInfo(ChangeErrorKinds.Argument, EntityNullTips));
            }
            if (string.IsNullOrWhiteSpace(UserId))
            {
                return(new ChangingResultInfo(ChangeErrorKinds.Unauthorized, LoginErrorTips));
            }
            if (string.IsNullOrWhiteSpace(entity.PublisherId) && entity.IsNew)
            {
                entity.PublisherId = UserId;
            }
            try
            {
                var result = await DataProvider.SaveAsync(entity, cancellationToken);

                if (ResourceEntityExtensions.IsSuccessful(result))
                {
                    return(new ChangingResultInfo <BlogCommentEntity>(result, entity, result.ToString() + " blog comment entity."));
                }
                return(result);
            }
            catch (Exception ex)
            {
                var err = ResourceEntityExtensions.TryCatch(ex);
                if (err != null)
                {
                    return(err);
                }
                throw;
            }
        }
        /// <summary>
        /// 添加博客信息
        /// </summary>
        public int Add(BlogCommentEntity blogCommentEntity)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into BlogComment(");
            strSql.Append("BCID, BlogID, BCContent , CommentBy, CommentTime, Memo, CreatedBy, CreatedTime, ModifiedBy, ModifiedTime)");
            strSql.Append(" values (");
            strSql.Append("@BCID, @BlogID, @BCContent, @CommentBy, @CommentTime, @Memo, @CreatedBy, @CreatedTime,@ModifiedBy, @ModifiedTime)");

            using (var connection = ConnectionFactory.GetOpenConnection(ConnStr))
            {
                var param = new DynamicParameters();
                param.Add("@BCID", blogCommentEntity.BCID, dbType: DbType.String);
                param.Add("@BlogID", blogCommentEntity.BlogID, dbType: DbType.String);
                param.Add("@BCContent", blogCommentEntity.BCContent, dbType: DbType.String);
                param.Add("@CommentBy", blogCommentEntity.CommentBy, dbType: DbType.String);
                param.Add("@CommentTime", blogCommentEntity.CommentTime, dbType: DbType.DateTime);
                param.Add("@Memo", blogCommentEntity.Memo, dbType: DbType.String);
                param.Add("@CreatedBy", blogCommentEntity.CreatedBy, dbType: DbType.String);
                param.Add("@CreatedTime", blogCommentEntity.CreatedTime, dbType: DbType.DateTime);
                param.Add("@ModifiedBy", blogCommentEntity.ModifiedBy, dbType: DbType.String);
                param.Add("@ModifiedTime", blogCommentEntity.ModifiedTime, dbType: DbType.DateTime);
                int i = connection.Execute(strSql.ToString(), param);
                return(i);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 编辑博客评论
        /// </summary>
        /// <param name="sBlogID"></param>
        /// <returns></returns>
        public IActionResult Update(string sBCID)
        {
            BlogCommentEntity m = null;

            if (!string.IsNullOrEmpty(sBCID))
            {
                m = blogCommentDAL.GetBlogCommentByBCID(sBCID);
            }
            return(View(m));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 获取所有的博客列表信息
        /// </summary>
        /// <returns></returns>
        public IActionResult Index(string sBlogID)
        {
            List <BlogCommentEntity> blogcommentlist = new List <BlogCommentEntity>();
            BlogCommentEntity        blogcomment     = new BlogCommentEntity();
            Hashtable has = new Hashtable();

            blogcommentlist    = blogCommentDAL.GetBlogCommentByBlogID(sBlogID);
            blogcomment.BlogID = sBlogID;
            blogcommentlist.Add(blogcomment);
            return(View(blogcommentlist));
        }
        /// <summary>
        /// 更新博客信息
        /// </summary>
        public bool Update(BlogCommentEntity blogCommentEntity)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("update BlogComment set ");
            strSql.Append(" BCContent=@BCContent, ModifiedTime=getdate() ");
            strSql.Append(" where BCID=@BCID ");
            using (var connection = ConnectionFactory.GetOpenConnection(ConnStr))
            {
                int i = connection.Execute(strSql.ToString(), blogCommentEntity);
                return(i > 0);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 添加博客
        /// </summary>
        /// <param name="sBlogID"></param>
        /// <returns></returns>
        public IActionResult Add(string sBlogID)
        {
            BlogCommentEntity m = null;

            if (!string.IsNullOrEmpty(sBlogID))
            {
                m = blogCommentDAL.GetOneBlogCommentByBlogID(sBlogID);
                if (m == null)
                {
                    m        = new BlogCommentEntity();
                    m.BlogID = sBlogID;
                }
            }
            return(View(m));
        }
        /// <summary>
        /// 根据ID获取博客评论信息
        /// </summary>
        public BlogCommentEntity GetBlogCommentByBCID(string sBCID)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select * from BlogComment ");
            strSql.Append(" where BCID=@BCID ");
            BlogCommentEntity blogcomment = null;

            using (var connection = ConnectionFactory.GetOpenConnection(ConnStr))
            {
                var param = new DynamicParameters();
                param.Add("@BCID", sBCID, dbType: DbType.String);
                blogcomment = connection.QuerySingle <BlogCommentEntity>(strSql.ToString(), param);
            }
            return(blogcomment);
        }
Ejemplo n.º 8
0
        public IActionResult Update(BlogCommentEntity blogCommentEntity)
        {
            BlogCommentEntity m = null;

            if (!string.IsNullOrEmpty(blogCommentEntity.BCID))
            {
                //修改
                m = blogCommentDAL.GetBlogCommentByBCID(blogCommentEntity.BCID);
                if (m != null)
                {
                    blogCommentEntity.ModifiedTime = DateTime.Now;
                    blogCommentEntity.ModifiedBy   = this.User.Identity.Name;
                    blogCommentDAL.Update(blogCommentEntity);
                }
            }
            return(Redirect("/BlogComment/Index?sBlogID=" + blogCommentEntity.BlogID));
        }
Ejemplo n.º 9
0
 public IActionResult Add(BlogCommentEntity blogCommentEntity)
 {
     if (string.IsNullOrEmpty(this.User.Identity.Name))
     {
         return(Content("您尚未登录用户"));
     }
     if (string.IsNullOrEmpty(blogCommentEntity.BCID))
     {
         //新增
         blogCommentEntity.BCID        = Guid.NewGuid().ToString();
         blogCommentEntity.CreatedTime = DateTime.Now;
         blogCommentEntity.CommentTime = DateTime.Now;
         blogCommentEntity.CommentBy   = this.User.Identity.Name;
         blogCommentEntity.CreatedBy   = this.User.Claims.First().Value;
         blogCommentDAL.Add(blogCommentEntity);
     }
     return(Redirect("/BlogComment/Index?sBlogID=" + blogCommentEntity.BlogID));
 }
Ejemplo n.º 10
0
        public IActionResult Del(string sBCID)
        {
            BlogCommentEntity m = null;

            if (!string.IsNullOrEmpty(sBCID))
            {
                m = blogCommentDAL.GetBlogCommentByBCID(sBCID);
                if (m != null)
                {
                    bool b = blogCommentDAL.DeleteBlogCommentByBCID(sBCID);
                    if (b)
                    {
                        return(Content("删除成功!"));
                    }
                    else
                    {
                        return(Content("删除失败,请联系管理员!"));
                    }
                }
            }
            return(null);
        }
        /// <summary>
        /// Saves an entity.
        /// </summary>
        /// <param name="entity">The resource entity to save.</param>
        /// <param name="cancellationToken">The optional token to monitor for cancellation requests.</param>
        /// <returns>The changing result information.</returns>
        public Task <ChangeMethods> SaveAsync(BlogCommentEntity entity, CancellationToken cancellationToken = default)
        {
            var context = GetContext(false);

            return(DbResourceEntityExtensions.SaveAsync(context.BlogComments, context.SaveChangesAsync, entity, cancellationToken));
        }
Ejemplo n.º 12
0
 public Task <IActionResult> SaveAsync([FromBody] BlogCommentEntity entity)
 {
     return(this.SaveSnsEntityAsync(entity, (sns, e, cancellationToken) => sns.SaveAsync(entity, cancellationToken), Logger, new EventId(17001328, "SaveEntity")));
 }