コード例 #1
0
        public async void LoadProductsData()
        {
            IsViewLoading = true;


            var result = await SyncDataService.Instance.SyncProductsData();

            var minmumPrice   = AppPersistenceService.GetValue(AppPropertiesKeys.MINIMUM_FILTER_VALUE) != null ? (double)AppPersistenceService.GetValue(AppPropertiesKeys.MINIMUM_FILTER_VALUE) : 0;
            var maximumPrice  = AppPersistenceService.GetValue(AppPropertiesKeys.MAXIMUM_FILTER_VALUE) != null ? (double)AppPersistenceService.GetValue(AppPropertiesKeys.MAXIMUM_FILTER_VALUE) : 100;
            var filteredValue = result?.Where(p => p.Price >= Convert.ToDecimal(minmumPrice) && p.Price <= Convert.ToDecimal(maximumPrice));

            if (filteredValue != null)
            {
                Items = new ObservableCollection <Product>(filteredValue);
            }

            IsViewLoading = false;
        }
コード例 #2
0
        private async void ExecuteAddToCart()
        {
            var cartItemsCount = AppPersistenceService.GetValue(AppPropertiesKeys.CART_ITEMS_COUNT);

            if (cartItemsCount != null)
            {
                DependencyService.Get <IToolbarItemBadge>().SetBadge(View, View.ToolbarItems.First(), $"{(int)cartItemsCount + Quantity}", Color.Red, Color.White);

                AppPersistenceService.SaveValue(AppPropertiesKeys.CART_ITEMS_COUNT, (int)cartItemsCount + Quantity);
            }
            else
            {
                DependencyService.Get <IToolbarItemBadge>().SetBadge(View, View.ToolbarItems.First(), $"{Quantity}", Color.Red, Color.White);
                AppPersistenceService.SaveValue(AppPropertiesKeys.CART_ITEMS_COUNT, Quantity);
            }

            var connection = DependencyService.Get <ISQLiteDb>().GetConnection();
            await connection.CreateTableAsync <CartModel>();

            var cartItem = await connection.Table <CartModel>()
                           .FirstOrDefaultAsync(x => x.ProductId == CurrentProduct.ProductId);

            if (cartItem == null)
            {
                await connection.InsertAsync(new CartModel()
                {
                    ProductId = CurrentProduct.ProductId, Price = CurrentProduct.Price, ProductImageUrl = CurrentProduct.MainImageUrl, ProductTitle = CurrentProduct.Title, Quantity = Quantity
                });
            }
            else
            {
                cartItem.Quantity += Quantity;
                await connection.UpdateAsync(cartItem);
            }

            await View.Navigation.PushAsync(new HomePage());

            DependencyService.Get <IToastMessage>().Show("Cart Updated Successfully ..");
        }
コード例 #3
0
        protected async override void OnAppearing()
        {
            base.OnAppearing();

            Title = AppPersistenceService.GetValue(AppPropertiesKeys.USER_NAME) + "";
            var cartItemsCount = AppPersistenceService.GetValue(AppPropertiesKeys.CART_ITEMS_COUNT);

            if (cartItemsCount != null)
            {
                DependencyService.Get <IToolbarItemBadge>().SetBadge(this, ToolbarItems.First(), $"{(int)cartItemsCount}", Color.Red, Color.White);
            }
            else
            {
                var connection = DependencyService.Get <ISQLiteDb>().GetConnection();
                await connection.CreateTableAsync <CartModel>();

                var cartItems = await connection.Table <CartModel>().ToListAsync();

                AppPersistenceService.SaveValue(AppPropertiesKeys.CART_ITEMS_COUNT, cartItems.Count);
                DependencyService.Get <IToolbarItemBadge>().SetBadge(this, ToolbarItems.First(), $"{cartItems.Count}", Color.Red, Color.White);
            }

            CrossConnectivity.Current.ConnectivityChanged += Current_ConnectivityChanged;
        }
コード例 #4
0
 protected override void OnAppearing()
 {
     base.OnAppearing();
     MinPrice = AppPersistenceService.GetValue(AppPropertiesKeys.MINIMUM_FILTER_VALUE) != null ? (double)AppPersistenceService.GetValue(AppPropertiesKeys.MINIMUM_FILTER_VALUE) : 10;
     MaxPrice = AppPersistenceService.GetValue(AppPropertiesKeys.MAXIMUM_FILTER_VALUE) != null ? (double)AppPersistenceService.GetValue(AppPropertiesKeys.MAXIMUM_FILTER_VALUE) : 100;
 }