// GET: api/User
        public HttpResponseMessage Get()
        {
            IEnumerable <dynamic> userList = userRepository.GetAllUser();
            var date = UserToJsonRepository.ToJson(userList);
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            string str = serializer.Serialize(date);

            return(new HttpResponseMessage {
                Content = new StringContent(str, Encoding.UTF8, "application/json")
            });
        }
        public User Login(string loginname, string password)
        {
            if (loginname == null || password == null)
            {
                throw new Exception("用户名或密码不能为空!");
            }
            IEnumerable <dynamic> flag = userRepository.LoginCheck(loginname, password);
            User user = UserToJsonRepository.ToUser(flag);

            if (user != null)
            {
                HttpContext.Current.Session.Add("User", user);
                return((User)HttpContext.Current.Session["User"]);
            }
            else
            {
                throw new Exception("用户不存在!");
            }
        }