Esempio n. 1
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 { }
            }
        }
Esempio n. 2
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
        }
        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();
        }
Esempio n. 4
0
        private async void PurchaseButtonClicked()
        {
            LoadAnimationRunning  = true;
            LoadAnimationVisible  = true;
            PurchaseButtonEnabled = false;
            try
            {
                SubscriptionType selected = SubscriptionType.Basic;
                var subCode = SubscriptionUtility.GetInfoFromSubType(selected).SubscriptionCode;
                try
                {
                    await PurchaseSubscription(subCode);

                    await _alertUtility.Display("Purchase Complete", "Thank you for your purchase!", "Ok");

                    _nav.PopToRoot();
                }
                catch (Exception ex)
                {
                    _toastService.LongToast($"Failed to purchase subscription. {ex.Message}");
                }
            }
            catch (Exception ex)
            {
                _toastService.LongToast($"Something went wrong when trying to purchase subscription. {ex.Message}");
            }
            finally
            {
                try
                {
                    PurchaseButtonEnabled = true;
                    LoadAnimationRunning  = false;
                    LoadAnimationVisible  = false;
                }
                catch { }
            }
        }
        private async Task PurchaseButtonClicked()
        {
            LoadAnimationRunning  = true;
            LoadAnimationVisible  = true;
            PurchaseButtonEnabled = false;
            try
            {
                var code = SubscriptionUtility.GetSingleReportInfo(_validation).Code;
                try
                {
                    await PurchaseItem(code);

                    await _alertUtility.Display("Purchase Complete", "Thank you for your purchase!", "Ok");

                    _nav.PopToRoot();
                }
                catch (Exception ex)
                {
                    _toastService.LongToast($"Failed to purchase report. {ex.Message}");
                }
            }
            catch (Exception ex)
            {
                _toastService.LongToast($"Something went wrong when trying to purchase report. {ex.Message}");
            }
            finally
            {
                try
                {
                    PurchaseButtonEnabled = true;
                    LoadAnimationRunning  = false;
                    LoadAnimationVisible  = false;
                }
                catch { }
            }
        }