예제 #1
0
        // GET: Customer/Edit/1
        public async Task<IActionResult> Edit(int? id)
        {
            if (id == null)
                return NotFound();

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

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

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

            Customer c = new Customer();
            c.CustomerID = customer.CustomerID;
            c.Name = customer.Name;
            c.Tfn = customer.Tfn;
            c.AddressID = customer.Address.AddressID;
            c.Street = customer.Address.Street;
            c.City = customer.Address.City;
            c.State = customer.Address.State;
            c.PostCode = customer.Address.PostCode;
            c.Phone = customer.Address.Phone;

            return View(c);
        }
예제 #2
0
        public IActionResult Unblock(int id)
        {
            if (id < 0)
            {
                return(NotFound());
            }

            var content = new StringContent(JsonConvert.SerializeObject(id), Encoding.UTF8, "application/json");

            try
            {
                var response = NwbaApi.InitializeClient().PutAsync($"api/billpayments/{id}/unblock", content).Result;

                if (response.IsSuccessStatusCode)
                {
                    TempData["alertMessage"] = "Successfully Unblocked";
                    return(RedirectToAction("Index"));
                }
                else if (!response.IsSuccessStatusCode)
                {
                    TempData["alertMessage"] = "Already Unblocked";
                    return(RedirectToAction("Index"));
                }
            }
            catch (Exception e)
            {
                var error = e.Message;
                TempData["alertMessage"] = "Unblock when status is blocked";
            }
            return(RedirectToAction("Index"));
        }
예제 #3
0
        private async Task <bool> HasFreeTransfer()
        {
            var response = await NwbaApi.InitializeClient().GetAsync("api/transactions/");

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

            // Storing the response details recieved from web api.
            var result = response.Content.ReadAsStringAsync().Result;

            var transactions = JsonConvert.DeserializeObject <List <TransactionDto> >(result);

            int servicableTransactions = 0;

            foreach (var transaction in transactions)
            {
                if (transaction.AccountNumber == AccountNumber)
                {
                    servicableTransactions++;
                }
            }

            return(servicableTransactions < 4);
        }
예제 #4
0
        //returns the edit page of a customer
        public async Task <IActionResult> EditCustomer(int?id)
        {
            var response = await NwbaApi.InitializeClient().GetAsync("api/customers/" + id);

            if (!response.IsSuccessStatusCode)
            {
                return(RedirectToAction($"StatusCode/{response.StatusCode}"));
            }

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

            response = await NwbaApi.InitializeClient().GetAsync("api/logins/");

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

            try
            {
                var login = logins.Where(x => x.CustomerID == customer.CustomerID).FirstOrDefault();

                var customerViewModel = new EditCustomerViewModel(customer, login.Status);
                return(View(customerViewModel));
            }
            catch
            {
                return(RedirectToAction($"StatusCode/" + 204));
            }
        }
예제 #5
0
        public IActionResult Unlock(int id)
        {
            if (id < 0)
                return NotFound();
            Login locklg = new Login();
            locklg.locklogin = "******";

            var content = new StringContent(JsonConvert.SerializeObject(locklg), Encoding.UTF8, "application/json");
            try
            {
                var response = NwbaApi.InitializeClient().PutAsync($"api/customers/{id}/unlock", content).Result;

               
                if (response.IsSuccessStatusCode)
                {
                    TempData["alertMessage"] = "Successfully Unlocked";
                    return RedirectToAction("Index");
                }
                else if (!response.IsSuccessStatusCode)
                {
                    TempData["alertMessage"] = "Already Unlocked";
                    return RedirectToAction("Index");
                }
            }
            catch (Exception e)
            {
                var error = e.Message;
                TempData["alertMessage"] = "Already Unlocked";
            }
            return RedirectToAction("Index");
        }
