Example #1
0
        public void LoginClick(object sender, EventArgs args)
        {
            EditText usernameField = FindViewById <EditText>(Resource.Id.Login_UsernameField);
            EditText passwordField = FindViewById <EditText>(Resource.Id.Login_PasswordField);

            UserAccount user = userController.LogIn(usernameField.Text, passwordField.Text);

            if (user == null)
            {
                StringMessageDialogFragment dialog = StringMessageDialogFragment.CreateInstance("Invalid username or password.");
                dialog.Show(FragmentManager, "Login Failed");
            }
            else
            {
                Intent homeIntent = new Intent(this, typeof(HomeActivity));
                homeIntent.PutExtra("UserController", JsonConvert.SerializeObject(userController, Formatting.Indented, SerializationBinderHelper.Settings));
                StartActivity(homeIntent);
                Finish();
            }
        }
        public void CreateClick(object sender, EventArgs args)
        {
            Dictionary <string, IEnumerable <string> > errors = new Dictionary <string, IEnumerable <string> > {
                { "Username errors:", UsernameChecks(userNameField.Text) },
                { "Password errors:", PasswordChecks(passwordField.Text) },
                { "Email errors:", EmailChecks(emailField.Text) },
                { "Phone number errors:", PhoneNumberChecks(phoneNumberField.Text) }
            };

            Dictionary <string, IEnumerable <string> > errorsCaught =
                errors.Where(p => p.Value.Any()).ToDictionary(p => p.Key, p => p.Value);

            if (errorsCaught.Count > 0)
            {
                string errorMessage = String.Empty;
                foreach (KeyValuePair <string, IEnumerable <string> > errorPair in errorsCaught)
                {
                    errorMessage += errorPair.Key;
                    foreach (string message in errorPair.Value)
                    {
                        errorMessage += $"\n\t\t{message}";
                    }

                    errorMessage += "\n\n";
                }

                StringMessageDialogFragment dialog = StringMessageDialogFragment.CreateInstance(errorMessage);
                dialog.Show(FragmentManager, "Invalid information");
            }
            else
            {
                UserAccount user = userController.CreateAccount(userNameField.Text, passwordField.Text, emailField.Text, phoneNumberField.Text);
                userController.LogIn(user.UserName, passwordField.Text);
                Intent intent = new Intent(this, typeof(HomeActivity));
                intent.PutExtra("UserController", JsonConvert.SerializeObject(userController));
                StartActivity(intent);
                Finish();
            }
        }
Example #3
0
        private void Save_Click(object sender, EventArgs args)
        {
            if (!IsNameValid() || !IsDescriptionValid() || !IsFrequencyValid() || !IsDateValid())
            {
                string errorMessage = "Invalid input for one or more fields.";
                StringMessageDialogFragment dialog = StringMessageDialogFragment.CreateInstance(errorMessage);
                dialog.Show(FragmentManager, "Invalid information");
            }
            else
            {
                Goal goal;

                string   name        = taskNameField.Text;
                string   description = taskDescriptionField.Text;
                DateTime deadline    = new DateTime(deadlineDate.Year, deadlineDate.Month, deadlineDate.Day, deadlineTime.Hour, deadlineTime.Minute, deadlineTime.Second);

                if (IsRecurring)
                {
                    TimeSpan frequency;
                    switch (frequencyButton.Text)
                    {
                    case "Daily":
                        frequency = new TimeSpan(1, 0, 0, 0);
                        break;

                    case "Weekly":
                        frequency = new TimeSpan(7, 0, 0, 0);
                        break;

                    case "Monthly":
                        // I CAN'T DEAL WITH MONTHS HERE
                        frequency = new TimeSpan(30, 0, 0, 0);
                        break;

                    case "Yearly":
                        frequency = new TimeSpan(365, 0, 0, 0);
                        break;

                    default:
                        frequency = default(TimeSpan);
                        break;
                    }

                    goal = new RecurringGoal {
                        TaskName    = name,
                        Deadline    = deadline,
                        Description = description,
                        Frequency   = frequency,
                        Points      = points
                    };
                    goalController.CreateRecurringGoal(userController.CurrentUser.UserName, (RecurringGoal)goal);
                }
                else
                {
                    goal = new NonRecurringGoal {
                        TaskName    = name,
                        Deadline    = deadline,
                        Description = description,
                        Points      = points
                    };

                    goalController.CreateNonRecurringGoal(userController.CurrentUser.UserName, (NonRecurringGoal)goal);
                }

                GoBack();
            }
        }