Exemple #1
0
        public async Task Load()
        {
            try
            {
                IsBusy = true;
                switch (SettingsService.Instance.ApplicationMode)
                {
                case ApplicationModeEnum.Portal:

                    if (!Settings.IsImpersonatingCustomer && Settings.IsPortalSuperUser)
                    {
                        MenuItems = GetPortalSuperUserMenuList();
                    }
                    else
                    {
                        MenuItems = GetPortalMenuList();

                        //If a user has an overdue invoice we redirect to the invoice payment page.
                        if (!_hasCheckedOverdueInvoices)
                        {
                            var overdueInvoices = await GetOverdueInvoices();

                            _hasCheckedOverdueInvoices = true;
                            if (overdueInvoices?.Data?.Any() ?? false)
                            {
                                await Alert.ShowMessage(nameof(AppResources.OverdueInvoicesMessage)
                                                        .Translate());

                                var invoicePaymentPage = new MenuItemModel
                                {
                                    Id         = 9999,
                                    TargetType = typeof(InvoicePaymentPage),
                                    Tag        = overdueInvoices.Data
                                                 .Select(p => p.CloneToType <InvoiceModel, Invoice>())
                                                 .ToList()
                                };

                                await OnItemSelected(invoicePaymentPage);
                            }
                        }
                        await RefreshNotificationBalloons();
                    }

                    break;

                case ApplicationModeEnum.Driver:
                    MenuItems = GetDriverMenuList();
                    break;

                case ApplicationModeEnum.Pipeline:
                    if (Settings.IsImpersonatingCustomer)
                    {
                        if (SettingsService.Instance.IsImpersonatingCustomer)
                        {
                            MenuItems = GetPortalMenuList();
                        }
                        else
                        {
                            MenuItems = GetPipelineSuperUserMenuList();
                        }
                        await RefreshNotificationBalloons();
                    }
                    else
                    {
                        MenuItems = GetPipelineMenuList();
                    }

                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            catch (Exception e)
            {
#if DEBUG
                await Alert.DisplayError(e);
#endif
            }
            finally
            {
                IsBusy = false;
            }
        }
Exemple #2
0
        private async Task OnItemSelected(MenuItemModel item)
        {
            if (item == null)
            {
                return;
            }
            if (item.IsSeparator)
            {
                SelectedItem = null;
                return;
            }
            if (item.IsWebLink)
            {
                await Launcher.OpenAsync(new Uri(item.Link));

                SelectedItem = null;
                MessengerInstance.Send(new MenuItemSelectedMessage());
                return;
            }
            //Logout
            if (item.TargetType == typeof(LoginPage))
            {
                App.Current.MainPage = new NavigationPage(new LoginPage());
                return;
            }
            if (item.Id == 16)//When in pipeline or portal super user mode return
            {
                try
                {
                    if (IsBusy)
                    {
                        return;
                    }
                    IsBusy = true;
                    var settings = SettingsService.Instance;
                    settings.AxCustomerId            = settings.MasterAxCustomerId;
                    settings.Token                   = settings.MasterToken;
                    settings.TokenExpiration         = settings.MasterTokenExpiration;
                    settings.IsImpersonatingCustomer = false;
                    var infoResult = await ApiService.Instance.GetMyInfo(Api.GetCustomerContext());

                    if (infoResult.Data == null)
                    {
                        await Alert.ShowMessage(Translate.Get(nameof(AppResources.CouldNotReceiveInformationFromServer)));

                        return;
                    }
                    Settings.MyPreferences = infoResult.Data.AppPreferences;
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        Page mainPage = null;
                        Messenger.Reset();
                        mainPage             = new NavigationPage(new MasterDetailPage1(MainPageMode.OpenInPipelineAccounts));
                        App.Current.MainPage = mainPage;
                    }
                                                   );
                    return;
                }
                catch (Exception e)
                {
                    await Alert.DisplayError(e);
                }
                finally
                {
                    IsBusy = false;
                }
            }

            if (item.Id == 116)//When in pipeline or portal super user mode return
            {
                try
                {
                    if (IsBusy)
                    {
                        return;
                    }
                    IsBusy = true;
                    var settings = SettingsService.Instance;
                    settings.AxCustomerId            = settings.MasterAxCustomerId;
                    settings.Token                   = settings.MasterToken;
                    settings.TokenExpiration         = settings.MasterTokenExpiration;
                    settings.IsImpersonatingCustomer = false;
                    var infoResult = await ApiService.Instance.GetMyInfo(Api.GetCustomerContext());

                    if (infoResult.Data == null)
                    {
                        await Alert.ShowMessage(Translate.Get(nameof(AppResources.CouldNotReceiveInformationFromServer)));

                        return;
                    }
                    Settings.MyPreferences = infoResult.Data.AppPreferences;
                    Device.BeginInvokeOnMainThread(() =>
                    {
                        Page mainPage = null;
                        Messenger.Reset();
                        mainPage             = new NavigationPage(new MasterDetailPage1(MainPageMode.PortalSuperUser));
                        App.Current.MainPage = mainPage;
                    }
                                                   );
                    return;
                }
                catch (Exception e)
                {
                    await Alert.DisplayError(e);
                }
                finally
                {
                    IsBusy = false;
                }
            }
            Page page;

            if (item.Id == 3 || item.Id == 30)
            {
                page = new InvoicesPage
                {
                    InvoicePageDefaultMode = (InvoicePageDefaultMode)item.Tag
                };
                page.Title = $"Invoices - {item.Title}";
            }
            else if (item.Id == 9999)
            {
                page = new InvoicePaymentPage(item.Tag as List <InvoiceModel>, PaymentRequest.FullPayment);
            }
            else
            {
                page       = (Page)Activator.CreateInstance(item.TargetType);
                page.Title = item.Title;
            }

            MessengerInstance.Send(new MenuItemSelectedMessage
            {
                Page = new NavigationPage(page)
            });
            SelectedItem = null;
        }