Пример #1
0
        public static async Task <bool> insertBankAcc(BankAccDetails b)
        {
            string url = "http://172.18.12.224/Api/AddDBEntries/AddBankAccount";

            using (var client = new HttpClient())
            {
                var request     = JsonConvert.SerializeObject(b);
                var buffer      = Encoding.UTF8.GetBytes(request);
                var bytecontent = new ByteArrayContent(buffer);
                bytecontent.Headers.ContentType = new MediaTypeHeaderValue("application/json");

                HttpResponseMessage res = await client.PostAsync(url, bytecontent);

                Console.WriteLine(b.AccountNum);
                if (res.IsSuccessStatusCode)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }
Пример #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Reading data");
            using (StreamReader r = new StreamReader("empOut.json"))
            {
                string json = r.ReadToEnd();
                employees = JsonConvert.DeserializeObject <List <Employee> >(json);
            }

            using (StreamReader r = new StreamReader("compOut.json"))
            {
                string json = r.ReadToEnd();
                companies = JsonConvert.DeserializeObject <List <Company> >(json);
            }

            Console.WriteLine("Processing Employees");
            foreach (var item in employees)
            {
                BankAccDetails acc = new BankAccDetails()
                {
                    AccountBalance = new Random().Next(100000000, 999999999),
                    AccountNum     = item.AccountNumber,
                    AccStatus      = AccountStatus.Active,
                    BankCode       = (BankCode)item.Bank.BankId
                };

                CardDetail c = new CardDetail()
                {
                    AccountBalance = new Random().Next(100000000, 999999999),
                    CardNumber     = item.CardNumber,
                    CardStatus     = AccountStatus.Active,
                    Currency       = CurrencyEnum.ZAR,
                    BankCode       = (BankCode)item.Bank.BankId,
                    CardClass      = CardClassification.None
                };

                bankAcc.Add(acc);
                cards.Add(c);
            }

            Console.WriteLine("Processing Companies");
            foreach (var item in companies)
            {
                BankAccDetails acc = new BankAccDetails()
                {
                    AccountBalance = new Random().Next(100000000, 999999999),
                    AccountNum     = item.AccountNumber,
                    AccStatus      = AccountStatus.Active,
                    BankCode       = (BankCode)item.Bank.BankId
                };

                CardDetail c = new CardDetail()
                {
                    AccountBalance = new Random().Next(100000000, 999999999),
                    CardNumber     = item.CardNumber,
                    CardStatus     = AccountStatus.Active,
                    Currency       = CurrencyEnum.ZAR,
                    BankCode       = (BankCode)item.Bank.BankId,
                    CardClass      = item.PaymentType == PaymentType.VISA ? CardClassification.Visa : CardClassification.None
                };

                bankAcc.Add(acc);
                cards.Add(c);
            }

            Console.WriteLine("Submitting bank accounts");
            foreach (var item in bankAcc)
            {
                Console.WriteLine(insertBankAcc(item).GetAwaiter().GetResult());
            }
            Console.WriteLine("Submitting cards");
            foreach (var item in cards)
            {
                Console.WriteLine(insertCards(item).GetAwaiter().GetResult());
            }

            Console.WriteLine("Completed");
            Console.WriteLine();
            Console.WriteLine(bankAcc.Count);
            Console.WriteLine(cards.Count);
            Console.ReadKey();
        }