예제 #6
0
        public async Task <IActionResult> EditCustomer(EditCustomerViewModel customerViewModel)
        {
            if (ModelState.IsValid)
            {
                var content  = new StringContent(JsonConvert.SerializeObject(customerViewModel.Customer), Encoding.UTF8, "application/json");
                var response = NwbaApi.InitializeClient().PutAsync("api/customers", content).Result;

                response = await NwbaApi.InitializeClient().GetAsync("api/logins/");

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

                var login = logins.Where(x => x.CustomerID == customerViewModel.Customer.CustomerID).FirstOrDefault();
                login.Status      = customerViewModel.LoginStatus;
                login.LockedUntil = customerViewModel.LockedUntil;

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

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


                if (response.IsSuccessStatusCode)
                {
                    return(RedirectToAction(nameof(ViewCustomers)));
                }
            }


            return(RedirectToAction(nameof(ViewCustomers)));
        }
        public async Task <IActionResult> Index(TransactionViewModel viewModel)
        {
            var custResult = await NwbaApi.InitializeClient().GetAsync("api/customers");

            var resultCustomer = custResult.Content.ReadAsStringAsync().Result;
            var customers      = JsonConvert.DeserializeObject <List <Customer> >(resultCustomer);

            List <int> customerNumbers = new List <int>();

            List <SelectListItem> customerList = new List <SelectListItem>();

            customerList.Add(new SelectListItem()
            {
                Text  = "All Transactions",
                Value = "All Transactions"
            });

            foreach (var customer in customers)
            {
                customerList.Add(new SelectListItem()
                {
                    Text  = customer.CustomerID.ToString() + " - " + customer.Name,
                    Value = customer.CustomerID.ToString()
                });
            }

            var selectedCustomerNumber = viewModel.SelectedCustomerNumber;
            var fromDate = viewModel.FromDate;
            var toDate   = viewModel.ToDate;

            var fDate = String.Format("{0:yyyy-MM-dd}", fromDate);
            var tDate = String.Format("{0:yyyy-MM-dd}", toDate);

            string query = "";

            if (selectedCustomerNumber == 0)
            {
                query = "api/transactions";
            }
            else
            {
                query = "api/customers/" + selectedCustomerNumber + "/transactions?from=" + fDate + "&to=" + tDate + "";
            }
            var tranResult = await NwbaApi.InitializeClient().GetAsync(query);

            var resultTransactions = tranResult.Content.ReadAsStringAsync().Result;
            var transactions       = JsonConvert.DeserializeObject <List <Transaction> >(resultTransactions);

            TransactionViewModel tvm = new TransactionViewModel();

            tvm.Transactions           = transactions;
            tvm.FromDate               = viewModel.FromDate;
            tvm.ToDate                 = viewModel.ToDate;
            tvm.SelectedCustomerNumber = selectedCustomerNumber;
            tvm.CustomerList           = customerList;
            return(View(tvm));
        }
        //Gets the valid transactions depending on the date and customerID
        public async Task <List <TransactionDto> > ValidTransactions()
        {
            var response = await NwbaApi.InitializeClient().GetAsync($"api/transactions/");

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

            var result       = response.Content.ReadAsStringAsync().Result;
            var transactions = JsonConvert.DeserializeObject <List <TransactionDto> >(result);

            response = await NwbaApi.InitializeClient().GetAsync("api/accounts/");

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

            result = response.Content.ReadAsStringAsync().Result;
            var accounts = JsonConvert.DeserializeObject <List <AccountDto> >(result);

            List <TransactionDto> validTransactions = new List <TransactionDto>();

            foreach (var account in accounts)
            {
                foreach (var transaction in transactions)
                {
                    //If seaching for customer ID
                    if (account.CustomerID == CustomerID && transaction.AccountNumber == account.AccountNumber)
                    {
                        if ((transaction.TransactionTime >= FromDate && transaction.TransactionTime <= ToDate) ||
                            (FromDate == DateTime.MinValue && ToDate == DateTime.MinValue))
                        {
                            validTransactions.Add(transaction);
                        }
                    }
                    //if searching for all customers within the time
                    else if (CustomerID == 0 && transaction.TransactionTime >= FromDate &&
                             transaction.TransactionTime <= ToDate)
                    {
                        validTransactions.Add(transaction);
                    }
                    //else if searching for all transactions of a certain customer
                    else if (CustomerID == 0 && FromDate == DateTime.MinValue && ToDate == DateTime.MinValue)
                    {
                        validTransactions.Add(transaction);
                    }
                }
            }

            //removes duplicates
            validTransactions = validTransactions.Distinct().ToList();

            return(validTransactions);
        }
