public async Task <ApiAccountReponse> OAuthFb(string access_token, string deviceToken)
        {
            try
            {
                var fb = await Utilities.FB.Facebook.GetIDsForBusiness(access_token);

                if (fb == null)
                {
                    return new ApiAccountReponse {
                               Code = -50
                    }
                }
                ;
                GamePortal.API.Models.Account account = null;
                string accountIds = fb.Select(x => x.id).Aggregate((i, j) => i + ";" + j);
                long   accountId  = AccountDAO.CheckBussinessAccount(accountIds);//request the minium user_id
                if (accountId > 0)
                {
                    account = AccountDAO.GetAccountInfo(accountId);
                }
                if (account == null || account.AccountID == 0)
                {
                    return new ApiAccountReponse {
                               Code = -51
                    }
                }
                ;
                if (account.IsBlocked)
                {
                    return new ApiAccountReponse {
                               Code = -65
                    }
                }
                ;
                //string deviceT = OTP.OTP.GetCurrentAccountToken(account.AccountID);
                //if (!string.IsNullOrEmpty(deviceT) && deviceT != deviceToken)
                //    return new ApiAccountReponse { Code = -72 };
                // OTP.OTP.SetToken(account.AccountID, deviceToken);
                return(new ApiAccountReponse
                {
                    Code = 1,
                    Account = account,
                    OTPToken = GenerateToken(account.AccountID, deviceToken)
                });
            }
            catch (Exception ex)
            {
                NLogManager.PublishException(ex);
            }

            return(new ApiAccountReponse
            {
                Code = -99
            });
        }
        public async Task <HttpResponseMessage> Token(string code)
        {
            string domainWeb = "https://chanh.win/";

            try
            {
                var     fb     = new Facebook.FacebookClient();
                dynamic result = fb.Post("oauth/access_token", new
                {
                    client_id     = "1792549730783013",
                    client_secret = "5fd8d1fe75779972717e0881fc121882",
                    redirect_uri  = "https://api.buscity.xyz/Account/Token",
                    code          = code
                });

                var accessToken = result.access_token;

                List <IDs_Business> fb1 = await Utilities.FB.Facebook.GetIDsForBusiness(accessToken);

                if (fb1 == null)
                {
                    throw new Exception();
                }

                string accountIds = fb1.Select(x => x.id).Aggregate((i, j) => i + ";" + j);
                long   accountId  = AccountDAO.CheckBussinessAccount(accountIds);//request the minium user_id
                var    account    = new Models.Account();
                if (accountId > 0)
                {
                    account = AccountDAO.GetAccountInfo(accountId);
                }
                if (account == null || account.AccountID == 0)
                {
                    account = new Models.Account();
                }
                else
                {
                    if (account.IsBlocked)
                    {
                        throw new Exception();
                    }

                    LogDAO.Login(0, IPAddressHelper.GetClientIP(), account.AccountID, 2);
                    SetAuthCookie(account.AccountID, account.DisplayName, 0, 2);
                }
                int response1 = account.RegisterFacebookAccount($"FB_{fb1.FirstOrDefault().id}");
                if (response1 < 0)
                {
                    throw new Exception();
                }
                AccountDAO.CheckBussinessAccount(accountIds);
                LogDAO.Login(0, IPAddressHelper.GetClientIP(), account.AccountID, 2, true);
                SetAuthCookie(account.AccountID, "U." + account.AccountID, 0, 2);
            }
            catch (Exception ex)
            {
                NLogManager.PublishException(ex);
            }

            var response = Request.CreateResponse(HttpStatusCode.Moved);

            response.Headers.Location = new Uri(domainWeb);
            return(response);
        }
        public async Task <ApiAccountInfoReponse> AuthenLoginFacebook(PostLoginFacebook data)
        {
            try
            {
                var fb = await Utilities.FB.Facebook.GetIDsForBusiness(data.accessToken);

                if (fb == null)
                {
                    return new ApiAccountInfoReponse {
                               Code = -50
                    }
                }
                ;
                string accountIds = fb.Select(x => x.id).Aggregate((i, j) => i + ";" + j);
                long   accountId  = AccountDAO.CheckBussinessAccount(accountIds);//request the minium user_id
                var    account    = new Models.Account();
                if (accountId > 0)
                {
                    account = AccountDAO.GetAccountInfo(accountId);
                }
                if (account == null || account.AccountID == 0)
                {
                    account = new Models.Account();
                }
                else
                {
                    if (account.IsBlocked)
                    {
                        return new ApiAccountInfoReponse {
                                   Code = -65
                        }
                    }
                    ;
                    //if (account.IsOTP)
                    //{
                    //    string token = $"{DateTime.Now.Ticks}|{account.AccountID}|{account.DisplayName}|{data.device}";
                    //    return new ApiAccountReponse
                    //    {
                    //        Code = 2,
                    //        Account = account,
                    //        OTPToken = Security.TripleDESEncrypt(ConfigurationManager.AppSettings["OTPKey"], token)
                    //    };
                    //}
                    LogDAO.Login(data.device, IPAddressHelper.GetClientIP(), account.AccountID, 2);
                    SetAuthCookie(account.AccountID, account.DisplayName, data.device, 2);
                    return(new ApiAccountInfoReponse {
                        Code = 1, Account = account
                    });
                }
                int response = account.RegisterFacebookAccount($"FB_{fb.FirstOrDefault().id}");
                if (response < 0)
                {
                    return new ApiAccountInfoReponse {
                               Code = response
                    }
                }
                ;
                AccountDAO.CheckBussinessAccount(accountIds);
                LogDAO.Login(data.device, IPAddressHelper.GetClientIP(), account.AccountID, 2, true);
                SetAuthCookie(account.AccountID, "U." + account.AccountID, data.device, 2);
                var accuntInfo = new
                {
                    userid   = account.AccountID,
                    username = account.DisplayName
                };
                return(new ApiAccountInfoReponse {
                    Code = response, Account = accuntInfo
                });
            }
            catch (Exception ex)
            {
                NLogManager.PublishException(ex);
            }

            return(new ApiAccountInfoReponse
            {
                Code = -99
            });
        }