public JsonResult AddAskTopic(string desc, int pid, string type) { int next = 0; var query = (from o in db.AskTopic where o.PageId == pid orderby o.IndexNum select o).ToList(); if (query.Count > 0) { next = query[query.Count - 1].IndexNum.Value + 1; } AskTopic ac = new AskTopic(); ac.PageId = pid; ac.Title = desc; ac.Type = type; ac.CreateTime = DateTime.Now; ac.IndexNum = next; db.AskTopic.Add(ac); db.SaveChanges(); List <AskTopic> acList = db.AskTopic.Where(a => a.PageId == pid).OrderByDescending(a => a.IndexNum).ToList(); return(Json(acList)); }
public JsonResult DeleteAskTopic2(int tid) { //需要查询不属于这个题目的所有题目条目 //List<AskTopic> acList = new List<AskTopic>(); //acList = (from o in db.AskTopic join p in db.AskTopicContent.AsNoTracking() on o.id equals p.AskTopicId select o).Skip((pageindex - 1) * pagesize).Take(pagesize).ToList(); AskTopic ac = db.AskTopic.Find(tid); Result result = new Result(); if (ac != null) { db.AskTopic.Remove(ac); db.SaveChanges(); result.success = true; List <AskTopic> acList = db.AskTopic.Where(a => a.PageId == ac.PageId).OrderBy(a => a.IndexNum).ToList(); result.obj = acList; } else { result.obj = "数据表中没有选中项"; result.success = false; } return(Json(result)); }
public JsonResult EditAskTopic(int tid, string desc, string type) { AskTopic at = db.AskTopic.Find(tid); if (at != null) { at.Type = type; at.Title = desc; db.SaveChanges(); } return(Json(at)); }
public JsonResult AddAskTopic(string title, int pageId, int order) { AskTopic at = new AskTopic(); at.Title = title; at.Order = order; at.PageId = pageId; at.CreateTime = DateTime.Now; db.AskTopic.Add(at); db.SaveChanges(); return(Json(at)); }
/// <summary> /// 交换 题目项位置 /// </summary> /// <param name="topicId"></param> /// <param name="increase"></param> /// <returns></returns> public JsonResult ChangeTopicItemIndex(int topicId, int increase) { //if (!UserInfo.CurUser.HasRight("系统管理-数据字典")) return Json(new Result { obj = "没有权限" }); Result result = new Result(); AskTopic item = db.AskTopic.Find(topicId); if (item == null) { result.obj = "找不到题目"; } else { AskTopic another = null; if (increase > 0) { another = (from o in db.AskTopic where o.PageId == item.PageId && o.IndexNum > item.IndexNum orderby o.IndexNum select o).FirstOrDefault(); } else { another = (from o in db.AskTopic where o.PageId == item.PageId && 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; another.IndexNum = temp; db.SaveChanges(); result.success = true; } } if (result.success == true) { var query = (from o in db.AskTopic where o.PageId == item.PageId orderby o.IndexNum ascending select o).ToList(); result.obj = query; } return(Json(result)); }
public ActionResult AskTopicEdit(int id, int?projectid, FormCollection collection) { AskTopic r = db.AskTopic.Find(id); if (r == null) { int pid = 0; if (projectid != null) { pid = projectid.Value; } r = new AskTopic(); db.AskTopic.Add(r); } TryUpdateModel(r, collection); if (ModelState.IsValid) { db.SaveChanges(); return(Redirect("../AskTopicView/" + r.id)); } return(View(r)); }
public ActionResult AskTopicEdit2(int id) { AskTopic r = db.AskTopic.Find(id); return(View(r)); }