예제 #9
0
        public async Task <IActionResult> DeleteConfirmed(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var response = await NwbaApi.InitializeClient().DeleteAsync("api/billpays/" + id);

            return(RedirectToAction("Index"));
        }
예제 #10
0
        public IActionResult DeleteConfirmed(int id)
        {
            var response = NwbaApi.InitializeClient().DeleteAsync($"api/customers/{id}").Result;

            if (response.IsSuccessStatusCode)
            {
                TempData["alertMessage"] = "Successfully Deteted";
                return RedirectToAction("Index");
            }
            
            return NotFound();
        }
예제 #11
0
        // GET: Customer/Index
        public async Task<IActionResult> Index()
        {
            var response = await NwbaApi.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 customer = JsonConvert.DeserializeObject<List<Customer>>(result);
            return View(customer);
        }
예제 #12
0
        //Views all the customers
        public async Task <IActionResult> ViewCustomers()
        {
            var response = await NwbaApi.InitializeClient().GetAsync("api/customers/");

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

            var result    = response.Content.ReadAsStringAsync().Result;
            var customers = JsonConvert.DeserializeObject <List <CustomerDto> >(result);

            return(View(customers));
        }
예제 #13
0
        //Views the details of a customer
        public async Task <IActionResult> ViewCustomer(int?id)
        {
            var response = await NwbaApi.InitializeClient().GetAsync("api/customers/" + id);

            if (!response.IsSuccessStatusCode)
            {
                return(RedirectToAction($"StatusCode/{response.StatusCode}"));
            }

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

            return(View(customer));
        }
예제 #14
0
        //gets all the billpays
        public async Task <IActionResult> Index()
        {
            var response = await NwbaApi.InitializeClient().GetAsync("api/billpays/");

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

            var result   = response.Content.ReadAsStringAsync().Result;
            var billPays = JsonConvert.DeserializeObject <List <BillPayDto> >(result);

            return(View(billPays));
        }
예제 #15
0
        // GET: Customer/Delete/1
        public async Task<IActionResult> Delete(int? id)
        {
            if (id == null)
                return NotFound();

            var response = await NwbaApi.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);
        }
예제 #16
0
        //Attempts to log the user in
        public async Task <bool> LoginUser(NwbaContext _context, string _password, string loginID, Controller controller)
        {
            bool successfull = false;

            if (Status == LoginStatus.OPEN || (Status == LoginStatus.TEMP_LOCKED && LockedUntil <= DateTime.UtcNow))
            {
                bool correctPassword = PBKDF2.Verify(PasswordHash, _password);

                //Creates a new login attempt and adds that to the database via the API
                LoginAttempt loginAttempt = new LoginAttempt
                {
                    CustomerID  = _context.Logins.Where(x => x.LoginID == loginID).FirstOrDefault().CustomerID,
                    LoginTime   = DateTime.Now,
                    Successfull = correctPassword,
                };

                var content = new StringContent(JsonConvert.SerializeObject(loginAttempt), Encoding.UTF8, "application/json");
                await NwbaApi.InitializeClient().PostAsync("api/loginattempts", content);

                //If the login details are correct. log the user in.
                if (correctPassword)
                {
                    // Logs in customer.
                    controller.Response.Cookies.Append("LoggedIn", "", new CookieOptions()
                    {
                        Expires = DateTime.MaxValue
                    });
                    controller.HttpContext.Session.SetInt32("LoggedIn", 1);
                    controller.HttpContext.Session.SetInt32(nameof(CustomerID), CustomerID);
                    controller.HttpContext.Session.SetString(nameof(Customer.Name), Customer.Name);


                    //If the user was previously temporary locked, set to open.
                    if (Status == LoginStatus.TEMP_LOCKED)
                    {
                        Status = LoginStatus.OPEN;
                    }

                    successfull = true;
                }
                else
                {
                    controller.ModelState.AddModelError("Login", "Login Failed");
                }
            }

            return(successfull);
        }
