private async void Submit_Click(object sender, RoutedEventArgs e)
        {
            double amount = 0;

            if (string.IsNullOrEmpty(NameInput.Text) ||
                string.IsNullOrEmpty(Number.Text) ||
                !double.TryParse(Number.Text, out amount))
            {
                MessageDialog dialog = new MessageDialog("You need to fill in all fields.");
                await dialog.ShowAsync();

                return;
            }

            Food food = new Food
            {
                AccountId   = UserState.CurrentId,
                Amount      = amount,
                Date        = DateTime.UtcNow,
                FoodName    = NameInput.Text,
                Measurement = (Measurement)Enum.Parse(typeof(Measurement), (string)((ComboBoxItem)Units.SelectedValue).Tag)
            };
            await Api.Do.PostFood(food);

            PageDispatch.GoHome(Frame);
        }
        private async void DoneButton_Click(object sender, RoutedEventArgs e)
        {
            if (new[] { Name.Text, PreferredName.Text, HeightFeet.Text, HeightInches.Text,
                        Weight.Text, Zip.Text }.Any(string.IsNullOrEmpty))
            {
                MessageDialog dialog = new MessageDialog("You need to fill in all fields.");
                await dialog.ShowAsync();

                return;
            }

            bool?sex = null;

            if (Sex.SelectionBoxItem == null)
            {
            }
            else if ((string)Sex.SelectionBoxItem == "Female")
            {
                sex = true;
            }
            else if ((string)Sex.SelectionBoxItem == "Male")
            {
                sex = false;
            }

            var account = new Account()
            {
                Id            = "",
                FullName      = Name.Text,
                PreferredName = PreferredName.Text,
                UserName      = new string(Name.Text.Where(c => char.IsDigit(c) || char.IsLetter(c)).ToArray()),
                Height        = int.Parse(HeightFeet.Text) * 12 + int.Parse(HeightInches.Text),
                Weight        = UserState.UseOldUnits ? (int.Parse(Weight.Text) * 14) : int.Parse(Weight.Text),
                Sex           = sex,
                Birthdate     = Birthdate.Date.DateTime,
                Zip           = int.Parse(Zip.Text)
            };

            if (info.Authenticator == Authenticator.Twitter)
            {
                account.TwitterId = info.SocialId;
            }
            else
            {
                account.FacebookId = info.SocialId;
            }

            account = await Api.Do.CreateAccount(account);

            UserState.ActiveAccount = account;
            PageDispatch.GoHome(Frame);
        }
Beispiel #3
0
 private void ChangeUnits_Click(object sender, RoutedEventArgs e)
 {
     UserState.UseOldUnits = !UserState.UseOldUnits;
     if (UserState.UseOldUnits)
     {
         ChangeUnits.Label = "Use modern english units";
     }
     else
     {
         ChangeUnits.Label = "Use ye old units";
     }
     PageDispatch.GoHome(Frame);
 }
        private async void SubmitButtonTapped(object sender, TappedRoutedEventArgs e)
        {
            var item = ((TextBlock)MoodOptions.SelectionBoxItem).Text;

            var mood = moods.First(m => m.Description == item);

            await Api.Do.CreateStatus(new Status
            {
                MoodId    = mood.Id,
                Date      = DateTime.UtcNow,
                AccountId = UserState.CurrentId
            });

            PageDispatch.GoHome(Frame);
        }
        private async void AppBarButton_Click_Leave(object sender, RoutedEventArgs e)
        {
            var membership = (UserState.ActiveAccount.Memberships.Where(m => m.TeamId == teamId)).FirstOrDefault();

            if (membership != null &&
                membership.Status == MembershipStatus.Admin &&
                (await Api.Do.GetTeam(teamId)).Memberships.Where(m => m.Status == MembershipStatus.Member || m.Status == MembershipStatus.Admin ||
                                                                 m.Status == MembershipStatus.Invited).Count() > 1)
            {
                await new MessageDialog("You can't leave the group until you make someone else admin.").ShowAsync();
                return;
            }

            Api.Do.LeaveTeam(UserState.CurrentId, teamId);
            JoinButton.Visibility  = Windows.UI.Xaml.Visibility.Visible;
            LeaveButton.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
            PageDispatch.GoHome(Frame);
        }
        private async void Submit(object sender, TappedRoutedEventArgs e)
        {
            int number;

            if (MeasureBox.SelectedValue == null ||
                TimelineBox.SelectedValue == null ||
                TypeBox.SelectedValue == null ||
                !int.TryParse(NumberBox.Text, out number) ||
                number <= 0)
            {
                MessageDialog dialog = new MessageDialog("Your count must be a natural number and all fields must be filled in.");
                await dialog.ShowAsync();

                return;
            }

            Target target = new Target
            {
                TargetNumber = (UIType() == TargetType.Distance && UserState.UseOldUnits) ? number / 3.0 : number,
                ActivityType = UIActivityType(),
                Type         = UIType()
            };

            target = await Api.Do.PostTarget(target);

            Goal goal = new Goal
            {
                TargetId  = target.Id,
                AccountId = challenged != null ? challenged.Id : UserState.CurrentId,
                Timeline  = UITimeline(),
                BeginDate = DateTime.UtcNow,
                EndDate   = DateTime.UtcNow + UITimeline().Span(),
                Status    = challenged != null ? GoalStatus.Challenged : GoalStatus.Current,
            };

            await Api.Do.PostGoal(goal);

            goal.Target = target;
            PageDispatch.GoHome(Frame);
        }
Beispiel #7
0
 private void HomeTapped(object sender, RoutedEventArgs e)
 {
     PageDispatch.GoHome(Frame);
 }