Exemplo n.º 1
0
        public OrderViewModel(IOrderValidationService validator,
                              ICurrentUserService userCache,
                              IOrderService orderService,
                              IToastService toast,
                              IPageFactory pageFactory,
                              MainThreadNavigator nav,
                              IMessagingSubscriber topicSubscriber,
                              ILogger <OrderViewModel> logger,
                              string deviceType,
                              AlertUtility alertUtility,
                              Action <BaseNavPageType> baseNavigationAction,
                              ICache <Models.Order> orderCache)
        {
            _orderValidator       = validator;
            _userService          = userCache;
            _toast                = toast;
            _nav                  = nav;
            _orderService         = orderService;
            _pageFactory          = pageFactory;
            _orderCache           = orderCache;
            _alertUtility         = alertUtility;
            _topicSubscriber      = topicSubscriber;
            _baseNavigationAction = baseNavigationAction;
            _deviceType           = deviceType;
            _logger               = logger;

            PurchaseOptionsCommand = new Command(async() =>
            {
                var val = await _orderValidator.ValidateOrderRequest(_userService.GetLoggedInAccount());
                if (SubscriptionUtility.SubscriptionActive(val.Subscription))
                {
                    _nav.Push(_pageFactory.GetPage(PageType.SingleReportPurchase, val));
                }
                else
                {
                    _nav.Push(_pageFactory.GetPage(PageType.PurchaseOptions, val));
                }
            });
            OptionsInfoCommand = new Command(async() => await alertUtility.Display("Roof Option Selection",
                                                                                   $"Selecting a roof option allows Fair Squares to determine what roofs you would like measured at the submitted address.{Environment.NewLine}" +
                                                                                   $"{Environment.NewLine}Primary Only- Fair Squares will measure the primary structure, including attached garage.{Environment.NewLine}" +
                                                                                   $"Detached Garage- Fair Squares will also measure the detached garage on the property.{Environment.NewLine}" +
                                                                                   $"Shed/Barn- Fair Squares will also measure a shed or barn on the property.{Environment.NewLine}" +
                                                                                   $"{Environment.NewLine}NOTE: Fair Squares only supports measuring one primary structure per report (with a detached garage or shed/barn if needed).",
                                                                                   "Ok"));
            ErrorMessageRowHeight = 0;
            SelectedOptionIndex   = -1;
            SelectedStateIndex    = -1;
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
            SetVisualStateForValidation();
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
        }
 public BaseTabViewModel(ICache <SettingsModel> settings,
                         IPageFactory pageFactory,
                         ILogger <BaseTabViewModel> logger,
                         MainThreadNavigator nav)
 {
     _settings           = settings;
     _pageFactory        = pageFactory;
     _logger             = logger;
     _nav                = nav;
     OnAppearingBehavior = new Command(() =>
     {
         try
         {
             if (!_dialogShown && (!_settings.GetAll().Any() || _settings.Get("").DisplayWelcomeMessage))
             {
                 _dialogShown = true;
                 _nav.Push(_pageFactory.GetPage(PageType.Instruction, true));
             }
         }
         catch (Exception ex)
         {
             _logger.LogError($"Failed to check settings on load.", ex);
         }
     });
 }
 public ManageSubscriptionViewModel(ValidationModel model,
                                    string runtimePlatform,
                                    Action <Uri> openUri,
                                    MainThreadNavigator nav,
                                    ILogger <ManageSubscriptionViewModel> logger,
                                    IPageFactory pageFactory)
 {
     _model           = model;
     _runtimePlatform = runtimePlatform;
     _openUri         = openUri;
     _nav             = nav;
     _logger          = logger;
     _pageFactory     = pageFactory;
     try
     {
         SubscriptionTypeLabel = "   " + _model.Subscription.SubscriptionType.ToString();
         RemainingOrdersLabel  = "   " + _model.RemainingOrders.ToString();
         PurchasedOrdersLabel  = "   " + _model.PurchasedReports?.Count.ToString();
         EndDateLabel          = "   " + _model.Subscription.EndDateTime.ToString("dddd, dd MMMM yyyy");
         GetMoreReportsLabel   = $"Purchase additional reports at a reduced price of ${SubscriptionUtility.GetSingleReportInfo(_model).Price} per report.";
         GetMoreReportsCommand = new Command(() => _nav.Push(_pageFactory.GetPage(PageType.SingleReportPurchase, _model)));
         var compName   = _runtimePlatform == Device.Android ? "Google" : "Apple";
         var supportUri = _runtimePlatform == Device.Android ? "https://support.google.com/googleplay/answer/7018481" :
                          "https://support.apple.com/en-us/HT202039#subscriptions";
         DisclaimerLabel  = $"NOTE: {compName} does not allow subscriptions to be cancelled through the app. This button will open a web browser with instructions on how to cancel from your device.";
         CancelSubCommand = new Command(() => _openUri(new Uri(supportUri)));
     }
     catch (Exception ex)
     {
         _logger.LogError($"Failed to load manage subscription page.", ex);
     }
 }
