Exemplo n.º 1
0
        // 新增API帳號
        public IActionResult InsertApiUser([FromBody] B2dApiAccount acc)
        {
            try
            {
                //var accountRepo = (B2dApiAccountRepository)HttpContext.RequestServices.GetService(typeof(B2dApiAccountRepository));
                var services    = HttpContext.RequestServices.GetServices <IB2dAccountRepository>();
                var accountRepo = (B2dApiAccountRepository)services.First(o => o.GetType() == typeof(B2dApiAccountRepository));

                var aesUserData = User.Identities.SelectMany(i => i.Claims.Where(c => c.Type == ClaimTypes.UserData).Select(c => c.Value)).FirstOrDefault();
                var UserData    = JsonConvert.DeserializeObject <B2dApiAccount>(AesCryptHelper.aesDecryptBase64(aesUserData, Website.Instance.AesCryptKey));
                var crt_user    = UserData.EMAIL;
                acc.COMPANY_XID = UserData.COMPANY_XID;
                acc.TEL_AREA    = UserData.TEL_AREA;

                accountRepo.InsertAccount(acc, crt_user);
                return(Json("OK"));
            }
            catch (Exception ex)
            {
                return(Json(ex.ToString()));
            }
        }
Exemplo n.º 2
0
        // API修改帳號資料
        public IActionResult ApiUserUpdate([FromBody] B2dApiAccount acc)
        {
            Dictionary <string, object> jsonData = new Dictionary <string, object>();

            try
            {
                var services  = HttpContext.RequestServices.GetServices <IB2dAccountRepository>();
                var acctRepos = services.First(o => o.GetType() == typeof(B2dApiAccountRepository));
                var upd_user  = User.Identities.SelectMany(i => i.Claims.Where(c => c.Type == "Account").Select(c => c.Value)).FirstOrDefault();

                //更新分銷商公司資料
                acctRepos.UpdateAccount(acc, upd_user);
                jsonData["status"] = "OK";
            }
            catch (Exception ex)
            {
                jsonData.Clear();
                jsonData.Add("status", "FAIL");
                jsonData.Add("msg", ex.Message);
            }

            return(Json(jsonData));
        }