示例#1
0
        public async Task <TokenDto> AutoGetToKen(int chiCucId)
        {
            try
            {
                var _lienThongSettings = await _tenantSettingsr.GetLienThongInfoSettingsAsync(chiCucId);

                if (_lienThongSettings != null && !string.IsNullOrEmpty(_lienThongSettings.UserLienThong))
                {
                    var account = new TaiKhoanLienThongInput
                    {
                        DomainLienThong        = _lienThongSettings.DomainLienThong,
                        Password               = _lienThongSettings.PassLienThong,
                        UsernameOrEmailAddress = _lienThongSettings.UserLienThong,
                        TenancyName            = _lienThongSettings.TenantLienThong
                    };
                    var obj = await GetToken(account);

                    return(obj);
                }
                return(null);
            }
            catch (Exception ex)
            {
                _logger.Fatal(ex.Message);
                return(null);
            }
        }
示例#2
0
        public async Task <TokenDto> GetToken(TaiKhoanLienThongInput input)
        {
            try
            {
                var obj = await _callApiDomainService.GetToken(input);

                return(obj);
            }
            catch (Exception ex)
            {
                _logger.Fatal(ex.Message);
                return(null);
            }
        }
示例#3
0
        public async Task <TokenDto> GetToken(TaiKhoanLienThongInput input)
        {
            try
            {
                if (!string.IsNullOrEmpty(input.UsernameOrEmailAddress) && !string.IsNullOrEmpty(input.Password) && !string.IsNullOrEmpty(input.DomainLienThong))
                {
                    using (var client = new HttpClient())
                    {
                        string domain = input.DomainLienThong;
                        string api    = "api/Account";
                        if (string.IsNullOrEmpty(input.TenancyName))
                        {
                            input.TenancyName = "lienthong";
                        }
                        string dataJson = JsonConvert.SerializeObject(input);

                        client.BaseAddress = new Uri(domain);
                        client.DefaultRequestHeaders.Accept.Clear();
                        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

                        HttpContent content = new StringContent(dataJson, Encoding.UTF8, "application/json");
                        var         messge  = await client.PostAsync(api, content);

                        if (messge.IsSuccessStatusCode)
                        {
                            string result = await messge.Content.ReadAsStringAsync();

                            TokenDto obj = JsonConvert.DeserializeObject <TokenDto>(result);
                            return(obj);
                        }
                    }
                }
                return(null);
            }
            catch (Exception ex)
            {
                _logger.Fatal(ex.Message);
                return(null);
            }
        }