public ActionResult Sndex() { //获取轮播图 var listShouYeLunBo = IdNamesService.GetByTypeName("首页轮播图"); ViewBag.ShouYeLunBo = listShouYeLunBo; //获取公告 var listGongGao = IdNamesService.GetByTypeName("首页公告"); ViewBag.ShouYeGongGao = listGongGao; //获取快速推荐 var listTuiJian = IdNamesService.GetByTypeName("课程类型").Where(m => m.Remark == "快速推荐").ToList(); ViewBag.ShouYeTuiJian = listTuiJian; //首页视频推荐 var listVideoList = VideoService.GetAll().Take(10).ToList(); ViewBag.ShouYeVideo = listVideoList; return(View()); }
public ActionResult Index() { try { int type = 1; if (Session["CourseType"] != null && Session["CourseType"].ToString() != "") { type = int.Parse(Session["CourseType"].ToString()); } logger.Info($"type={type}"); var code = HttpContext.Request.QueryString["code"]; var openId = Session["OpenId"].ToString(); logger.Info($"openId={openId}"); //没有授权,没有获取 if (string.IsNullOrEmpty(openId) && string.IsNullOrEmpty(code)) { return(Redirect("/Authorize/Index?type=" + type)); } //有code,没有openid if (string.IsNullOrEmpty(openId) && !string.IsNullOrEmpty(code)) { //有了code之后,判断如果授权之后,获取用户信息 var content = oauth.GetUserInfo(AppId, Appsecret, code); var wxUserInfo = JsonConvert.DeserializeObject <WxUserInfo>(content); Session["OpenId"] = wxUserInfo.openid; //判断该微信号有没有注册过 UserAddDto user = new UserAddDto { AccountNumber = wxUserInfo.openid, HeadPortraitSrc = wxUserInfo.headimgurl, RegisterDataTime = DateTime.Now, UserName = wxUserInfo.nickname, WxAddress = wxUserInfo.country + "/" + wxUserInfo.province + "/" + wxUserInfo.city, Sex = wxUserInfo.sex == "1" }; logger.Info("添加用户信息," + content); UserService.AddNew(user); } //获取轮播图 var listShouYeLunBo = IdNamesService.GetByTypeName("首页轮播图"); ViewBag.ShouYeLunBo = listShouYeLunBo; //获取公告 var listGongGao = IdNamesService.GetByTypeName("首页公告"); ViewBag.ShouYeGongGao = listGongGao; //首页分类 var model = IdNamesService.GetById(type); var listCourseType = IdNamesService.GetByTypeName(model.Name); ViewBag.ShouYeCourseType = listCourseType; ViewBag.CourseTypeId = type; //var listVideoList = VideoService.GetAll().Where().Take(10).ToList(); //ViewBag.ShouYeVideo = listVideoList; return(View()); } catch (Exception ex) { logger.Error("主页加载错误", ex); return(Content(ex.Message)); } }