예제 #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 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));
                }
            }
        }
예제 #3
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));
     }
 }
예제 #4
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));
            }
        }
예제 #5
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));
                    }
                }
            }
        }
예제 #6
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));
            }
        }
예제 #7
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));
                }
            }
        }
예제 #8
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));
                }
            }
        }
예제 #9
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));
                }
            }
        }
예제 #10
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));
                }
            }
        }
예제 #11
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));
            }
        }
예제 #12
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));
                }
            }
        }
예제 #13
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));
                }
            }
        }
예제 #14
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));
            }
        }
예제 #15
0
        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));
            }
        }
예제 #16
0
        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));
                }
            }
        }
예제 #17
0
        public IHttpActionResult AddFriend(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
                    {
                        friends fd = new friends();
                        fd.focus      = userid;
                        fd.befocus    = target;
                        fd.createtime = DateTime.Now;
                        db.friends.Add(fd);
                        if (db.SaveChanges() == 0)
                        {
                            res.result = 3;//失败
                            return(Ok(res));
                        }
                        else
                        {
                            res.result = 1;//成功
                            return(Ok(res));
                        }
                    }
                }
            }
            catch
            {
                res.result = 3;//服务器错误
                return(Ok(res));
            }
        }