Example #1
0
        async void CreateAssets_Clicked(object sender, System.EventArgs e)
        {
            try
            {
                if (AssetIDTextField.Text == null &&
                    AssetTypeEntry.Text == null &&
                    DescriptionTextField.Text == null &&
                    LocationTextField.Text == null)
                {
                    await DisplayAlert("Error", "Please fill in missing fields.", "Ok");
                }
                else if (AssetIDTextField.Text == null)
                {
                    await DisplayAlert("Error", "Please fill in asset ID/barcode.", "Ok");
                }
                else if (AssetTypeEntry.Text == null)
                {
                    await DisplayAlert("Error", "Please fill in asset type.", "Ok");
                }
                else if (DescriptionTextField.Text == null)
                {
                    await DisplayAlert("Error", "Please fill in description.", "Ok");
                }
                else if (LocationTextField.Text == null)
                {
                    await DisplayAlert("Error", "Please fill in location.", "Ok");
                }
                //else if (QuantityEntry.Text == null)
                //{
                //    await DisplayAlert("Error", "Please Fill Quantity.", "OK");
                //}
                else
                {
                    Dictionary <string, string> dict = new Dictionary <string, string>();
                    dict["assetId"]   = AssetIDTextField.Text;
                    dict["assetType"] = AssetTypeEntry.Text;
                    if (AssetTypeEntry.Text == "batch")
                    {
                        dict["description"] = DescriptionTextField.Text;
                        dict["status"]      = LocationTextField.Text;
                        dict["quantity"]    = QuantityEntry.Text;
                        var isSuccess = await cloudStore.AddCreateAsset(dict);

                        if (isSuccess)
                        {
                            await DisplayAlert("Success", "Asset created successfully.", "Ok");

                            App.Current.MainPage = new MainPage();
                        }
                    }
                    else if (AssetTypeEntry.Text == "single")
                    {
                        dict["description"] = DescriptionTextField.Text;
                        dict["status"]      = LocationTextField.Text;
                        var isSuccess = await cloudStore.AddCreateAsset(dict);

                        if (isSuccess)
                        {
                            await DisplayAlert("Success", "Asset created successfully.", "Ok");

                            App.Current.MainPage = new MainPage();
                        }
                    }

                    else
                    {
                        await DisplayAlert("Error", "Asset creation failed. Please try again.", "Ok");

                        AssetIDTextField.Text     = string.Empty;
                        AssetTypeEntry.Text       = string.Empty;
                        DescriptionTextField.Text = string.Empty;
                        LocationTextField.Text    = string.Empty;
                        QuantityEntry.Text        = string.Empty;
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }