Esempio n. 1
0
        private async void OnButtonDoneClicked(object sender, EventArgs e)
        {
            // Check if all entries are filled
            if (!IsNewProductReady())
            {
                await DisplayAlert("Error", "Please fill all entries", "OK");

                return;
            }

            // Product Assembly
            try
            {
                CreateProduct();
            }
            catch (Exception ex)
            {
                await DisplayAlert("Error", $"An error occurred \n {ex.Message}", "OK");
            }

            //User confirmation
            bool userConfirmation = await DisplayAlert("Confirmation", "Do you want to add the product to the database?", "ADD", "CANCEL");

            if (!userConfirmation)
            {
                return;
            }

            Product result = null;

            try
            {
                frmLoading.IsVisible        = true;
                formLayout.InputTransparent = true;
                LoadingAnimation();
                result = await OnlineDataManager.PostProductAsync(_newProduct, new ByteArrayPart(_imageByteArray, "name"));
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error Posting image:\n" + ex.Message);
            }
            formLayout.InputTransparent = false;
            frmLoading.IsVisible        = false;



            // Check if the upload failed
            if (result == null)
            {
                await DisplayAlert("Error", "Something failed", "OK");

                return;
            }

            await DisplayAlert("Done", "The product has been added successfully", "OK");

            await Navigation.PopAsync();
        }
Esempio n. 2
0
        // Append new products to Products list

        public async Task UpdateProductsAsync()
        {
            List <Product> products = await OnlineDataManager.GetProductsByCategoryLocationAsync(this.CategoryList, GetCurrencyString());

            // Order by Date
            products = this.Products.ToList().Union(products).ToList();

            this.Products = new ObservableCollection <Product>(products.OrderByDescending(p => p.Date));
        }
Esempio n. 3
0
        // Search by name

        public async Task FilterProductsByPartialNameAsync(string name)
        {
            List <Product> products = await OnlineDataManager.FilterProductsByPartialNameAsync(this.CategoryList, name);

            // Order by Date
            products = products.OrderByDescending(p => p.Date).ToList();

            this.Products = new ObservableCollection <Product>(products);
        }
Esempio n. 4
0
        // Filter out the already existing products inside Products list

        public async Task FilterProductsAsync(bool refreshProductsList)
        {
            List <Product> products = await OnlineDataManager.FilterProductsByCategoryLocationAsync(this.CategoryList, GetCurrencyString());

            // Order by Date
            products = products.OrderByDescending(p => p.Date).ToList();

            this.Products = new ObservableCollection <Product>(products);

            if (refreshProductsList)
            {
                ProductPage.UpdateProductListItemSource();
            }
        }
Esempio n. 5
0
        private async void OnDeleteProduct(object sender, EventArgs e)
        {
            bool confirmation = await DisplayAlert("Confirm", "Do you want to delete this product?", "Yes", "No");

            if (!confirmation)
            {
                return;
            }

            Product result = null;

            try
            {
                btnDelete.Text = "Deleting";
                PopupLayout.InputTransparent = true;
                DeletingTextAnimation();
                result = await OnlineDataManager.DeleteProductAsync(SelectedProduct._id);
            }
            catch (Exception ex)
            {
                await DisplayAlert("Error", "There was an error deleting the product", "Ok");

                return;
            }
            PopupLayout.InputTransparent = false;

            if (result == null)
            {
                return;
            }

            await DisplayAlert("Done", "Product deleted successfully", "Ok");

            await PopupNavigation.Instance.PopAsync(true);

            await _app.FilterProductsAsync(true);
        }