public async Task <IActionResult> Index(string searchString) { var response = await BankApi.InitializeClient().GetAsync("api/Customers"); if (!response.IsSuccessStatusCode) { throw new Exception(); } //Storing the response details recieved from web api. var result = response.Content.ReadAsStringAsync().Result; //Deserializing the response recieved from web api and storing into a list. var customers = JsonConvert.DeserializeObject <List <Customer> >(result); var customers1 = from m in customers select m; if (!String.IsNullOrEmpty(searchString)) { customers1 = customers1.Where(s => s.CustomerName.Contains(searchString)); } return(View(customers1.ToList())); }
public IActionResult DeleteConfirmed(int id) { var response = BankApi.InitializeClient().DeleteAsync($"api/Customers/{id}").Result; if (response.IsSuccessStatusCode) { return(RedirectToAction("Index")); } return(NotFound()); }
public async Task <IActionResult> Showuser() { if (HttpContext.Session.GetString("AdminID") == null) { return(RedirectToAction("Login", "Adminlogin")); } else { if (HttpContext.Session.GetString("AdminID").Length == 0) { return(RedirectToAction("Index", "Adminlogin")); } else { List <Customer> Customers = new List <Customer>(); HttpClient client = _api.InitializeClient(); HttpResponseMessage res = await client.GetAsync("api/Bank"); if (res.IsSuccessStatusCode) { var results = res.Content.ReadAsStringAsync().Result; Customers = JsonConvert.DeserializeObject <List <Customer> >(results); } return(View(Customers)); } } }
public static async Task <bool> CheckBlockAsync(int id) { var response = await BankApi.InitializeClient().GetAsync($"api/Logins/{id}"); if (!response.IsSuccessStatusCode) { throw new Exception(); } var result = response.Content.ReadAsStringAsync().Result; var login = JsonConvert.DeserializeObject <Login>(result); return(login.Block); }
public IActionResult Create(Customer customer) { if (ModelState.IsValid) { var content = new StringContent(JsonConvert.SerializeObject(customer), Encoding.UTF8, "application/json"); var response = BankApi.InitializeClient().PostAsync("api/Customers", content).Result; if (response.IsSuccessStatusCode) { return(RedirectToAction("Index")); } } return(View(customer)); }
public async Task <IActionResult> Index(string searchString) { var response = await BankApi.InitializeClient().GetAsync("api/BillPays"); /* if (!response.IsSuccessStatusCode) * throw new Exception();*/ //Storing the response details recieved from web api. var result = response.Content.ReadAsStringAsync().Result; //Deserializing the response recieved from web api and storing into a list. var BillPays = JsonConvert.DeserializeObject <List <BillPay> >(result); return(View(BillPays.ToList())); }
public async Task <IActionResult> Reverse(int id) { var response = await BankApi.InitializeClient().GetAsync($"api/BillPays/{id}"); if (!response.IsSuccessStatusCode) { throw new Exception(); } var result = response.Content.ReadAsStringAsync().Result; var billPay = JsonConvert.DeserializeObject <BillPay>(result); billPay.Block = !billPay.Block; var content = new StringContent(JsonConvert.SerializeObject(billPay), Encoding.UTF8, "application/json"); response = BankApi.InitializeClient().PutAsync("api/BillPays", content).Result; return(RedirectToAction(nameof(Index))); }
// GET: Customers/Edit/1 public async Task <IActionResult> Edit(int?id) { if (id == null) { return(NotFound()); } var response = await BankApi.InitializeClient().GetAsync($"api/Customers/{id}"); if (!response.IsSuccessStatusCode) { throw new Exception(); } var result = response.Content.ReadAsStringAsync().Result; var customer = JsonConvert.DeserializeObject <Customer>(result); return(View(customer)); }
public IActionResult Edit(int id, Customer customer) { if (id != customer.CustomerID) { return(NotFound()); } if (ModelState.IsValid) { var content = new StringContent(JsonConvert.SerializeObject(customer), Encoding.UTF8, "application/json"); var response = BankApi.InitializeClient().PutAsync("api/Customers", content).Result; if (response.IsSuccessStatusCode) { return(RedirectToAction(nameof(Profile), new { id = customer.CustomerID })); } } return(View(customer)); }
public async Task <IActionResult> Block(int id) { var response = await BankApi.InitializeClient().GetAsync($"api/Logins/{id}"); if (!response.IsSuccessStatusCode) { throw new Exception(); } var result = response.Content.ReadAsStringAsync().Result; var login = JsonConvert.DeserializeObject <Login>(result); login.Block = true; login.ModifyDate = DateTime.UtcNow; var content = new StringContent(JsonConvert.SerializeObject(login), Encoding.UTF8, "application/json"); response = BankApi.InitializeClient().PutAsync("api/Logins", content).Result; return(RedirectToAction(nameof(Index))); }
// GET: Transactions/ViewTransaction public async Task <IActionResult> ViewTransaction() { var id = TempData["customerId"]; DateTime date1 = DateTime.Parse(HttpContext.Session.GetString("Date1")); DateTime date2 = DateTime.Parse(HttpContext.Session.GetString("Date2")); string s = string.Format("api/Transactions/{0}", id); var response = await BankApi.InitializeClient().GetAsync(s); if (!response.IsSuccessStatusCode) { throw new Exception(); } // Storing the response details recieved from web api. var result = response.Content.ReadAsStringAsync().Result; // Deserializing the response recieved from web api and storing into a list. var transactions = JsonConvert.DeserializeObject <List <Transaction> >(result); TimeZoneInfo cstZone = TimeZoneInfo.FindSystemTimeZoneById("AUS Eastern Standard Time"); foreach (Transaction transaction in transactions) { transaction.TransactionTimeUtc = TimeZoneInfo.ConvertTimeFromUtc(transaction.TransactionTimeUtc, cstZone); } var selectedTransactions = from transaction in transactions where transaction.TransactionTimeUtc.CompareTo(date1) >= 0 && transaction.TransactionTimeUtc.CompareTo(date2) <= 0 select transaction; String jsonString = JsonConvert.SerializeObject(selectedTransactions); HttpContext.Session.SetString(sessionKey, jsonString); return(View(selectedTransactions)); }
public async Task <IActionResult> Showgraph() { List <Customer> Customers = new List <Customer>(); List <Transaction> Transaction = new List <Transaction>(); List <Account> Account = new List <Account>(); HttpClient client = _api.InitializeClient(); HttpResponseMessage res = await client.GetAsync("api/Bank"); if (res.IsSuccessStatusCode) { var results = res.Content.ReadAsStringAsync().Result; Customers = JsonConvert.DeserializeObject <List <Customer> >(results); } List <int> cust_city = new List <int>(); var city = Customers.Select(x => x.City).Distinct().ToList(); foreach (var item in city) { cust_city.Add(Customers.Count(x => x.City == item)); } ViewBag.city = JsonConvert.SerializeObject(city.ToList()); ViewBag.Rep = JsonConvert.SerializeObject(cust_city.ToList()); //Deposit & Withdraw string[] Transactiontype = { "Withdraw", "Deposit" }; HttpResponseMessage res1 = await client.GetAsync("api/Transactions"); if (res1.IsSuccessStatusCode) { var results = res1.Content.ReadAsStringAsync().Result; _logger.LogInformation(" API CALL FROM TRANSACTION {0}", results); Transaction = JsonConvert.DeserializeObject <List <Transaction> >(results); } int no_of_deposit = 0; int no_of_withdraw = 0; foreach (var groupItem in Transaction) { var depositType = groupItem.TransactionType.ToString(); // _logger.LogInformation(" TYPE: {0}", groupItem.TransactionType.ToString()); if (depositType == "Withdraw") { no_of_withdraw++; } if (depositType == "Deposit") { no_of_deposit++; } } //List<int> no_of_deposit = new List<int>(); //var no_of_withdraw = Transaction.Count(x => x.TransactionType.Equals("Withdraw")); //var no_of_deposit = Transaction.Count(x => x.TransactionType.Equals("Deposit")); _logger.LogInformation(" TOTAL DEPOSIT: {0}", no_of_deposit); _logger.LogInformation(" TOTAL WITHDRAW: {0}", no_of_withdraw); int[] terms = new int[2]; terms[0] = no_of_withdraw; terms[1] = no_of_deposit; ViewBag.Transactiontype = JsonConvert.SerializeObject(Transactiontype); ViewBag.terms = JsonConvert.SerializeObject(terms); return(View()); }