Exemple #1
0
        public async Task <IActionResult> Index([FromQuery] string token)
        {
            var userInfo = await etgService.RegisterUserAsync(token);

            ViewData["UserName"] = userInfo.Name;
            return(View());
        }
        /// <summary>
        /// 上传客户数据
        /// </summary>
        /// <param name="context"></param>
        /// <param name="next"></param>
        /// <returns></returns>
        public async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
        {
            string token = context.HttpContext.Request.Query["token"];

            GZCNegotiation.Services.EtgInfoLib.Data.UserInfo    userInfo;
            GZCNegotiation.Services.EtgInfoLib.Data.CompanyInfo companyInfo;
            string errorType  = string.Empty;
            string errorDetal = string.Empty;

            //带Token参数则从远程API获取用户信息和企业信息
            if (!string.IsNullOrEmpty(token))
            {
                errorDetal = await etgService.RegisterUserAsync(token);

                if (!string.IsNullOrEmpty(errorDetal))
                {
                    errorType      = "RequestToken无效,请重新登陆。";
                    context.Result = new RedirectToActionResult("Authentication", "Error", new { errorType, errorDetal });
                    return;
                }
            }
            //从Session中读取User信息
            try
            {
                userInfo = etgService.GetCurrentUser();
            }
            catch (Exception ex)
            {
                errorType      = "Session已过期,请重新登陆。";
                errorDetal     = ex.ToString();
                context.Result = new RedirectToActionResult("Authentication", "Error", new { errorType, errorDetal });
                return;
            }
            //从Session中读取Company信息
            try
            {
                companyInfo = etgService.GetCompanyInfo();
            }
            catch (Exception ex)
            {
                errorType      = "CompanyInfo获取失败,请先实名认证。";
                errorDetal     = ex.ToString();
                context.Result = new RedirectToActionResult("Authentication", "Error", new { errorType, errorDetal });
                return;
            }

            //获取API返回结果
            var result = await GetUdeskCustomerImport(userInfo, companyInfo);

            await next();
        }