예제 #1
0
        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));
                }
            }
        }
예제 #2
0
        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 }));
            }
        }
예제 #3
0
 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));
             }
         }
     }
 }
예제 #4
0
        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));
                }
            }
        }
예제 #5
0
 public IHttpActionResult login(loginformation log)
 {
     using (var db = new oucfreetalkEntities())
     {
         var stu = db.students.FirstOrDefault(a => a.id == log.account);
         return(Ok(stu));
     }
 }
예제 #6
0
 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));
     }
 }
예제 #7
0
        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));
                }
            }
        }
예제 #8
0
        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));
            }
        }
예제 #9
0
 /*
  * //检查是否拥有权限
  * //
  */
 public bool IfYouHaveAcess(int access, string StuId)
 {
     using (var db = new oucfreetalkEntities())
     {
         var search = (from it in db.accountaccess
                       where it.studentid == StuId && it.classid == access
                       select it).ToList();
         return((search.Count == 0) ? false : true);
     }
 }
예제 #10
0
 /*
  * //检查是板块是否存在
  * //
  */
 public bool IfClassExist(string classname)
 {
     using (var db = new oucfreetalkEntities())
     {
         var search = (from it in db.postclass
                       where it.name == classname && it.state == true
                       select it).ToList();
         return((search.Count == 0) ? false : true);
     }
 }
예제 #11
0
        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));//返回数据
                }
            }
        }
예제 #12
0
        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));
                    }
                }
            }
        }
예제 #13
0
        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));
            }
        }
예제 #14
0
        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));
                }
            }
        }
예제 #15
0
        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));
            }
        }
예제 #16
0
 private bool IfExist(string id)
 {
     using (var db = new oucfreetalkEntities())
     {
         var se = db.students.FirstOrDefault(a => a.id == id);
         if (se == null)
         {
             return(false);
         }
         else
         {
             return(true);
         }
     }
 }
예제 #17
0
        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));
                }
            }
        }
예제 #18
0
        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));
                }
            }
        }
예제 #19
0
        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 }));
            }
        }
예제 #20
0
        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));
                }
            }
        }
예제 #21
0
        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));
            }
        }
예제 #22
0
        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));
                }
            }
        }
예제 #23
0
        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 }));
            }
        }
예제 #24
0
        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));
            }
        }
예제 #25
0
        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));
            }
        }
예제 #26
0
 /*
  * //是否登录
  * //
  */
 public string IfLogin()
 {
     try
     {
         string stuid = HttpContext.Current.Session["sid"].ToString();
         using (var db = new oucfreetalkEntities())
         {
             var re = db.students.FirstOrDefault(a => a.id == stuid);
             if (re == null)
             {
                 return("");
             }
             else
             {
                 return(stuid);
             }
         }
     }
     catch
     {
         return("");
     }
 }
예제 #27
0
        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));
            }
        }
예제 #28
0
        public IHttpActionResult SearchPost(SearchData sd)
        {
            int perpage             = 20;
            List <SearchReturn> srd = new List <SearchReturn>();

            using (var db = new oucfreetalkEntities())
            {
                //查询主题
                var search_post = (from it in db.posts
                                   join it2 in db.students on it.owner equals it2.id
                                   where it.state == true && (it.title.Contains(sd.searchtext) || it.contenttext.Contains(sd.searchtext))
                                   select new
                {
                    it.title,
                    it.contenttext,
                    it.id,
                    it.updatetime,
                    it2.nikename,
                    stuid = it2.id
                }).ToList();
                for (int i = 0; i < search_post.Count; i++)
                {
                    SearchReturn srtemp = new SearchReturn();
                    srtemp.srtype     = 2;                               //类型2帖子
                    srtemp.postid     = search_post[i].id.ToString();    //帖子id
                    srtemp.postname   = search_post[i].title.ToString(); //贴子标题
                    srtemp.createtime = search_post[i].updatetime;       //帖子最后更新时间
                    srtemp.stuid      = search_post[i].stuid;
                    srtemp.nikename   = search_post[i].nikename;
                    srtemp.replytext  = search_post[i].contenttext;
                    srd.Add(srtemp);
                }

                //搜索楼层
                var search_post_s = (from it in db.postc
                                     join it2 in db.posts on it.ownpost equals it2.id
                                     join it3 in db.students on it.owner equals it3.id
                                     where it.state == true && it.body.Contains(sd.searchtext)
                                     select new
                {
                    it.body,
                    it.id,
                    it.createtime,
                    postname = it2.title,
                    postid = it2.id,
                    nikename = it3.nikename,
                    stuid = it3.id
                }).ToList();
                for (int i = 0; i < search_post_s.Count; i++)
                {
                    SearchReturn srtemp = new SearchReturn();
                    srtemp.srtype     = 3;
                    srtemp.postid     = search_post_s[i].postid.ToString();
                    srtemp.stuid      = search_post_s[i].stuid;
                    srtemp.nikename   = search_post_s[i].nikename;
                    srtemp.replytext  = search_post_s[i].body;
                    srtemp.commentsid = search_post_s[i].id.ToString();
                    srtemp.postname   = search_post_s[i].postname;
                    srtemp.createtime = search_post_s[i].createtime;
                    srd.Add(srtemp);
                }

                var dd = (from it in db.students
                          where it.nikename == sd.searchtext
                          select it).ToList();
                srd.OrderByDescending(a => a.createtime);
                for (int i = 0; i < dd.Count; i++)
                {
                    SearchReturn srtemp = new SearchReturn();
                    srtemp.srtype   = 1;
                    srtemp.ico      = dd[i].pic;
                    srtemp.nikename = dd[i].nikename;
                    srtemp.stuid    = dd[i].id;
                    srd.Insert(0, srtemp);
                }
                //计算页数
                int allcount = srd.Count;
                int allpage  = allcount / perpage;
                if (allcount % perpage != 0)
                {
                    allpage++;
                }
                var search = srd.Skip((sd.index - 1) * perpage).Take(perpage);

                return(Ok(new { search, allpage }));
            }
        }
예제 #29
0
        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));
                }
            }
        }
예제 #30
0
        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));
                }
            }
        }