Ejemplo n.º 1
0
 public OrderFacade(IOrderValidationService orderValidationService, IOrderRepository ordersRepo, IPcRepository pcRepo, IClientRepository clientRepo, IDeliveryService deliveryService, ITaxService taxService, IClientOrderFactory clientOrderFactory, INotifier notifier)
 {
     _orderValidationService = orderValidationService;
     _clientRepo             = clientRepo;
     _pcRepo          = pcRepo;
     _ordersRepo      = ordersRepo;
     _deliveryService = deliveryService;
     _taxService      = taxService;
     _orderFactory    = clientOrderFactory;
     _notifier        = notifier;
 }
Ejemplo 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
        }
Ejemplo n.º 3
0
        public AccountViewModel(ICurrentUserService userCache,
                                IOrderValidationService orderValidator,
                                MainThreadNavigator navigation,
                                IPageFactory pageFactory,
                                Action <string> changeLogInStyleClass,
                                Action <string> changeSubStyleClass,
                                ILogger <AccountViewModel> logger,
                                ICacheRefresher cacheRefresher)
        {
            _navigation            = navigation;
            _pageFactory           = pageFactory;
            _userCache             = userCache;
            _logger                = logger;
            _cacheRefresher        = cacheRefresher;
            _userCache.OnLoggedIn += async(s, e) =>
            {
                SetAccountState(e.Account);
                await SetSubState(e.Account);
            };
            _userCache.OnLoggedOut += async(s, e) =>
            {
                SetAccountState(null);
                await SetSubState(null);
            };
            _orderValidator        = orderValidator;
            _changeLoginStyleClass = changeLogInStyleClass;
            _changeSubStyleClass   = changeSubStyleClass;
            var user = userCache.GetLoggedInAccount();

            _logger             = logger;
            OnAppearingBehavior = new Command(async() =>
            {
                var u = _userCache.GetLoggedInAccount();
                SetAccountState(u);
                await SetSubState(u);
            });
            SetInitialState(user);
        }
        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();
            });
        }