예제 #17
0
        public IActionResult Edit(Customer customer)
        {
            var id = customer.CustomerID;
            if (id != customer.CustomerID)
                return NotFound();

            if (ModelState.IsValid)
            {
                CustomerViewModel cust = new CustomerViewModel();
                cust.CustomerID = customer.CustomerID;
                cust.Tfn = customer.Tfn;
                cust.Name = customer.Name;
                cust.AddressID = customer.AddressID;

                Address adder = new Address();
                adder.AddressID = customer.AddressID;
                adder.Street = customer.Street;
                adder.City = customer.City;
                adder.State = customer.State;
                adder.PostCode = customer.PostCode;
                adder.Phone = customer.Phone;

                cust.Address = adder;
                cust.Account = null;

                var content = new StringContent(JsonConvert.SerializeObject(cust), Encoding.UTF8, "application/json");

                try
                {
                    var response = NwbaApi.InitializeClient().PutAsync($"api/customers/{id}", content).Result;

                    if (response.IsSuccessStatusCode)
                    {
                        TempData["alertMessage"] = "Successfully modified";
                        return RedirectToAction("Index");
                    }

                }
                catch (Exception e)
                {
                    var error = e.Message;
                    TempData["alertMessage"] = "Not Updated";
                    return RedirectToAction("Index");
                }
            }

            return View(customer);
        }
예제 #18
0
        public async Task <IActionResult> Edit(int id, BillPayViewModel billPayViewModel)
        {
            if (id != billPayViewModel.BillPay.BillPayID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                billPayViewModel.BillPay.ModifyDate = DateTime.UtcNow;
                var content  = new StringContent(JsonConvert.SerializeObject(billPayViewModel.BillPay), Encoding.UTF8, "application/json");
                var response = await NwbaApi.InitializeClient().PutAsync("api/billpays", content);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(billPayViewModel));
        }
예제 #19
0
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            var response = await NwbaApi.InitializeClient().GetAsync("api/billpays/" + id);

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

            var result  = response.Content.ReadAsStringAsync().Result;
            var billPay = JsonConvert.DeserializeObject <BillPayDto>(result);

            return(View(new BillPayViewModel(billPay)));
        }
예제 #20
0
        // GET: Transaction/Index
        public async Task <IActionResult> Index()
        {
            var tranResult = await NwbaApi.InitializeClient().GetAsync("api/transactions");

            var resultTransactions = tranResult.Content.ReadAsStringAsync().Result;
            var transactions       = JsonConvert.DeserializeObject <List <Transaction> >(resultTransactions);
            //
            var custResult = await NwbaApi.InitializeClient().GetAsync("api/customers");

            var resultCustomer = custResult.Content.ReadAsStringAsync().Result;
            var customers      = JsonConvert.DeserializeObject <List <Customer> >(resultCustomer);

            TransactionViewModel tvm = new TransactionViewModel();

            tvm.Transactions = transactions;
            tvm.FromDate     = DateTime.MinValue;
            tvm.ToDate       = DateTime.MaxValue;



            List <SelectListItem> customerList = new List <SelectListItem>();

            customerList.Add(new SelectListItem()
            {
                Text  = "All Transactions",
                Value = "All Transactions"
            });

            foreach (var customer in customers)
            {
                customerList.Add(new SelectListItem()
                {
                    Text  = customer.CustomerID.ToString() + " - " + customer.Name,
                    Value = customer.CustomerID.ToString()
                });
            }

            tvm.CustomerList = customerList;



            return(View(tvm));
        }
