コード例 #1
0
        /// <summary>
        /// Loads current lunches.
        /// </summary>
        private async Task Initialize()
        {
            var lunches = await App.Api.GetAsync <IEnumerable <Lunch> >("Lunch");

            if (null != lunches && lunches.Any())
            {
                await DispatchHelper.RunAsync(() =>
                {
                    NoLunchesStringVisibility = Visibility.Collapsed;
                    lunches.ForEach(x => Lunches.Add(x));
                });
            }
        }
コード例 #2
0
        /// <summary>
        /// Adds new anonymous attendee to the related lunch object
        /// </summary>
        /// <returns>The lunch.</returns>
        /// <param name="lunchGuid">Lunch GUID.</param>
        async Task JoinLunch(object lunchGuid)
        {
            if (IsBusy)
            {
                return;
            }

            isBusy = true;

            // Update the related lunch object
            var guid  = (string)lunchGuid;
            var lunch = Lunches.Where(l => l.Id == guid).First();
            var index = Lunches.IndexOf(lunch);

            lunch.NumberOfAttendees += 1;
            Lunches[index]           = lunch;

            // Trigger sync
            // .. not yet implemented

            isBusy = false;
        }
コード例 #3
0
        /// <summary>
        /// Retrieves all available lunches from the datasource
        /// </summary>
        /// <returns>Retrieves all available lunches</returns>
        async Task GetLunches()
        {
            if (IsBusy)
            {
                return;
            }

            Exception error = null;

            try
            {
                IsBusy = true;
                Lunches.Clear();

#pragma warning disable RECS0110
                var lunches = useServerDatasource ? await DependencyService.Get <AzureService>().GetLunches() : MockHelper.MockLunches();

#pragma warning restore RECS0110

                foreach (var lunch in MockHelper.MockLunches())
                {
                    Lunches.Add(lunch);
                }
            }
            catch (Exception e)
            {
                error = e;
            }
            finally
            {
                isBusy = false;
            }

            if (error != null)
            {
                await Application.Current.MainPage.DisplayAlert("Error!", error.Message, "OK");
            }
        }