Beispiel #1
0
        public JsonResult AddComment(string articleid, string content)
        {
            StatusData myStatusData = new StatusData(); //返回的类型
            string     mobilePhone  = "";               //

            //
            #region 检查授权
            AuthCodeInstance myAuthCodeInstance = new AuthCodeInstance();
            AuthCodeClass    myAuthCodeClass    = new AuthCodeClass();
            bool             checkAuthCodeBool  = myAuthCodeClass.checkAuthCode(out myAuthCodeInstance);
            #endregion
            if (checkAuthCodeBool)
            {
                mobilePhone = myAuthCodeInstance.mobilePhone;
                using (chefuzi_dataEntities myOperating = new chefuzi_dataEntities())//数据库操作
                {
                    Teacher_Article_Comment myRecord = new Teacher_Article_Comment();

                    long myLong = 0;//要评论的文章
                    bool isOk   = long.TryParse(articleid, out myLong);
                    if (isOk)
                    {
                        try
                        {
                            myRecord.AboutId     = myLong;
                            myRecord.Detail      = content;
                            myRecord.MobilePhone = mobilePhone;
                            myRecord.NickName    = "";
                            myRecord.AddDate     = DateTime.Now;
                            myRecord.Status      = 200;
                            myOperating.Teacher_Article_Comment.Add(myRecord);
                            myOperating.SaveChanges();
                            myStatusData.operateStatus = 200;
                        }
                        catch
                        {
                            myStatusData.operateStatus = -1;
                        }
                    }
                    else
                    {
                        myStatusData.operateStatus = 400;
                        myStatusData.operateMsg    = "参数错误";
                    }
                }
            }
            else
            {
                myStatusData.operateStatus = 5;
            }
            return(Json(myStatusData.operateMsg));
        }
Beispiel #2
0
        //---------------------CommentList
        #region 评论列表
        public ActionResult CommentList(int currentpage = 1, long aboutid = 0, long del = 0)
        {
            #region 翻页定义
            ViewBag.CurrentPage = 0;  //当前页
            ViewBag.PPage       = 0;  //上一页
            ViewBag.NPage       = 0;  //下一页
            ViewBag.PageCount   = 0;  //总页数
            ViewBag.RecordCount = 0;  //记录总数
            ViewBag.IsFirstPage = ""; //第一条记录,禁用首页和上一页
            ViewBag.IsEndPage   = ""; //最后条记录,禁用首页和下一页
            #endregion
            //
            ViewBag.Headline = "评论管理";//栏目主题
            //
            ViewBag.DataList   = null;
            ViewBag.RecordItem = null;
            //
            StatusData myStatusData = new StatusData();                           //返回状态
            //
            using (chefuzi_dataEntities myOperating = new chefuzi_dataEntities()) //数据库操作
            {
                #region  除
                if (del > 0)
                {
                    Teacher_Article_Comment myDelRecord = myOperating.Teacher_Article_Comment.FirstOrDefault(p => p.CommentId == del);
                    if (myDelRecord != null)
                    {
                        myOperating.Teacher_Article_Comment.Remove(myDelRecord);
                        myOperating.SaveChanges();
                    }
                }
                #endregion
                //
                #region 翻页属性
                int    recordCount  = 0;
                int    pageCount    = 0;
                string orderbyfiled = "CommentId";
                //
                //当前页
                int sqlCurrentpage = currentpage;
                if (sqlCurrentpage < 1)
                {
                    sqlCurrentpage = 1;
                }
                //页大小
                int sqlPagesize = 10;
                #endregion
                //
                #region 取出内容
                IQueryable <Teacher_Article_Comment> myIQueryable = null;
                if (aboutid > 0)
                {
                    myIQueryable = myOperating.Teacher_Article_Comment.Where(p => p.AboutId == aboutid);
                }
                else
                {
                    myIQueryable = myOperating.Teacher_Article_Comment;
                }

                //
                if (myIQueryable != null)
                {
                    List <Teacher_Article_Comment> BookTable = QueryableExtensions.OrderBy(myIQueryable, orderbyfiled, out recordCount, out pageCount, ref sqlCurrentpage, sqlPagesize, true).ToList();
                    //
                    ViewBag.DataList = BookTable;
                    #region 页数取值
                    ViewBag.CurrentPage = sqlCurrentpage;
                    ViewBag.PageCount   = pageCount;
                    ViewBag.RecordCount = recordCount;
                    if (sqlCurrentpage > 1)
                    {
                        ViewBag.PPage = sqlCurrentpage - 1;
                    }
                    else
                    {
                        ViewBag.IsFirstPage = "disabled";
                        ViewBag.PPage       = 1;
                    }
                    if (sqlCurrentpage < pageCount)
                    {
                        ViewBag.NPage = sqlCurrentpage + 1;
                    }
                    else
                    {
                        ViewBag.NPage     = sqlCurrentpage;
                        ViewBag.IsEndPage = "disabled";
                    }
                    #endregion
                }
                #endregion
                //
            }
            return(View());
        }