예제 #21
0
        private async Task ProcessBillPay(BillPay billPay)
        {
            var response = await NwbaApi.InitializeClient().GetAsync("api/accounts/");

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

            // Storing the response details recieved from web api.
            var result = response.Content.ReadAsStringAsync().Result;

            var accounts = JsonConvert.DeserializeObject <List <Account> >(result);


            Account        account            = accounts.Where(x => x.AccountNumber == billPay.AccountNumber).FirstOrDefault();
            Account        destinationAccount = accounts.Where(x => x.AccountNumber == billPay.PayeeID).FirstOrDefault();
            TransactionDto transaction        = new TransactionDto()
            {
                Type                     = TransactionType.Transfer,
                AccountNumber            = billPay.AccountNumber,
                DestinationAccountNumber = billPay.PayeeID,
                Amount                   = (decimal)billPay.Amount,
                Comment                  = "Scheduled Transfer",
                TransactionTime          = billPay.ScheduleDate,
            };

            if (transaction.Type == TransactionType.Transfer)
            {
                await account.AddTransaction(transaction);

                await destinationAccount.AddTransaction(transaction);
            }
            else
            {
                await account.AddTransaction(transaction);
            }

            if (billPay.Period == Period.Single)
            {
                billPay.Status = Status.PAYED;
            }
            else
            {
                switch (billPay.Period)
                {
                case Period.Monthly:
                    billPay.ScheduleDate.AddMonths(1);
                    break;

                case Period.Quarterly:
                    billPay.ScheduleDate.AddMonths(3);
                    break;

                case Period.Yearly:
                    billPay.ScheduleDate.AddMonths(12);
                    break;
                }
            }

            using (var scope = _serviceScopeFactory.CreateScope())
            {
                var db = scope.ServiceProvider.GetService <NwbaContext>();

                BillPay bp = db.BillPay.Where(x => x.BillPayID == billPay.BillPayID).FirstOrDefault();
                bp.ScheduleDate = billPay.ScheduleDate;
                bp.Status       = billPay.Status;

                db.Transactions.Add(transaction);

                Account ac1 = db.Accounts.Find(account.AccountNumber);
                ac1.Balance = account.Balance;

                Account ac2 = db.Accounts.Find(destinationAccount.AccountNumber);
                ac2.Balance = destinationAccount.Balance;

                await db.SaveChangesAsync();
            }
        }
예제 #22
0
        protected async Task BackgroundProcessing(CancellationToken stoppingToken)
        {
            List <BillPay> bills = new List <BillPay>();

            while (true)
            {
                bills.Clear();

                var response = await NwbaApi.InitializeClient().GetAsync("api/billpays/");

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

                // Storing the response details recieved from web api.
                var result = response.Content.ReadAsStringAsync().Result;

                var billPays = JsonConvert.DeserializeObject <List <BillPay> >(result);

                foreach (BillPay billPay in billPays)
                {
                    if (billPay.Status == Status.SCHEDULED)
                    {
                        bills.Add(billPay);
                    }
                }

                //loops through
                for (int i = bills.Count - 1; i >= 0; i--)
                {
                    BillPay billPay = bills[i];

                    //Switch based on the period
                    switch (billPay.Period)
                    {
                    case Period.Single:
                        //SINGLE PAYMENT
                        if (billPay.ScheduleDate.Date <= DateTime.Now.Date && billPay.ScheduleDate.TimeOfDay.TotalSeconds <= DateTime.Now.TimeOfDay.TotalSeconds)
                        {
                            await ProcessBillPay(billPay);
                        }
                        break;

                    case Period.Monthly:
                        //MONTHLY PAYMENT
                        if (billPay.ScheduleDate.Date <= DateTime.Now.Date && billPay.ScheduleDate.TimeOfDay.TotalSeconds <= DateTime.Now.TimeOfDay.TotalSeconds)
                        {
                            await ProcessBillPay(billPay);
                        }
                        break;

                    case Period.Quarterly:
                        //QUARTERLY PAYMENT
                        if (billPay.ScheduleDate.Date <= DateTime.Now.Date && billPay.ScheduleDate.TimeOfDay.TotalSeconds <= DateTime.Now.TimeOfDay.TotalSeconds)
                        {
                            await ProcessBillPay(billPay);
                        }
                        break;

                    case Period.Yearly:
                        //YEARLY PAYMENT
                        if (billPay.ScheduleDate.Date <= DateTime.Now.Date && billPay.ScheduleDate.TimeOfDay.TotalSeconds <= DateTime.Now.TimeOfDay.TotalSeconds)
                        {
                            await ProcessBillPay(billPay);
                        }
                        break;

                    default:
                        break;
                    }
                }

                //Tick rate -> 1 seconds
                Thread.Sleep(1000);
            }
        }