Exemple #1
0
        public JsonResult DeleteAskContent(int cid)
        {
            //需要查询不属于这个题目的所有题目条目
            //List<AskContent> acList = new List<AskContent>();
            //acList = (from o in db.AskContent join p in db.AskTopicContent.AsNoTracking() on o.id equals p.AskContentId select o).Skip((pageindex - 1) * pagesize).Take(pagesize).ToList();
            AskContent ac     = db.AskContent.Find(cid);
            Result     result = new Result();

            if (ac != null)
            {
                db.AskContent.Remove(ac);
                db.SaveChanges();
                result.success = true;
                List <AskContent> acList = db.AskContent.Where(a => a.TopicId == ac.TopicId).OrderByDescending(a => a.IndexNum).ToList();
                result.obj = acList;
            }
            else
            {
                result.obj     = "数据表中没有选中项";
                result.success = false;
            }


            return(Json(result));
        }
Exemple #2
0
        public JsonResult AddAskContent(string desc, int tid)
        {
            int next  = 0;
            var query = (from o in db.AskContent where o.TopicId == tid orderby o.IndexNum select o).ToList();

            if (query.Count > 0)
            {
                next = query[query.Count - 1].IndexNum.Value + 1;
            }



            AskContent ac = new AskContent();

            ac.TopicId    = tid;
            ac.Desc       = desc;
            ac.CreateTime = DateTime.Now;
            ac.IndexNum   = next;

            ac.IndexDesc = getAlphByIndex(next, tid);
            db.AskContent.Add(ac);

            db.SaveChanges();

            List <AskContent> acList = db.AskContent.Where(a => a.TopicId == tid).OrderBy(a => a.IndexNum).ToList();

            return(Json(acList));
        }
Exemple #3
0
        public JsonResult EditAskContent(int cid, string desc)
        {
            AskContent ac = db.AskContent.Find(cid);

            if (ac != null)
            {
                ac.Desc = desc;
                db.SaveChanges();
            }
            return(Json(ac));
        }
Exemple #4
0
        /// <summary>
        /// 交换 题目项位置
        /// </summary>
        /// <param name="contentId"></param>
        /// <param name="increase"></param>
        /// <returns></returns>
        public JsonResult ChangeContentItemIndex(int contentId, int increase)
        {
            //if (!UserInfo.CurUser.HasRight("系统管理-数据字典")) return Json(new Result { obj = "没有权限" });
            Result     result = new Result();
            AskContent item   = db.AskContent.Find(contentId);

            if (item == null)
            {
                result.obj = "找不到题目项";
            }
            else
            {
                AskContent another = null;
                if (increase > 0)
                {
                    another =
                        (from o in db.AskContent
                         where o.TopicId == item.TopicId && o.IndexNum > item.IndexNum
                         orderby o.IndexNum
                         select o).FirstOrDefault();
                }
                else
                {
                    another =
                        (from o in db.AskContent
                         where o.TopicId == item.TopicId && o.IndexNum < item.IndexNum
                         orderby o.IndexNum descending
                         select o).FirstOrDefault();
                }
                if (another == null)
                {
                    result.obj = "找不到可以交换位置的题目项";
                }
                else
                {
                    int?temp = item.IndexNum;
                    item.IndexNum  = another.IndexNum;
                    item.IndexDesc = getAlphByIndex(item.IndexNum.Value, item.TopicId.Value);

                    another.IndexNum  = temp;
                    another.IndexDesc = getAlphByIndex(another.IndexNum.Value, another.TopicId.Value);

                    db.SaveChanges();
                    result.success = true;
                }
            }
            if (result.success == true)
            {
                var query = (from o in db.AskContent where o.TopicId == item.TopicId orderby o.IndexNum descending select o).ToList();
                result.obj = query;
            }
            return(Json(result));
        }