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 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));
            }
        }