Ejemplo n.º 1
0
        public List <UserModel> Finduser(string accountNumber)
        {
            databaseforassignmentEntities1 context = new databaseforassignmentEntities1();

            var query = from user in context.Users
                        where user.accountnumber == accountNumber
                        select user;

            List <UserModel> users = new List <UserModel>();

            foreach (var u in query)
            {
                users.Add(new UserModel
                {
                    status        = u.status,
                    password      = u.password,
                    name          = u.name,
                    email         = u.email,
                    city          = u.city,
                    accountnumber = u.accountnumber,
                    balance       = u.balance
                });
            }

            return(users);
        }
Ejemplo n.º 2
0
        public bool TransferMoney(int amountOfBitCoins, string receiverAccountNumber, string senderAccountNumber)
        {
            databaseforassignmentEntities1 context = new databaseforassignmentEntities1();

            var resultSender   = context.Users.SingleOrDefault(a => a.accountnumber == senderAccountNumber);
            var resultReceiver = context.Users.SingleOrDefault(a => a.accountnumber == receiverAccountNumber);

            if (resultSender == null || resultReceiver == null)
            {
                return(false);
            }

            if ((resultSender.balance - amountOfBitCoins) <= 0)
            {
                return(false);
            }

            resultSender.balance   = resultSender.balance - amountOfBitCoins;
            resultReceiver.balance = resultReceiver.balance + amountOfBitCoins;

            context.transactions.Add(new transaction
            {
                transactiontype = "transfer",
                date            = DateTime.Now,
                sender          = senderAccountNumber,
                receiver        = receiverAccountNumber,
                amount          = amountOfBitCoins
            });

            context.SaveChanges();
            return(true);
        }
Ejemplo n.º 3
0
        public void DeleteUser(string userAccountnumber)
        {
            databaseforassignmentEntities1 context = new databaseforassignmentEntities1();

            var user = context.Users.SingleOrDefault(a => a.accountnumber == userAccountnumber);

            user.status = "inactive";

            context.SaveChanges();
        }
        public bool ValidateLogin(string email, string password)
        {
            databaseforassignmentEntities1 context = new databaseforassignmentEntities1();

            var query = from user in context.Users
                         where user.email == email && user.password.ToString() == password && user.status == "active"
                         select user;

            List<User> users = new List<User>();
            foreach (var u in query)
            {
                users.Add(u);
            }

            return (users.Count > 0) ? true : false;
        }
Ejemplo n.º 5
0
        public List <string> AllUsers()
        {
            databaseforassignmentEntities1 context = new databaseforassignmentEntities1();

            var query = from user in context.Users
                        where user.status == "active"
                        select user;

            List <string> accountNumbers = new List <string>();

            foreach (var u in query)
            {
                accountNumbers.Add(u.accountnumber);
            }

            return(accountNumbers);
        }
Ejemplo n.º 6
0
        public bool ValidateLogin(string email, string password)
        {
            databaseforassignmentEntities1 context = new databaseforassignmentEntities1();

            var query = from user in context.Users
                        where user.email == email && user.password.ToString() == password && user.status == "active"
                        select user;

            List <User> users = new List <User>();

            foreach (var u in query)
            {
                users.Add(u);
            }

            return((users.Count > 0) ? true : false);
        }
        public UserModel GetUserByLogin(string email, string password)
        {
            databaseforassignmentEntities1 context = new databaseforassignmentEntities1();
            var query = from user in context.Users
                        where user.email == email && user.password.ToString() == password && user.status == "active"
                        select user;

            UserModel loginUser = new UserModel();
            foreach (var u in query)
            {
                loginUser.accountnumber = u.accountnumber;
                loginUser.balance = u.balance;
                loginUser.city = u.city;
                loginUser.email = u.email;
                loginUser.name = u.name;
                loginUser.password = u.password;
            }

            return loginUser;
        }
        public void RegisterUser(UserModel user)
        {
            databaseforassignmentEntities1 context = new databaseforassignmentEntities1();
            User DBuser = new User();

            if (context.Users.SingleOrDefault(u => u.email == user.email) == null)
            {
                DBuser.accountnumber = user.accountnumber;
                DBuser.balance = 0;
                DBuser.city = user.city;
                DBuser.email = user.email;
                DBuser.name = user.name;
                DBuser.password = user.password;
                DBuser.status = "active";

                context.Users.Add(DBuser);

                context.SaveChanges();
            }
        }
Ejemplo n.º 9
0
        public void RegisterUser(UserModel user)
        {
            databaseforassignmentEntities1 context = new databaseforassignmentEntities1();
            User DBuser = new User();

            if (context.Users.SingleOrDefault(u => u.email == user.email) == null)
            {
                DBuser.accountnumber = user.accountnumber;
                DBuser.balance       = 0;
                DBuser.city          = user.city;
                DBuser.email         = user.email;
                DBuser.name          = user.name;
                DBuser.password      = user.password;
                DBuser.status        = "active";

                context.Users.Add(DBuser);

                context.SaveChanges();
            }
        }
Ejemplo n.º 10
0
        public UserModel GetUserByLogin(string email, string password)
        {
            databaseforassignmentEntities1 context = new databaseforassignmentEntities1();
            var query = from user in context.Users
                        where user.email == email && user.password.ToString() == password && user.status == "active"
                        select user;

            UserModel loginUser = new UserModel();

            foreach (var u in query)
            {
                loginUser.accountnumber = u.accountnumber;
                loginUser.balance       = u.balance;
                loginUser.city          = u.city;
                loginUser.email         = u.email;
                loginUser.name          = u.name;
                loginUser.password      = u.password;
            }

            return(loginUser);
        }
