Пример #1
0
        protected override void OnAppearing()

        {
            base.OnAppearing();

            AppPersistenceService.SaveValue(AppPropertiesKeys.IS_ONLINE, CrossConnectivity.Current.IsConnected);
        }
Пример #2
0
 private async void Current_ConnectivityChanged(object sender, ConnectivityChangedEventArgs e)
 {
     AppPersistenceService.SaveValue(AppPropertiesKeys.IS_ONLINE, e.IsConnected);
     if (!e.IsConnected)
     {
         DependencyService.Get <IToastMessage>().Show("You Are Offline Now .. Please turn on internet Connectivity");
     }
 }
Пример #3
0
 private async void Current_ConnectivityChanged(object sender, ConnectivityChangedEventArgs e)
 {
     AppPersistenceService.SaveValue(AppPropertiesKeys.IS_ONLINE, e.IsConnected);
     if (e.IsConnected)
     {
         await StartSyncProcess();
     }
 }
        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 ..");
        }
Пример #5
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;
        }
Пример #6
0
        private async void ExecuteLogin()
        {
            try
            {
                var userName = UserName?.ToLower();
                if (Regex.IsMatch(userName, @"^[a-zA-Z0-9 ]*$"))
                {
                    var connection = DependencyService.Get <ISQLiteDb>().GetConnection();

                    if (CrossConnectivity.Current.IsConnected)
                    {
                        var result = await _usersService.GetUserByUserName(userName);

                        if (result != null)
                        {
                            await connection.CreateTableAsync <UserModel>();

                            if (await connection.Table <UserModel>().FirstOrDefaultAsync(x => x.UserName == userName) == null)
                            {
                                await connection.InsertAsync(new UserModel()
                                {
                                    UserId = result.UserId, UserName = result.UserName
                                });
                            }

                            AppPersistenceService.SaveValue(AppPropertiesKeys.USER_NAME, result.UserName);
                            AppPersistenceService.SaveValue(AppPropertiesKeys.USER_ID, result.UserId);
                            await View.Navigation.PushAsync(new HomePage());

                            DependencyService.Get <IToastMessage>().Show("App Data Sync is starting ..");
                            await SyncDataService.Instance.SyncProductsData();

                            DependencyService.Get <IToastMessage>().Show("App Data Sync Done ..");
                        }
                        else
                        {
                            await View.DisplayAlert("Error", "User Not Found", "OK");
                        }
                    }
                    else
                    {
                        var users = await connection.Table <UserModel>().ToListAsync();

                        var result = users.FirstOrDefault(u => u.UserName == userName);
                        if (result != null)
                        {
                            AppPersistenceService.SaveValue(AppPropertiesKeys.USER_NAME, result.UserName);
                            await View.Navigation.PushAsync(new HomePage());
                        }
                        else
                        {
                            await View.DisplayAlert("Error", "User Not Found", "OK");
                        }
                    }
                }
                else
                {
                    await View.DisplayAlert("Error", "User Name Should not contain Any spaces or Special Characters", "OK");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                await View.DisplayAlert("Error", "Error Occured while trying to login", "OK");
            }
        }
Пример #7
0
 private async void Logout_OnClicked(object sender, EventArgs e)
 {
     AppPersistenceService.SaveValue(AppPropertiesKeys.USER_NAME, string.Empty);
     await Navigation.PushAsync(new MainPage());
 }