Ejemplo n.º 1
0
        /// <summary>
        /// It takes all the accounts from Account API
        /// </summary>
        /// <returns></returns>
        public List <Account> GetAccounts()
        {
            try
            {
                List <Account> acc = null;

                HttpClient          client   = _client.AccountClient();
                HttpResponseMessage response = client.GetAsync("api/Account/getAllCustomerAccounts").Result;
                if (response.StatusCode == System.Net.HttpStatusCode.InternalServerError)
                {
                    throw new NullReferenceException("Issue in getting accounts from Account API");
                }
                var result = response.Content.ReadAsStringAsync().Result;
                acc = JsonConvert.DeserializeObject <List <Account> >(result);

                return(acc);
            }
            catch (NullReferenceException e)
            {
                _log4net.Error(e.Message);
                throw e;
            }
            catch (Exception e)
            {
                _log4net.Error("Exception in getting accounts from Account API");
                throw e;
            }
        }
Ejemplo n.º 2
0
        public TransactionStatus ApplyServiceCharge(int AccountID, int Amount)
        {
            try
            {
                _client = new Client();
                HttpClient          client     = _client.AccountClient();
                dynamic             model      = new { AccountId = AccountID, amount = Amount };
                var                 jsonString = JsonConvert.SerializeObject(model);
                var                 obj        = new StringContent(jsonString, System.Text.Encoding.UTF8, "application/json");
                HttpResponseMessage response   = client.PostAsync("api/Account/withdraw", obj).Result;
                if (response.StatusCode == System.Net.HttpStatusCode.InternalServerError)
                {
                    throw new NullReferenceException("Issue in connecting with Transaction API");
                }
                var result = response.Content.ReadAsStringAsync().Result;
                TransactionStatus status = JsonConvert.DeserializeObject <TransactionStatus>(result);

                return(status);
            }
            catch (NullReferenceException e)
            {
                _log4net.Error(e.Message);
                throw e;
            }
            catch (Exception e)
            {
                _log4net.Error("Exception thrown while withdrawing Charge from transaction API");
                throw e;
            }
        }
        /// <summary>
        /// It takes all the accounts from Account API
        /// </summary>
        /// <returns></returns>
        public List <Account> GetAccounts()
        {
            try
            {
                List <Account> acc = null;

                HttpClient          client   = _client.AccountClient();
                HttpResponseMessage response = client.GetAsync("api/Account/getAllCustomerAccounts").Result;
                var result = response.Content.ReadAsStringAsync().Result;
                acc = JsonConvert.DeserializeObject <List <Account> >(result);

                return(acc);
            }
            catch (Exception e)
            {
                _log4net.Error("Exception in getting accounts from Account API");
                throw e;
            }
        }
Ejemplo n.º 4
0
        public RuleStatus evaluateMinBal(int balance, int AccountId)
        {
            try
            {
                _client = new Client();
                HttpClient          client   = _client.AccountClient();
                HttpResponseMessage response = client.GetAsync("api/Account/getAccount/" + AccountId).Result;
                if (response.StatusCode == System.Net.HttpStatusCode.InternalServerError)
                {
                    throw new NullReferenceException("issue in connecting with Account API");
                }
                var     result  = response.Content.ReadAsStringAsync().Result;
                Account account = JsonConvert.DeserializeObject <Account>(result);

                if (balance >= account.minBalance)
                {
                    return new RuleStatus {
                               Status = "allowed"
                    }
                }
                ;
                else if (balance < account.minBalance)
                {
                    return new RuleStatus {
                               Status = "denied"
                    }
                }
                ;
                else
                {
                    return new RuleStatus {
                               Status = "NA"
                    }
                };
            }
            catch (NullReferenceException e)
            {
                _log4net.Error("The account is not returned from Account API.", e);
                throw e;
            }
            catch (Exception e)
            {
                _log4net.Error("Exception occured while getting Account by ID");
                throw e;
            }
        }