Esempio n. 1
0
 public bool AddUserCollection(UserCollectionList newList)
 {
     try
     {
         long rowNum = mDB.InsertOrThrow(UserCollectionList.TABLE_NAME, null, newList.GetContentValues());
         if (rowNum > 0)
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch (SQLException ex)
     {
         Toast.MakeText(Application.Context, ex.Message, ToastLength.Long).Show();
         return(false);
     }
 }
Esempio n. 2
0
        private void RegisterOnClick(object s, EventArgs e)
        {
            TextView userNameText    = FindViewById <TextView>(Resource.Id.usernameRegisterText);
            TextView passwordText    = FindViewById <TextView>(Resource.Id.passwordRegisterText);
            TextView displayNameText = FindViewById <TextView>(Resource.Id.displayNameRegisterText);
            TextView emailText       = FindViewById <TextView>(Resource.Id.emailRegisterText);

            DateTime timeStamp = DateTime.Now;

            if (userNameText.Text.Trim().Length != 0 &&
                passwordText.Text.Trim().Length != 0 &&
                displayNameText.Text.Trim().Length != 0 &&
                emailText.Text.Trim().Length != 0)
            {
                User newUser = new User
                {
                    Username    = userNameText.Text,
                    Password    = passwordText.Text,
                    DisplayName = displayNameText.Text,
                    Email       = emailText.Text
                };
                long userID = DBHandler.Instance.AddUser(newUser);

                userNameText.Text    = "";
                passwordText.Text    = "";
                displayNameText.Text = "";
                emailText.Text       = "";

                if (userID != -1)
                {
                    Collection newCollection = new Collection
                    {
                        Name      = "Default List",
                        CreatorID = userID
                    };
                    long collectionID = DBHandler.Instance.AddCollection(newCollection);

                    if (collectionID != -1)
                    {
                        UserCollectionList newList = new UserCollectionList
                        {
                            UserID       = userID,
                            CollectionID = collectionID
                        };

                        bool result = DBHandler.Instance.AddUserCollection(newList);

                        if (result)
                        {
                            Toast.MakeText(this, "User registered!", ToastLength.Long).Show();
                        }
                        else
                        {
                            Toast.MakeText(this, "Unable to link user to collection!", ToastLength.Long).Show();
                        }
                    }
                    else
                    {
                        Toast.MakeText(this, "Unable to add collection!", ToastLength.Long).Show();
                    }
                }
                else
                {
                    Toast.MakeText(this, "User already exists!", ToastLength.Long).Show();
                }
            }
            else
            {
                Toast.MakeText(this, "Missing fields!", ToastLength.Long).Show();
            }
        }