Ejemplo n.º 11
0
        public void MakeDepositWIthdrawal(string accountNumber, double amount, bool deposit)
        {
            databaseforassignmentEntities1 context = new databaseforassignmentEntities1();

            var user = context.Users.SingleOrDefault(u => u.accountnumber == accountNumber);

            if (deposit)
            {
                user.balance += amount;

                context.transactions.Add(new transaction
                {
                    transactiontype = "deposit",
                    date            = DateTime.Now,
                    sender          = accountNumber,
                    receiver        = accountNumber,
                    amount          = amount
                });

                context.SaveChanges();
            }
            else
            {
                if (user.balance - amount >= 0)
                {
                    user.balance -= amount;
                }

                context.transactions.Add(new transaction
                {
                    transactiontype = "withdrawing",
                    date            = DateTime.Now,
                    sender          = accountNumber,
                    receiver        = accountNumber,
                    amount          = amount
                });

                context.SaveChanges();
            }
        }
Ejemplo n.º 12
0
        public List <TransactionModel> TransactionsPerReceiver(string receiver)
        {
            databaseforassignmentEntities1 context = new databaseforassignmentEntities1();

            var query = from transaction in context.transactions
                        where transaction.receiver == receiver && transaction.transactiontype == "transfer"
                        select transaction;

            List <TransactionModel> transactions = new List <TransactionModel>();

            foreach (var t in query)
            {
                transactions.Add(new TransactionModel
                {
                    transactiontype = t.transactiontype,
                    date            = t.date.ToString(),
                    sender          = t.sender,
                    receiver        = t.receiver,
                    amount          = Convert.ToDouble(t.amount)
                });
            }

            return(transactions);
        }
        public bool TransferMoney(int amountOfBitCoins, string receiverAccountNumber, string senderAccountNumber)
        {
            databaseforassignmentEntities1 context = new databaseforassignmentEntities1();

            var resultSender = context.Users.SingleOrDefault(a => a.accountnumber == senderAccountNumber);
            var resultReceiver = context.Users.SingleOrDefault(a => a.accountnumber == receiverAccountNumber);

            if (resultSender == null || resultReceiver == null) return false;

            if ((resultSender.balance - amountOfBitCoins) <= 0) return false;

            resultSender.balance = resultSender.balance - amountOfBitCoins;
            resultReceiver.balance = resultReceiver.balance + amountOfBitCoins;

            context.transactions.Add(new transaction
            {
                transactiontype = "transfer",
                date = DateTime.Now,
                sender = senderAccountNumber,
                receiver = receiverAccountNumber,
                amount = amountOfBitCoins
            });

            context.SaveChanges();
            return true;
        }
        public List<TransactionModel> TransactionsPerReceiver(string receiver)
        {
            databaseforassignmentEntities1 context = new databaseforassignmentEntities1();

            var query = from transaction in context.transactions
                        where transaction.receiver == receiver && transaction.transactiontype == "transfer"
                        select transaction;

            List<TransactionModel> transactions = new List<TransactionModel>();

            foreach (var t in query)
            {
                transactions.Add(new TransactionModel
                {
                    transactiontype = t.transactiontype,
                    date = t.date.ToString(),
                    sender = t.sender,
                    receiver = t.receiver,
                    amount = Convert.ToDouble(t.amount)
                });
            }

            return transactions;
        }
        public List<UserModel> Finduser(string accountNumber)
        {
            databaseforassignmentEntities1 context = new databaseforassignmentEntities1();

            var query = from user in context.Users
                        where user.accountnumber == accountNumber
                        select user;

            List<UserModel> users = new List<UserModel>();

            foreach (var u in query)
            {
                users.Add(new UserModel
                {
                    status = u.status,
                    password = u.password,
                    name = u.name,
                    email = u.email,
                    city = u.city,
                    accountnumber = u.accountnumber,
                    balance = u.balance
                });
            }

            return users;
        }
        public void DeleteUser(string userAccountnumber)
        {
            databaseforassignmentEntities1 context = new databaseforassignmentEntities1();

            var user = context.Users.SingleOrDefault(a => a.accountnumber == userAccountnumber);

            user.status = "inactive";

            context.SaveChanges();
        }
        public void MakeDepositWIthdrawal(string accountNumber, double amount, bool deposit) {
            databaseforassignmentEntities1 context = new databaseforassignmentEntities1();

            var user = context.Users.SingleOrDefault(u => u.accountnumber == accountNumber);

            if (deposit)
            {
                user.balance += amount;

                context.transactions.Add(new transaction
                {
                    transactiontype = "deposit",
                    date = DateTime.Now,
                    sender = accountNumber,
                    receiver = accountNumber,
                    amount = amount
                });

                context.SaveChanges();
            }
            else
            {
                if (user.balance - amount >= 0)
                    user.balance -= amount;

                context.transactions.Add(new transaction
                {
                    transactiontype = "withdrawing",
                    date = DateTime.Now,
                    sender = accountNumber,
                    receiver = accountNumber,
                    amount = amount
                });

                context.SaveChanges();
            }
        }
        public List<string> AllUsers()
        {
            databaseforassignmentEntities1 context = new databaseforassignmentEntities1();

            var query = from user in context.Users
                        where user.status == "active"
                        select user;

            List<string> accountNumbers = new List<string>();
            foreach (var u in query)
            {
                accountNumbers.Add(u.accountnumber);
            }

            return accountNumbers;
        }