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();
        }