public int Add(Account account) //insert account obj into datbase
        {
            _context.Accounts.Add(account);
            _context.SaveChanges();

            return(account.CustomerID);
        }
        public int Add(Payee payee) //insert Payee obj into datbase
        {
            _context.Payees.Add(payee);
            _context.SaveChanges();

            return(payee.PayeeID);
        }
예제 #3
0
        public int Add(BillPay bill) //insert billpay obj into datbase
        {
            _context.BillPays.Add(bill);
            _context.SaveChanges();

            return(bill.BillPayID);
        }
예제 #4
0
        public int Add(Customer customer) //insert customer obj into datbase
        {
            _context.Customers.Add(customer);
            _context.SaveChanges();

            return(customer.CustomerID);
        }
        public int Add(Transaction transaction) //insert transaction obj into datbase
        {
            _context.Transactions.Add(transaction);
            _context.SaveChanges();

            return(transaction.TransactionID);
        }
        public int Add(Login login) //insert login obj into datbase
        {
            _context.Logins.Add(login);
            _context.SaveChanges();

            return(Convert.ToInt32(login.LoginID));
        }
예제 #7
0
        public async Task <bool> InsertPayment(int?id, int PayeeID, decimal Amount, DateTime ScheduleDate, Period Period)
        {
            Account account = await _context.Accounts.FindAsync(id);

            if (account.Balance < Amount)
            {
                controller.ModelState.AddModelError(nameof(Amount), "Your account balance is not enough.");
            }

            if (!await CheckNull(id))
            {//check if the customer own this account
                controller.ModelState.AddModelError("AccountNotExsit", "Account not exsit in your name.");
            }


            if (CountDecimalPlaces(Amount) > 2)
            {
                controller.ModelState.AddModelError(nameof(Amount), "Amount cannot have more than 2 decimal places.");
            }
            if (Amount <= 0)
            {
                controller.ModelState.AddModelError(nameof(Amount), "Amount must be positive.");
            }


            if (!(CheckPayee(PayeeID)))
            {//check if the customer own this account
                controller.ModelState.AddModelError("AccountNotExsit", "Payee not exsit");
            }

            if (ScheduleDate < DateTime.Today)
            {
                controller.ModelState.AddModelError("ScheduleDate", "Schedule Date cannot be ealier than today");
            }

            if (!controller.ModelState.IsValid)
            {
                return(false);
            }

            BillPay billPay = new BillPay
            {
                AccountNumber = (int)id,
                PayeeID       = PayeeID,
                Amount        = Amount,
                ModifyDate    = DateTime.UtcNow, //default modfied today
                ScheduleDate  = ScheduleDate.ToUniversalTime(),
                Period        = Period
            };

            _context.BillPays.Add(billPay);
            _context.SaveChanges();

            return(true);
        }