public async Task <AvihangTokens> GetToken(int terminalId)
        {
            AuthResponse  authResponse  = new AuthResponse();
            AvihangTokens avihangTokens = new AvihangTokens();

            try
            {
                avihangTokens = _avihangTokensRepository.GetByTerminalId(terminalId.ToString()).Result;
                if (TokenState(avihangTokens) != Framework.Utility.TokenState.Ok)
                {
                    var           providers    = _providersRepository.GetById((int)ProviderType.Avihang).Result;
                    var           providerApis = _providerApisRepository.GetByProviderId((int)ProviderType.Avihang).Result;
                    string        ApiUrl       = providerApis.Where(a => a.Id == (int)AvihangApis.Token).FirstOrDefault().Url;
                    string        Uri          = $"{(providers.BaseUrl.EndsWith("/") ? providers.BaseUrl : providers.BaseUrl + "/")}{(ApiUrl.StartsWith("/") ? ApiUrl.Remove(0, 1) : ApiUrl)}";
                    BaseApiHeader header       = new BaseApiHeader(Uri, 1, "application/json");
                    AuthRequest   authRequest  = new AuthRequest(providers.UserName, providers.Password, terminalId);
                    var           preResponse  = _factory.GetChannel().CallWebApi <BaseApiHeader, AuthRequest>(header, authRequest);
                    avihangTokens.ResDate = DateTime.Now;
                    authResponse          = Utilities.JsonTextToModel <AuthResponse>(preResponse.Content);
                    authResponse.CopyPropertiesTo(avihangTokens);
                    authResponse.info.CopyPropertiesTo(avihangTokens);
                    avihangTokens.TerminalId     = terminalId.ToString();
                    authResponse.info.terminalId = terminalId;
                    await _avihangTokensRepository.Add(avihangTokens);

                    await _avihangTokensRepository.CommitAsync();
                }
            }
            catch (Exception ex)
            {
                _logService.LogText(ex.Message);
                throw;
            }


            return(avihangTokens);
        }