示例#1
0
        public bool CreateNewAccount(string username, string firstname, string lastname, string password, string role)
        {
            //search for an existing user with the same username
            var accQuery = from u in DataContextInv.AccountsTables
                           where u.Username.Equals(username)
                           select u;

            if (accQuery.Count() == 0)  //if the query returns more than 0 , the username is taken
            {
                //create a new Accounts table instance and fill it with the passed values
                AccountsTable newuser = new AccountsTable();
                newuser.Username  = username;
                newuser.FirstName = firstname;
                newuser.LastName  = lastname;
                newuser.Password  = password;
                newuser.Role      = role;
                DataContextInv.AccountsTables.InsertOnSubmit(newuser);
                DataContextInv.SubmitChanges();
                string message = "Created a new account for the user " + username;
                AddLogEntry(username, message);
                return(true);
            }
            else //the username was taken so return false
            {
                return(false);
            }
        }
 partial void UpdateAccountsTable(AccountsTable instance);
 partial void DeleteAccountsTable(AccountsTable instance);
 partial void InsertAccountsTable(AccountsTable instance);