Exemplo n.º 4
0
        private async Task HandleSubmitClick()
        {
            try
            {
                var user = _userService.GetLoggedInAccount();

                SubmitButtonEnabled = false;
                ErrorMessage        = "";
                if (string.IsNullOrWhiteSpace(AddressLine1) ||
                    string.IsNullOrWhiteSpace(City) ||
                    SelectedStateIndex < 0 ||
                    SelectedOptionIndex < 0 ||
                    string.IsNullOrWhiteSpace(Zip))
                {
                    ErrorMessageRowHeight = GridLength.Star;
                    ErrorMessage          = "Please fill out all fields before submitting.";
                    SubmitButtonEnabled   = true;
                    return;
                }
                if (user == null)
                {
                    var answer = await _alertUtility.Display("Please Log In", "Please log in first to submit a report.", "Login", "Cancel");

                    if (!answer)
                    {
                        SubmitButtonEnabled = true;
                        return;
                    }
                    _nav.Push(_pageFactory.GetPage(PageType.Landing));
                    SubmitButtonEnabled = true;
                    return;
                }
                await SubmitOrder(user.UserId, user.Email);
            }
            catch (Exception ex)
            {
                ErrorMessageRowHeight = GridLength.Star;
                SubmitButtonEnabled   = true;
                ErrorMessage          = $"Failed to submit order with error {ex.Message}";
                _logger.LogError($"Failed to submit order.", ex);
            }
            finally
            {
                try
                {
                    await SetVisualStateForValidation();
                }
                catch { }
            }
        }
 private void HandleSelectedItemChange(OrderViewCell selected)
 {
     try
     {
         if (selected == null)
         {
             return;
         }
         var id = selected.OrderId;
         _nav.Push(_pageFactory.GetPage(PageType.OrderDetail, _orderCache.Get(id)));
     }
     catch (Exception ex)
     {
         _logger.LogError($"Failed to handle selected item change event.", ex);
     }
     OrderListSelectedItem = null;
 }
        private async Task SubmitFeedback(string feedback)
        {
            if (string.IsNullOrWhiteSpace(feedback))
            {
                return;
            }
            var user = _userCache.GetLoggedInAccount();

            if (user == null)
            {
                var response = await _alertUtility.Display("Not Logged In", "Because you are not logged in, Fair Squares staff will not be able to respond to your feedback. " +
                                                           "Are you sure you want to continue?", "Continue", "Log In");

                if (!response)
                {
                    _nav.Push(_pageFactory.GetPage(PageType.Landing));
                    return;
                }
            }
            try
            {
                _notifier.Notify(new Models.NotificationRequest()
                {
                    From        = "*****@*****.**",
                    To          = "*****@*****.**",
                    Message     = feedback,
                    MessageType = Models.MessageType.Email,
                    Subject     = "Feedback from " + user?.Email
                });
                await _alertUtility.Display("Feedback Submitted", "Thank you for your feedback!", "Ok");
            }
            catch (Exception ex)
            {
                _logger.LogError("Failed to submit feedback.", ex, $"Feedback: {feedback}");
            }
            _nav.Pop();
        }
        public MyOrdersViewModel(IOrderService orderSvc,
                                 ICache <Models.Order> orderCache,
                                 ICache <PropertyModel> propertyCache,
                                 ICache <ImageModel> imageCache,
                                 ILogger <MyOrdersViewModel> logger,
                                 ICacheRefresher cacheRefresher,
                                 IOrderValidationService validator,
                                 IPageFactory pageFactory,
                                 ICurrentUserService userService,
                                 LaunchedFromPushModel pushModel,
                                 MainThreadNavigator nav,
                                 IMessagingCenter messagingCenter,
                                 Action <Action> uiInvoke,
                                 Action <BaseNavPageType> baseNavAction)
        {
            _orderService      = orderSvc;
            _orderCache        = orderCache;
            _propertyCache     = propertyCache;
            _imageCache        = imageCache;
            _logger            = logger;
            _uiInvoke          = uiInvoke;
            _cacheRefresher    = cacheRefresher;
            _validationService = validator;
            _pageFactory       = pageFactory;
            _userService       = userService;
            _messagingCenter   = messagingCenter;
            _nav                 = nav;
            _baseNavAction       = baseNavAction;
            ExampleReportCommand = new Command(() =>
            {
                try
                {
                    var order = JsonConvert.DeserializeObject <Models.Order>(Examples.ExampleOrder);
                    _imageCache.Put(order.OrderId, new ImageModel()
                    {
                        OrderId = order.OrderId,
                        Image   = Convert.FromBase64String(Examples.ExampleImage)
                    });
                    _propertyCache.Put(order.OrderId, JsonConvert.DeserializeObject <PropertyModel>(Examples.ExampleProperty));
                    _nav.Push(_pageFactory.GetPage(PageType.OrderDetail, order));
                }
                catch (Exception ex)
                {
                    _logger.LogError($"An error occurred while trying to open example order.", ex);
                }
            });
            Action refreshAction = async() =>
            {
                try
                {
                    OrderListRefreshing = true;
                    var fresh = await _orderService.GetMemberOrders(_userService.GetLoggedInAccount()?.UserId);

                    _orderCache.Put(fresh.ToDictionary(x => x.OrderId, x => x));
                    SetListViewSource(fresh.ToList());
                    OrderListRefreshing = false;
                }
                catch (Exception ex)
                {
                    _logger.LogError($"Failed to refresh order list.", ex);
                }
            };

            OrderListRefreshCommand = new Command(refreshAction);
            _messagingCenter.Subscribe <App>(this, "CacheInvalidated", async x =>
            {
                await this.SetViewState();
            });
            OnAppearingBehavior = new Command(async() =>
            {
                if (!_pmEventSubscribed)
                {
                    _pmEventSubscribed         = true;
                    pushModel.PropertyChanged += async(s, e) =>
                    {
                        if (!string.IsNullOrWhiteSpace(pushModel.OrderId))
                        {
                            var order = await _orderService.GetOrder(pushModel.OrderId);
                            _orderCache.Put(order.OrderId, order);
                            _nav.Push(_pageFactory.GetPage(PageType.OrderDetail, order));
                        }
                    };
                }
                await SetViewState();
            });
        }
