public IHttpActionResult login(loginformation log) { using (var db = new oucfreetalkEntities()) { var stu = db.students.FirstOrDefault(a => a.id == log.account); results res = new results(); if (stu == null) { res.result = 0;//登录失败,没有用户名 return(Ok(res)); } else { if (PasswordHash.PasswordHash.ValidatePassword(log.password, stu.password)) { HttpContext.Current.Session["sid"] = stu.id; res.result = 1;//登录成功 return(Ok(res)); } else { res.result = 2;//密码错误 return(Ok(res)); } } } }
public IHttpActionResult getMyAccess() { results res = new results(); string userid = ""; try { userid = HttpContext.Current.Session["sid"].ToString(); if (userid == "") { res.result = 0;//未登录 return(Ok(res)); } } catch { res.result = 0;//未登录 return(Ok(res)); } using (var db = new oucfreetalkEntities()) { var search = (from it in db.accountaccess where it.studentid == userid select new { it.id, it.studentid, it.classid, it.createtime }).ToList();//查看我的管理列表 if (search.Count == 0) { res.result = 1;//没有任何权限 return(Ok(res)); } else { return(Ok(search)); } } }
public IHttpActionResult addlost(addlistdata ald) { results res = new results(); using (var db = new oucfreetalkEntities()) { var laf = new lostafound(); laf.stuid = ald.sid; laf.secarea = ald.SecArea; laf.state = false; laf.name = ald.name; laf.area = ald.area; laf.createtime = DateTime.Now; try { if (db.SaveChanges() == 0) { res.result = 5; return(Ok(res)); } else { res.result = 1; return(Ok(res)); } } catch { res.result = 3; return(Ok(res)); } } }
public IHttpActionResult getmylost(int index) { results res = new results(); if (index < 1) { index = 1; } int perpage = 20; string stuid = new MyApi.SqlHelper().IfLogin(); if (stuid == null) { res.result = 0; return(Ok(res)); } using (var db = new oucfreetalkEntities()) { var mylost = (from it in db.lostafound where it.stuid == stuid && it.state == true orderby it.createtime descending select it).ToList(); int allcount = mylost.Count; int allpage = allcount / perpage; if (allcount % perpage != 0) { allpage++; } var search = mylost.Skip((index - 1) * perpage).Take(perpage); return(Ok(new { search, allpage })); } }
public IHttpActionResult logout(loginformation log) { HttpContext.Current.Session.Clear(); results res = new results(); res.result = 1; return(Ok(res)); }
public IHttpActionResult delPostsd(delPostData dpd) { results res = new results(); string userid = new MyApi.SqlHelper().IfLogin();//获取id if (userid == "") { res.result = 0;//未登录 return(Ok(res)); } if (!new PostAcess().GetPostAccess(userid, dpd.postid)) { res.result = 2;//权限不够 return(Ok(res)); } using (var db = new oucfreetalkEntities()) { var searchpost = db.posts.FirstOrDefault(a => a.id == dpd.postid); if (searchpost == null) { res.result = 4;//帖子不存在 return(Ok(res)); } searchpost.state = false; var search_comment = (from it in db.postc where it.ownpost == searchpost.id && it.state == true select it).ToList(); for (int i = 0; i < search_comment.Count; i++) { var search_reply = (from it in db.postreply where it.ownlocation == search_comment[i].id && it.state == true select it).ToList(); for (int j = 0; j < search_reply.Count; j++) { search_reply[j].state = false; } search_comment[i].state = false; } try { if (db.SaveChanges() == 0) { res.result = 5; return(Ok(res)); } else { res.result = 1; return(Ok(res)); } } catch { res.result = 3; return(Ok(res)); } } }
public IHttpActionResult eidtor(students stu) { try { string sid = HttpContext.Current.Session["sid"].ToString(); if (sid == stu.id) { using (var db = new oucfreetalkEntities()) { var s = db.students.FirstOrDefault(a => a.id == stu.id); if (s == null) { results res = new results(); res.result = 3;//没有此用户 return(Ok(res)); } else { s.nikename = stu.nikename; s.sex = stu.sex; s.birth = stu.birth; s.year = stu.year; s.family = stu.family; s.pic = stu.pic; s.ifname = stu.ifname; s.ifsex = stu.ifsex; s.ifbirth = stu.ifbirth; s.ifmobile = stu.ifmobile; s.ifemail = stu.ifemail; if (db.SaveChanges() != 0) { results res = new results(); res.result = 1;//成功 return(Ok(res)); } else { results res = new results(); res.result = 4;//保存失败 return(Ok(res)); } } } } else { results res = new results(); res.result = 2; //id不合法 return(Ok(res)); } } catch { results res = new results(); res.result = 0; //还未登录 return(Ok(res)); } }
public IHttpActionResult addreply(ReplyMainInfo rmi) { results res = new results(); string userid = new MyApi.SqlHelper().IfLogin(); if (userid == "") { res.result = 0; return(Ok(res)); } try { using (var db = new oucfreetalkEntities()) { var thisPost = db.postc.FirstOrDefault(a => a.id == rmi.commentid); if (thisPost == null) { res.result = 4; return(Ok(res)); } var rootpost = db.posts.FirstOrDefault(a => a.id == thisPost.ownpost); postreply pc = new postreply(); pc.owner = userid; pc.ownlocation = thisPost.id; pc.createtime = DateTime.Now; pc.replyto = rmi.replyid; pc.state = true; pc.contenttext = rmi.context; db.postreply.Add(pc); rootpost.realbody += 1; if (db.SaveChanges() == 0) { res.result = 2; return(Ok(res)); } else { var rst = db.postreply.FirstOrDefault(a => a.owner == pc.owner && a.createtime == pc.createtime && a.ownlocation == pc.ownlocation); if (!new MessageHelper().addreplymessage(rst.id)) { res.result = 6;//消息未创建成功 return(Ok(res)); } buridata.addbridata(userid, 3, 0); res.result = 1; return(Ok(res)); } } } catch { res.result = 3; return(Ok(res)); } }
public IHttpActionResult getAccess(getAccessData gad) { results res = new results(); string userid = ""; try { userid = HttpContext.Current.Session["sid"].ToString(); if (userid == "") { res.result = 0;//未登录 return(Ok(res)); } } catch { res.result = 0;//未登录 return(Ok(res)); } using (var db = new oucfreetalkEntities()) { var search = (from it in db.accountaccess where it.studentid == userid && it.classid == -2 select it).ToList();//查看我的是否是管理员 if (search.Count == 0) { res.result = 2;//你不是管理员再见 return(Ok(res)); } if (gad.access == -3) { var s_data = (from it in db.accountaccess select it).ToList(); if (s_data.Count == 0) { res.result = 1; return(Ok(res)); } return(Ok(s_data));//返回数据 } else { var s_data = (from it in db.accountaccess where it.classid == gad.access select it).ToList(); if (s_data.Count == 0) { res.result = 1; return(Ok(res)); } return(Ok(s_data));//返回数据 } } }
public IHttpActionResult getGod() { results res = new results(); string userid = ""; try { userid = HttpContext.Current.Session["sid"].ToString(); if (userid == "") { res.result = 0;//未登录 return(Ok(res)); } } catch { res.result = 0;//未登录 return(Ok(res)); } using (var db = new oucfreetalkEntities()) { var search = (from it in db.accountaccess where it.studentid == userid && it.classid == -2 select it).ToList();//确认是否为狗管理 if (search.Count != 0) { res.result = 2;//你已经是狗管理了 return(Ok(res)); } else { accountaccess ata = new accountaccess(); ata.studentid = userid; ata.createtime = DateTime.Now; ata.classid = -2; try { db.accountaccess.Add(ata); if (db.SaveChanges() == 0) { res.result = 4;//服务器错误 return(Ok(res)); } res.result = 1;//授予成功 return(Ok(res)); } catch { res.result = 3;//服务器错误 return(Ok(res)); } } } }
public IHttpActionResult GetFocusMe() { results res = new results(); string sid = ""; try { sid = HttpContext.Current.Session["sid"].ToString(); if (sid == "") { res.result = 0; return(Ok(res)); } } catch { res.result = 0; return(Ok(res)); } try { using (var db = new oucfreetalkEntities()) { var stu = db.students.FirstOrDefault(a => a.id == sid); if (stu == null) { res.result = 2; return(Ok(res)); } var information = (from it in db.friendfocus where it.befocus == stu.id select it).ToList(); if (information.Count == 0) { res.result = 1; return(Ok(res)); //返回正确但是没有数据 } for (int i = 0; i < information.Count; i++) { if (!information[i].ifname) { information[i].name = null; } } return(Ok(information)); } } catch { res.result = 3; return(Ok(res)); } }
public IHttpActionResult GetOhters(string id) { results res = new results(); using (var db = new oucfreetalkEntities()) { var stu = db.students.FirstOrDefault(a => a.id == id); if (stu != null) { reStudent st = new reStudent(); st.id = stu.id; st.ifname = stu.ifname; st.nikename = stu.nikename; st.pic = stu.pic; st.ifsex = stu.ifsex; st.year = stu.year; st.ifemail = stu.ifemail; st.ifmobile = stu.ifmobile; st.exp = stu.exp; st.family = stu.family; st.ifbirth = stu.ifbirth; if (stu.ifemail) { st.email = stu.email; } if (stu.ifname) { st.name = stu.name; } if (stu.ifmobile) { st.mobile = stu.mobile; } if (stu.ifbirth) { st.birth = stu.birth; } if (stu.ifsex) { st.sex = stu.sex; } return(Ok(st)); } else { res.result = 0; return(Ok(res)); } } }
public IHttpActionResult register(registerdata rgd) { results res = new results(); if (IfExist(rgd.id)) { res.result = 2; return(Ok(res)); } try { using (var db = new oucfreetalkEntities()) { students std = new students(); std.id = rgd.id; std.nikename = rgd.nikename; std.sex = rgd.sex; std.introduction = rgd.introduce; std.name = " "; std.birth = DateTime.Today; std.year = DateTime.Today.Year.ToString(); std.ifsex = false; std.exp = 0; std.ifemail = false; std.ifmobile = false; std.ifname = false; std.ifbirth = false; std.password = PasswordHash.PasswordHash.CreateHash(rgd.password); db.students.Add(std); if (db.SaveChanges() == 0) { res.result = 0; return(Ok(res)); } else { res.result = 1; return(Ok(res)); } } } catch { //return NotFound();\ res.result = 0; return(Ok(res)); } }
public IHttpActionResult delReply(delReplyData drd) { results res = new results(); string userid = new MyApi.SqlHelper().IfLogin();//获取id if (userid == "") { res.result = 0;//未登录 return(Ok(res)); } if (!new PostAcess().GetReplyAccess(userid, drd.replyid)) { res.result = 2;//权限不够 return(Ok(res)); } using (var db = new oucfreetalkEntities()) { var searchreply = db.postreply.FirstOrDefault(a => a.id == drd.replyid); if (searchreply == null) { res.result = 4; return(Ok(res)); } var thiscomment = db.postc.FirstOrDefault(a => a.id == searchreply.ownlocation); var thispost = db.posts.FirstOrDefault(a => a.id == thiscomment.ownpost); thispost.realbody -= 1; searchreply.state = false; try { if (db.SaveChanges() == 0) { res.result = 5; return(Ok(res)); } else { res.result = 1; return(Ok(res)); } } catch { res.result = 3; return(Ok(res)); } } }
public IHttpActionResult match(ver v) { results res = new results(); if (v.str == HttpContext.Current.Session["ValidateNum"].ToString()) { res.result = 1; HttpContext.Current.Session["ValidateNum"] = null; return(Ok(res)); } else { res.result = 0; } return(Ok(res)); }
public IHttpActionResult editorClass(editorClassData ecd) { results res = new results(); string userid = new MyApi.SqlHelper().IfLogin(); if (userid == "") { res.result = 0; return(Ok(res)); } if (!new MyApi.SqlHelper().IfYouHaveAcess(-1, userid)) { res.result = 2;//权限不够 return(Ok(res)); } using (var db = new oucfreetalkEntities()) { var searchName = (from it in db.postclass where it.id == ecd.classid select it).ToList(); if (searchName.Count == 0) { res.result = 4;//该板块不存在 return(Ok(res)); } try { postclass ptc = db.postclass.FirstOrDefault(a => a.id == ecd.classid); ptc.name = ecd.newname; if (db.SaveChanges() == 0) { res.result = 5;//服务器错误 return(Ok(res)); } else { res.result = 1;//修改成功 return(Ok(res)); } } catch { res.result = 3;//服务器错误 return(Ok(res)); } } }
public IHttpActionResult addClass(AddClassData acd) { results res = new results(); string userid = new MyApi.SqlHelper().IfLogin(); if (userid == "") { res.result = 0;//未登录 return(Ok(res)); } using (var db = new oucfreetalkEntities()) { if (!new MyApi.SqlHelper().IfYouHaveAcess(-1, userid)) { res.result = 2;//权限不够 return(Ok(res)); } if (new MyApi.SqlHelper().IfClassExist(acd.classname)) { res.result = 4;//该板块已存在 return(Ok(res)); } try { postclass pcs = new postclass(); pcs.name = acd.classname; pcs.state = true;//未删除 db.postclass.Add(pcs); if (db.SaveChanges() == 0) { res.result = 5;//服务器错误 return(Ok(res)); } else { res.result = 1;//添加成功 return(Ok(res)); } } catch { res.result = 3;//服务器错误 return(Ok(res)); } } }
public IHttpActionResult getPostindex(ReqPostData rpd) { results res = new results(); int perpage = 20; if (rpd.index <= 0) { rpd.index = 1; } using (var db = new oucfreetalkEntities()) { var thispost = db.posts.FirstOrDefault(a => a.id == rpd.postid); if (thispost == null) { res.result = 2;//post不存在 return(Ok(res)); } var thisstu = db.students.FirstOrDefault(a => a.id == thispost.owner); var searchcomment = (from it in db.postc join it2 in db.students on it.owner equals it2.id where it.ownpost == rpd.postid && it.state == true orderby it.createtime select new { commentid = it.id, commentcontext = it.body, it.createtime, it.postlocation, stuid = it2.id, ico = it2.pic, nikename = it2.nikename }).ToList(); searchcomment.Add(new { commentid = 0, commentcontext = thispost.contenttext, thispost.createtime, postlocation = 1, stuid = thisstu.id, ico = thisstu.pic, thisstu.nikename }); searchcomment.OrderBy(a => a.postlocation); int allcount = searchcomment.Count; int allpage = allcount / perpage; if (allcount % perpage != 0) { allpage++; } var search = searchcomment.Skip((rpd.index - 1) * perpage).Take(perpage); return(Ok(new { search, allpage })); } }
public IHttpActionResult gotit(int lostid) { results res = new results(); string stuid = new MyApi.SqlHelper().IfLogin(); if (stuid == null) { res.result = 0; return(Ok(res)); } using (var db = new oucfreetalkEntities()) { var thislot = db.lostafound.FirstOrDefault(a => a.id == lostid && a.state == false); if (thislot == null) { res.result = 2; return(Ok(res)); } if (thislot.stuid != stuid) { res.result = 4; return(Ok(res)); } thislot.state = false; try { if (db.SaveChanges() == 0) { res.result = 5; return(Ok(res)); } else { res.result = 1; return(Ok(res)); } } catch { res.result = 3; return(Ok(res)); } } }
public IHttpActionResult addPost(PostMainInfo pmi) { results res = new results(); string userid = new MyApi.SqlHelper().IfLogin(); if (userid == "") { res.result = 0; return(Ok(res)); } try { using (var db = new oucfreetalkEntities()) { posts pts = new posts(); DateTime nowtime = DateTime.Now; pts.ownclass = pmi.pclass; pts.title = pmi.title; pts.contenttext = pmi.context; pts.realbody = 1; pts.body = 1; pts.owner = userid; pts.createtime = nowtime; pts.updatetime = nowtime; pts.state = true; db.posts.Add(pts); if (db.SaveChanges() == 0) { res.result = 2; return(Ok(res)); } else { buridata.addbridata(userid, 1, 0); res.result = 1; return(Ok(res)); } } } catch { res.result = 3; return(Ok(res)); } }
public IHttpActionResult Getmy() { results res = new results(); try { string sid = HttpContext.Current.Session["sid"].ToString(); using (var db = new oucfreetalkEntities()) { var stu = db.students.FirstOrDefault(a => a.id == sid); if (stu != null) { reStudent st = new reStudent(); st.id = stu.id; st.name = stu.name; st.nikename = stu.nikename; st.pic = stu.pic; st.ifsex = stu.ifsex; st.year = stu.year; st.ifemail = stu.ifemail; st.ifmobile = stu.ifmobile; st.exp = stu.exp; st.family = stu.family; st.ifbirth = stu.ifbirth; st.email = stu.email; st.ifname = stu.ifname; st.mobile = stu.mobile; st.birth = stu.birth; st.sex = stu.sex; return(Ok(st)); } else { res.result = 4; return(Ok(res)); } } } catch { res.result = 0; return(Ok(res)); } }
public IHttpActionResult getCommentindex(ReqCommentData rcd) { results res = new results(); int perpage = 20; if (rcd.index <= 0) { rcd.index = 1; } using (var db = new oucfreetalkEntities()) { var thiscomment = db.posts.FirstOrDefault(a => a.id == rcd.commentid); if (thiscomment == null) { res.result = 2;//comment不存在 return(Ok(res)); } var searchreply = (from it in db.postreply join it2 in db.students on it.owner equals it2.id join it3 in db.students on it.replyto equals it3.id where it.ownlocation == thiscomment.id && it.state == true orderby it.createtime descending select new { it.id, it.contenttext, it.createtime, stuid = it2.id, stunike = it2.nikename, replyid = it.replyto, replynike = it3.nikename }).ToList(); int allcount = searchreply.Count; int allpage = allcount / perpage; if (allcount % perpage != 0) { allpage++; } var search = searchreply.Skip((rcd.index - 1) * perpage).Take(perpage); return(Ok(new { search, allpage })); } }
public IHttpActionResult getClasses() { results res = new results(); try { using (var db = new oucfreetalkEntities()) { var classes = (from it in db.postclass where it.state == true select it).ToList(); return(Ok(new { classes, classes.Count })); } } catch { res.result = 3; return(Ok(res)); } }
public IHttpActionResult getmynotice(noticedata ntd) { int perpage = 20; results res = new results(); string stuid = new MyApi.SqlHelper().IfLogin(); if (stuid == null) { res.result = 0; } using (var db = new oucfreetalkEntities()) { if (ntd.nclass == -1) { var searchnotice = (from it in db.notices join it3 in db.students on it.replystuid equals it3.id join it4 in db.posts on it.postid equals it4.id join it5 in db.postc on it.commentsid equals it5.id join it6 in db.postreply on it.replyid equals it6.id where it.state == true && it.stuid == stuid orderby it.createtime descending select new { it.id, it.noticeclass, it.postid, it.createtime, posttitle = it4.title, it.commentsid, commenttext = it5.body, it.replyid, replytext = it6.contenttext, it.replystuid, it3.nikename, it3.pic }).ToList(); int allcount = searchnotice.Count; int allpage = allcount / perpage; if (allcount % perpage != 0) { allpage++; } var search = searchnotice.Skip((ntd.index - 1) * perpage).Take(perpage); return(Ok(new { search, allpage })); } else { var searchnotice = (from it in db.notices join it3 in db.students on it.replystuid equals it3.id join it4 in db.posts on it.postid equals it4.id join it5 in db.postc on it.commentsid equals it5.id join it6 in db.postreply on it.replyid equals it6.id where it.state == true && it.stuid == stuid && it.noticeclass == ntd.nclass orderby it.createtime descending select new { it.id, it.noticeclass, it.postid, it.createtime, posttitle = it4.title, it.commentsid, commenttext = it5.body, it.replyid, replytext = it6.contenttext, it.replystuid, it3.nikename, it3.pic }).ToList(); int allcount = searchnotice.Count; int allpage = allcount / perpage; if (allcount % perpage != 0) { allpage++; } var search = searchnotice.Skip((ntd.index - 1) * perpage).Take(perpage); return(Ok(new { search, allpage })); } } }
public IHttpActionResult DeleteFriend(mytarget ta) { string target = ta.target; results res = new results(); using (var db = new oucfreetalkEntities()) { var dlist = (from it in db.students where it.id == target select it).ToList(); if (dlist.Count == 0) { res.result = 4; return(Ok(res)); } } string userid = ""; try { userid = HttpContext.Current.Session["sid"].ToString(); if (userid == "") { res.result = 0; return(Ok(res)); } } catch { res.result = 0; return(Ok(res)); }//未登录 if (userid == target) { res.result = 5;//同名错误 return(Ok(res)); } try { using (var db = new oucfreetalkEntities()) { var search = (from it in db.friends where it.focus == userid && it.befocus == target select it).ToList(); if (search.Count == 0) { res.result = 2;//不存在该好友 return(Ok(res)); } else { db.friends.Remove(search[0]); if (db.SaveChanges() == 0) { res.result = 3;//失败 return(Ok(res)); } else { res.result = 1;//成功 return(Ok(res)); } } } } catch { res.result = 3;//服务器错误 return(Ok(res)); } }
public IHttpActionResult getPosts(ReqPost rp) { results res = new results(); int perpage = 20; if (rp.index <= 0) { rp.index = 1; } using (var db = new oucfreetalkEntities()) { if (rp.pclass != -1 && db.postc.FirstOrDefault(a => a.id == rp.pclass) == null) { res.result = 0; return(Ok(res)); } if (rp.pclass == -1) { var search_post = (from it in db.posts join itb in db.students on it.owner equals itb.id where it.state == true orderby it.updatetime descending select new { it.id, it.ownclass, it.owner, it.realbody, it.title, it.contenttext, it.createtime, ownername = itb.nikename, ownerpic = itb.pic }).ToList(); int allcount = search_post.Count; int allpage = allcount / perpage; if (allcount % perpage != 0) { allpage++; } var search = search_post.Skip((rp.index - 1) * perpage).Take(perpage); return(Ok(new { search, allpage })); } else { var search_post = (from it in db.posts join itb in db.students on it.owner equals itb.id where it.ownclass == rp.pclass orderby it.updatetime descending select new { it.id, it.ownclass, it.owner, it.realbody, it.title, it.contenttext, it.body, it.createtime, ownername = itb.nikename, ownerpic = itb.pic }).ToList(); int allcount = search_post.Count; int allpage = allcount / perpage; if (allcount % perpage != 0) { allpage++; } var search = search_post.Skip((rp.index - 1) * perpage).Take(perpage); return(Ok(new { search, allpage })); } } }
public IHttpActionResult deleteClass(removeClassData rcd) { results res = new results(); string userid = new MyApi.SqlHelper().IfLogin(); if (userid == "") { res.result = 0; return(Ok(res)); } using (var db = new oucfreetalkEntities()) { var searchaccess = (from it in db.accountaccess where it.classid == -1 select it).ToList(); if (searchaccess.Count == 0) { res.result = 2;//权限不够 return(Ok(res)); } var searchName = (from it in db.postclass where it.id == rcd.classid select it).ToList(); if (searchName.Count == 0) { res.result = 4;//该板块不存在 return(Ok(res)); } try { postclass ptc = db.postclass.FirstOrDefault(a => a.id == rcd.classid);//删除 var search_post = (from it in db.posts where it.postclass == ptc select it).ToList();//查找该板块的帖子 for (int i = 0; i < search_post.Count; i++) { var search_comm = (from it in db.postc where it.ownpost == search_post[i].id select it).ToList();//查找帖子的楼层 for (int j = 0; j < search_comm.Count; j++) { var search_reply = (from it in db.postreply where it.ownlocation == search_comm[i].id select it).ToList(); for (int ij = 0; ij < search_reply.Count; ij++) { search_reply[ij].state = false; //循环删除回复 } search_comm[j].state = false; //循环删除楼层 } search_post[i].state = false; //循环删除帖子 } var search_access = (from it in db.accountaccess where it.classid == rcd.classid select it).ToList(); for (int i = 0; i < search_access.Count; i++) { db.accountaccess.Remove(search_access[i]); //循环删除版主 } db.postclass.Remove(ptc); //删除板块 if (db.SaveChanges() == 0) { res.result = 5;//服务器错误 return(Ok(res)); } else { res.result = 1;//成功 return(Ok(res)); } } catch { res.result = 3;//服务器错误 return(Ok(res)); } } }
public IHttpActionResult setAccess(setaccessdata sad) { results res = new results(); string userid = ""; try { userid = HttpContext.Current.Session["sid"].ToString(); if (userid == "") { res.result = 0;//未登录 return(Ok(res)); } } catch { res.result = 0;//未登录 return(Ok(res)); } using (var db = new oucfreetalkEntities()) { var search = (from it in db.accountaccess where it.studentid == userid && it.classid == -2 select it).ToList(); if (search.Count == 0) { res.result = 2;//不是管理员的管理员 return(Ok(res)); } if (sad.accessclass != -1) { var search_access = (from it in db.postclass where it.id == sad.accessclass select it).ToList(); if (search_access.Count == 0) { res.result = 5;//权限不存在 return(Ok(res)); } } var search_stu_access = (from it in db.accountaccess where it.studentid == sad.stuid && (it.classid == sad.accessclass || it.classid == -1) select it).ToList(); if (search_stu_access.Count != 0) { res.result = 6;//已有权限或者更高权限 return(Ok(res)); } try { accountaccess ata = new accountaccess(); ata.studentid = userid; ata.createtime = DateTime.Now; ata.classid = sad.accessclass; db.accountaccess.Add(ata); if (sad.accessclass == -1)//如果添加的是板块总管理员,删除其他版主身份 { for (int i = 0; i < search_stu_access.Count; i++) { if (search_stu_access[i].classid != -2) { db.accountaccess.Remove(search_stu_access[i]); } } } if (db.SaveChanges() == 0) { res.result = 4;//服务器错误 return(Ok(res)); } res.result = 1; return(Ok(res)); } catch { res.result = 3; return(Ok(res)); } } }
public IHttpActionResult addcomment(CommentMainInfo cmi) { results res = new results(); string userid = new MyApi.SqlHelper().IfLogin(); if (userid == "") { res.result = 0; return(Ok(res)); } try { using (var db = new oucfreetalkEntities()) { var seachpost = (from it in db.posts where it.id == cmi.postid select it).ToList(); if (seachpost.Count == 0) { res.result = 4; return(Ok(res)); } var thisPost = db.posts.FirstOrDefault(a => a.id == cmi.postid); postc pc = new postc(); pc.owner = userid; pc.ownpost = thisPost.id; pc.body = cmi.context; pc.createtime = DateTime.Now; pc.postlocation = thisPost.body + 1; pc.state = true; db.postc.Add(pc); thisPost.realbody += 1; thisPost.body += 1; if (db.SaveChanges() == 0) { res.result = 2; return(Ok(res)); } else { //添加提醒 var rst = db.comment.FirstOrDefault(a => a.owner == pc.owner && a.createtime == pc.createtime && a.body == pc.body); if (!new MessageHelper().addcommentmessage(rst.id)) { res.result = 6;//消息未创建成功 return(Ok(res)); } buridata.addbridata(userid, 2, 0); res.result = 1; return(Ok(res)); } } } catch { res.result = 3; return(Ok(res)); } }
public IHttpActionResult delAccess(delaccessdata sad) { results res = new results(); string userid = ""; try { userid = HttpContext.Current.Session["sid"].ToString(); if (userid == "") { res.result = 0;//未登录 return(Ok(res)); } } catch { res.result = 0;//未登录 return(Ok(res)); } using (var db = new oucfreetalkEntities()) { var search = (from it in db.accountaccess where it.studentid == userid && it.classid == -2 select it).ToList(); if (search.Count == 0) { res.result = 2;//不是管理员的管理员 return(Ok(res)); } if (sad.accessclass != -1) { var search_access = (from it in db.postclass where it.id == sad.accessclass && it.state == true select it).ToList(); if (search_access.Count == 0) { res.result = 5;//权限不存在 return(Ok(res)); } } var search_stu_access = (from it in db.accountaccess where it.studentid == sad.stuid && it.classid == sad.accessclass select it).ToList(); if (search_stu_access.Count == 0) { res.result = 6;//根本没有该权限 return(Ok(res)); } try { db.accountaccess.Remove(search_stu_access[0]); if (db.SaveChanges() == 0) { res.result = 4;//服务器错误 return(Ok(res)); } res.result = 1; return(Ok(res)); } catch { res.result = 3; return(Ok(res)); } } }