public async Task <IActionResult> Chart(int?id, int?id2)
        {
            HttpResponseMessage response;

            if (String.IsNullOrEmpty(id2.ToString()))
            {
                response = await NwbaAPI.InitializeClient().GetAsync($"api/transaction/{id}");
            }
            else
            {
                response = await NwbaAPI.InitializeClient().GetAsync($"api/transaction/{id}/{id2}");
            }
            ViewBag.AccountNumber = id;
            if (!response.IsSuccessStatusCode)
            {
                throw new Exception();
            }
            var           result       = response.Content.ReadAsStringAsync().Result;
            var           transactions = JsonConvert.DeserializeObject <List <Transaction> >(result);
            var           SortedList   = transactions.OrderBy(o => o.ModifyDate).ToList();
            List <string> date         = new List <string>();

            foreach (var t in SortedList)
            {
                date.Add(t.ModifyDate.ToString("dd/MM/yyyy"));
            }
            var chartViewModelList = date.GroupBy(x => x)
                                     .Select(g => new ChartViewModel {
                Date = g.Key, Count = g.Count()
            })
                                     .ToList();

            return(View(chartViewModelList));
        }
        public async Task <IActionResult> BlockBillpay(int?id, int?id2)
        {
            var response = await NwbaAPI.InitializeClient().GetAsync($"api/billpay/{id}/{id2}");

            var result  = response.Content.ReadAsStringAsync().Result;
            var billpay = JsonConvert.DeserializeObject <BillPay>(result);

            return(View(billpay));
        }
Example #3
0
        public IActionResult DeleteConfirmed(int id)
        {
            var response = NwbaAPI.InitializeClient().DeleteAsync($"api/customer/{id}").Result;

            if (response.IsSuccessStatusCode)
            {
                return(RedirectToAction("Index", "Dashboard"));
            }

            return(NotFound());
        }
Example #4
0
        //the page that manage each user
        public async Task <IActionResult> Manage(int id)
        {
            var response = await NwbaAPI.InitializeClient().GetAsync($"api/customer/{id}");

            if (!response.IsSuccessStatusCode)
            {
                throw new Exception();
            }

            var result   = response.Content.ReadAsStringAsync().Result;
            var customer = JsonConvert.DeserializeObject <Customer>(result);

            return(View(customer));
        }
        public async Task <IActionResult> BlockLogin(int id)
        {
            var response = await NwbaAPI.InitializeClient().GetAsync($"api/login/{id}");

            if (!response.IsSuccessStatusCode)
            {
                throw new Exception();
            }

            var result = response.Content.ReadAsStringAsync().Result;
            var user   = JsonConvert.DeserializeObject <Login>(result);

            ViewBag.CustomerID = id;

            return(View(user));
        }
        public async Task <IActionResult> BlockBillpay(int?id, int?id2, BillPay billpay)
        {
            var content  = new StringContent(JsonConvert.SerializeObject(billpay), Encoding.UTF8, "application/json");
            var response = NwbaAPI.InitializeClient().PutAsync("api/billpay", content).Result;

            //if success, get new billpay and display in the view
            if (response.IsSuccessStatusCode)
            {
                var newResponse = await NwbaAPI.InitializeClient().GetAsync($"api/billpay/{id}/{id2}");

                var result     = newResponse.Content.ReadAsStringAsync().Result;
                var newBillpay = JsonConvert.DeserializeObject <BillPay>(result);
                return(View(newBillpay));
            }
            return(View(billpay));
        }
        public async Task <IActionResult> BillpayList(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var response = await NwbaAPI.InitializeClient().GetAsync($"api/billpay/{id}");

            if (!response.IsSuccessStatusCode)
            {
                throw new Exception();
            }
            var result   = response.Content.ReadAsStringAsync().Result;
            var billPays = JsonConvert.DeserializeObject <List <BillPay> >(result);

            return(View(billPays));
        }
Example #8
0
        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 = NwbaAPI.InitializeClient().PutAsync("api/customer", content).Result;

                if (response.IsSuccessStatusCode)
                {
                    return(RedirectToAction("Index", "Dashboard"));
                }
            }

            return(View(customer));
        }
        public async Task <IActionResult> BlockLoginAsync(int id, Login user)
        {
            if (id != user.CustomerID)
            {
                return(NotFound());
            }

            var content  = new StringContent(JsonConvert.SerializeObject(user), Encoding.UTF8, "application/json");
            var response = NwbaAPI.InitializeClient().PutAsync("api/login", content).Result;

            //if success, get new user and display in the view
            if (response.IsSuccessStatusCode)
            {
                var newResponse = await NwbaAPI.InitializeClient().GetAsync($"api/login/{id}");

                var result  = newResponse.Content.ReadAsStringAsync().Result;
                var newUser = JsonConvert.DeserializeObject <Login>(result);
                return(View(newUser));
            }
            return(View(user));
        }
        public async Task <IActionResult> TransactionHistory(int?id, int?id2, int page = 1)
        {
            HttpResponseMessage response;
            const int           pageSize = 6;

            if (!id2.HasValue)
            {
                response = await NwbaAPI.InitializeClient().GetAsync($"api/transaction/{id}");
            }
            else
            {
                response = await NwbaAPI.InitializeClient().GetAsync($"api/transaction/{id}/{id2}");
            }
            ViewBag.AccountNumber = id;
            if (!response.IsSuccessStatusCode)
            {
                throw new Exception();
            }
            var result       = response.Content.ReadAsStringAsync().Result;
            var transactions = JsonConvert.DeserializeObject <List <Transaction> >(result);

            return(View(transactions.ToPagedList(page, pageSize)));
        }