Exemplo n.º 8
0
 private async Task SetInitialState(AccountModel user)
 {
     ToolbarInfoCommand = new Command(() => _navigation.Push(_pageFactory.GetPage(PageType.Instruction, false)));
     LogOutCommand      = new Command(async() =>
     {
         if (_userCache.GetLoggedInAccount() == null)
         {
             _navigation.Push(_pageFactory.GetPage(PageType.Landing));
         }
         else
         {
             _userCache.LogOut();
             SetAccountState(null);
             await SetSubState(null);
         }
     });
     SubscriptionCommand = new Command(async() =>
     {
         if (_userCache.GetLoggedInAccount() == null)
         {
             return;
         }
         var valid = await _orderValidator.ValidateOrderRequest(_userCache.GetLoggedInAccount());
         try
         {
             SubscriptionButtonEnabled = false;
             if (SubscriptionUtility.SubscriptionActive(valid.Subscription))
             {
                 _navigation.Push(_pageFactory.GetPage(PageType.ManageSubscription, valid));
             }
             else
             {
                 _navigation.Push(_pageFactory.GetPage(PageType.PurchaseOptions, valid));
             }
         }
         catch (Exception ex)
         {
             _logger.LogError("Failed to handle subscription click command.", ex);
         }
         finally
         {
             SubscriptionButtonEnabled = true;
         }
     });
     FeedbackCommand = new Command(() =>
     {
         try
         {
             FeedbackButtonEnabled = false;
             _navigation.Push(_pageFactory.GetPage(PageType.Feedback, _navigation));
         }
         catch (Exception ex)
         {
             _logger.LogError("Failed to handle feedback click command.", ex);
         }
         finally
         {
             FeedbackButtonEnabled = true;
         }
     });
     SetAccountState(user);
     await SetSubState(user);
 }