public async override Task InitializeAsync(object navigationData)
        {
            if (navigationData is GraphEvent)
            {
                IsBusy = true;

                try
                {
                    _event = navigationData as GraphEvent;

                    if (_event == null)
                    {
                        return;
                    }

                    PickTime   = _event.StartDate;
                    ArriveTime = _event.EndDate;
                    IsPickup   = _event.BodyPreview != null && _event.BodyPreview.Contains("Pickup");

                    if (_event.BodyPreview
                        .Contains(AppSettings.CarpoolEventBody))
                    {
                        int index      = _event.BodyPreview.IndexOf(AppSettings.CarpoolEventBody);
                        var driverName = _event.BodyPreview
                                         .Substring(index)
                                         .Replace(AppSettings.CarpoolEventBody, string.Empty);
                        var result = await _dataService.GetAllDriversAsync();

                        var driver = result.FirstOrDefault(d => d.Name.Equals(driverName));
                        if (driver != null)
                        {
                            IsDriver = driver.Name.Equals(App.CurrentUser.UserPrincipalName);

                            _drivers = new ObservableCollection <GraphUser>();
                            var employees = await _dataService.GetAllEmployeesAsync();

                            var riders = new List <GraphUser>();
                            if (!string.IsNullOrEmpty(driver.Rider1) && driver.Rider1Status)
                            {
                                var rider1 = new GraphUser(await _userService.GetUserByDisplayNameAsync(driver.Rider1));
                                rider1.Merge(employees.FirstOrDefault(e => e.Name.Equals(driver.Rider1)));
                                _drivers.Add(rider1);
                            }
                            if (!string.IsNullOrEmpty(driver.Rider2) && driver.Rider2Status)
                            {
                                var rider2 = new GraphUser(await _userService.GetUserByDisplayNameAsync(driver.Rider2));
                                rider2.Merge(employees.FirstOrDefault(e => e.Name.Equals(driver.Rider2)));
                                _drivers.Add(rider2);
                            }
                            if (!string.IsNullOrEmpty(driver.Rider3) && driver.Rider3Status)
                            {
                                var rider3 = new GraphUser(await _userService.GetUserByDisplayNameAsync(driver.Rider3));
                                rider3.Merge(employees.FirstOrDefault(e => e.Name.Equals(driver.Rider3)));
                                _drivers.Add(rider3);
                            }
                            if (!string.IsNullOrEmpty(driver.Rider4) && driver.Rider4Status)
                            {
                                var rider4 = new GraphUser(await _userService.GetUserByDisplayNameAsync(driver.Rider4));
                                rider4.Merge(employees.FirstOrDefault(e => e.Name.Equals(driver.Rider4)));
                                _drivers.Add(rider4);
                            }

                            RidersList = CalculateRidePushpins();

                            // Add my position to the map

                            var graphdriverUser = new GraphUser(driver);
                            graphdriverUser.Merge(employees.FirstOrDefault(e => e.Email.Equals(driver.Name)));
                            PushpinsList = CalculateDrivePushpins(graphdriverUser);

                            _drivers.Insert(0, graphdriverUser);
                            Users = _drivers;

                            // Update user photo in background
                            var tasks = new List <Task>();
                            foreach (var user in _drivers)
                            {
                                tasks.Add(GetUserPhotoAsync(user));
                            }
                            await Task.WhenAll(tasks);
                        }
                    }
                }
                catch
                {
                    if (!IsConnected)
                    {
                        await _dialogService.ShowAlertAsync("No network connection, please check your internet.", "Service unavailable", "Ok");
                    }
                    else
                    {
                        await _dialogService.ShowAlertAsync("CDS service currently unavailable, please try again.", "Service unavailable", "Ok");
                    }
                }
                finally
                {
                    IsBusy = false;
                }
            }

            await base.InitializeAsync(navigationData);
        }
Esempio n. 2
0
 private async Task OnSelectUserAsync(GraphUser user)
 {
     // Merge CDS data with Graph data
     user.Merge(await _userService.GetUserByPrincipalNameAsync(user.UserPrincipalName));
     await NavigationService.NavigateToAsync <FindRideDetailViewModel>(user);
 }
Esempio n. 3
0
        private async Task RefreshAsync()
        {
            IsBusy = true;

            try
            {
                var employees = await _dataService.GetAllEmployeesAsync();

                var driver = (await _dataService.GetAllDriversAsync()).FirstOrDefault(d => d.Name.Equals(App.CurrentUser.UserPrincipalName));

                var riders   = DriverHelper.GetRiders(driver);
                var myRiders = new Collection <GraphUser>();

                foreach (var rider in riders)
                {
                    var graphRider = new GraphUser(await _userService.GetUserByDisplayNameAsync(rider));
                    graphRider.Merge(employees.FirstOrDefault(e => e.Name.Equals(rider)));
                    myRiders.Add(graphRider);
                    graphRider.Distance = UserHelper.CalculateDistance(App.CurrentUser, graphRider);
                }

                MyRiders = new ObservableCollection <GraphUser>(myRiders);

                var riderRequests   = DriverHelper.GetRiderRequests(driver);
                var myRiderRequests = new Collection <GraphUser>();

                foreach (var rider in riderRequests)
                {
                    var graphRider = new GraphUser(await _userService.GetUserByDisplayNameAsync(rider));
                    myRiderRequests.Add(graphRider);
                    graphRider.Merge(employees.FirstOrDefault(e => e.Name.Equals(rider)));
                    graphRider.Distance = UserHelper.CalculateDistance(App.CurrentUser, graphRider);
                }

                MyRiderRequests = new ObservableCollection <GraphUser>(myRiderRequests);

                // Add my pushpin to the map
                PushpinsList = CalculateDrivePushpins();
                RidersList   = CalculateRiderPushpins();

                IsBusy = false;

                // background photo requests
                foreach (var rider in myRiders)
                {
                    await GetUserPhotoAsync(rider);
                }
                foreach (var rider in myRiderRequests)
                {
                    await GetUserPhotoAsync(rider);
                }
            }
            catch
            {
                IsBusy = false;
                if (!IsConnected)
                {
                    await _dialogService.ShowAlertAsync("No network connection, please check your internet.", "Service unavailable", "Ok");
                }
                else
                {
                    await DialogService.ShowAlertAsync("CDS service currently unavailable, please try again", "Service unavailable", "Try again");
                }
            }
        }