コード例 #1
0
        public ActionResult Index()
        {
            try
            {
                var db         = new Common.DBContext().Instance;
                int?useCount   = db.Queryable <MhysUserInfo>().Sum(x => x.LoginCount);
                int?totalCount = db.Queryable <MhysUserInfo>().Count();
                ViewBag.useCount   = useCount;
                ViewBag.totalCount = totalCount;
            }
            catch (Exception)
            {
            }

            return(View());
        }
コード例 #2
0
        public UserInfo CourseQuery(string login_name, string login_pass)
        {
            LoginInfoPC(login_name, login_pass);//顺便把PC协议的COOKIE也留下来

            UserInfo myUserInfo   = new UserInfo();
            JObject  LoginInfo    = JObject.Parse(GetUrlContent(url_api + "api//v1/web_user?" + "login_name=" + login_name + "&login_pass="******"&sign=" + sign));
            string   userId       = LoginInfo["data"]["id"].ToString();
            string   courseIdList = "";

            for (int i = 0; i < LoginInfo["data"]["course_id_list"].ToArray().Length; i++)
            {
                courseIdList += LoginInfo["data"]["course_id_list"].ToArray()[i].ToString();
                if (i < LoginInfo["data"]["course_id_list"].ToArray().Length - 1)
                {
                    courseIdList += ",";
                }
            }
            courseIdList = System.Web.HttpUtility.UrlEncode(courseIdList);
            JObject courseInfoData = JObject.Parse(GetUrlContent(url_api + "api//v1/course_info?&id_list=" + courseIdList + "&user_id=" + userId + "&sign=" + sign));

            for (int i = 0; i < courseInfoData["data"].Count(); i++)
            {
                myUserInfo.CourseInfoList.Add(new CourseInfo
                {
                    Id   = courseInfoData["data"][i]["id"].ToString(),
                    Name = courseInfoData["data"][i]["name"].ToString()
                });
            }
            myUserInfo.UserId   = LoginInfo["data"]["id"].ToString();
            myUserInfo.UserName = LoginInfo["data"]["name"].ToString();

            //添加到数据库,用于统计
            #region
            try
            {
                var db     = new Common.DBContext().Instance;
                var getall = db.Queryable <MhysUserInfo>().ToList();
                if (!getall.Any(x => x.LoginName == login_name))
                {
                    db.Insertable(new MhysUserInfo()
                    {
                        LoginName  = login_name,
                        UserName   = myUserInfo.UserName,
                        LoginCount = 1
                    }).ExecuteCommand();
                }
                else
                {
                    int count = getall.Where(x => x.LoginName == login_name).Select(f => f.LoginCount).ToList()[0];
                    db.Updateable(new MhysUserInfo()
                    {
                        LoginName = login_name, UserName = myUserInfo.UserName, LoginCount = count + 1
                    }).Where(f => f.LoginName == login_name).ExecuteCommand();
                }
            }
            catch (Exception)
            {
            }


            #endregion

            return(myUserInfo);
        }