Ejemplo n.º 1
0
        private async void ButtonSubmit_Clicked(object sender, EventArgs e)
        {
            var kostData = (KostData)BindingContext;
            var kost     = kostData.Kost;

            string alertMessage;

            var error = kost.Validate();

            if (error != null)
            {
                await DisplayAlert("Error", error, "Try Again");

                return;
            }

            var loadingDialog = await MaterialDialog.Instance.LoadingDialogAsync(message : "On Processing :)");

            if (newData)
            {
                if (file == null)
                {
                    await DisplayAlert("Error", "Image can't be blank", "Try Again");

                    return;
                }

                var imageUrl = await firebaseHelper.StoreImage(file.GetStream());

                kost.ImageUrl = imageUrl;
                await firebaseHelper.AddKost(kost);

                alertMessage = "Kost Added Successfully";
            }
            else
            {
                if (file != null)
                {
                    var imageUrl = await firebaseHelper.StoreImage(file.GetStream());

                    kost.ImageUrl = imageUrl;
                }
                await firebaseHelper.UpdateKost(kostData);

                alertMessage = "Kost Updated Successfully";
            }

            await loadingDialog.DismissAsync();

            await DisplayAlert("Success", alertMessage, "OK");

            await Navigation.PopAsync();
        }