示例#1
0
 private async Task addUpdatePlayer(bool isUpdate)
 {
     try
     {
         var imgSource = "";
         if (string.IsNullOrWhiteSpace(playerNameEntry.Text) || string.IsNullOrWhiteSpace(playerInfoEntry.Text))
         {
             CrossToastPopUp.Current.ShowToastMessage("Please Fill all the field", Plugin.Toast.Abstractions.ToastLength.Long);
             return;
         }
         if (!string.IsNullOrEmpty(imgPath))
         {
             imgSource = await RemoteImageUpload.UploadImageToCloudinary(imgPath);
         }
         else
         {
             if (isUpdate)
             {
                 imgSource = _player.ImageUrl;
             }
             else
             {
                 CrossToastPopUp.Current.ShowToastMessage("Please upload the image.", Plugin.Toast.Abstractions.ToastLength.Long);
                 return;
             }
         }
         if (string.IsNullOrEmpty(imgSource))
         {
             //throw new Exception($"Error while uploading image");
             CrossToastPopUp.Current.ShowToastMessage("Image upload failed try again", Plugin.Toast.Abstractions.ToastLength.Long);
             return;
         }
         var isSuccess = false;
         if (isUpdate)
         {
             isSuccess = await remoteUpdatePlayer(imgSource);
         }
         else
         {
             isSuccess = await remoteAddNewPlayer(imgSource);
         }
         if (isSuccess)
         {
             CrossToastPopUp.Current.ShowToastSuccess("Successfully save the tournament.", Plugin.Toast.Abstractions.ToastLength.Long);
             //playerNameEntry.Text = string.Empty;
             //detailsEntry.Text = string.Empty;
             //img.Source = "default_cover.png";
             await Navigation.PopModalAsync();
         }
         else
         {
             CrossToastPopUp.Current.ShowToastMessage("Error occured, Please try again.", Plugin.Toast.Abstractions.ToastLength.Long);
         }
     }
     catch (Exception ex)
     {
     }
 }
 private async Task addUpdate(bool isUpdate)
 {
     try
     {
         var imgSource = "";
         if (string.IsNullOrWhiteSpace(nameEntry.Text) || string.IsNullOrWhiteSpace(detailsEntry.Text))
         {
             CrossToastPopUp.Current.ShowToastMessage("Please Fill all the field", Plugin.Toast.Abstractions.ToastLength.Long);
             return;
         }
         if (!string.IsNullOrEmpty(imgPath))
         {
             imgSource = await RemoteImageUpload.UploadImageToCloudinary(imgPath);
         }
         else
         {
             if (isUpdate)
             {
                 imgSource = _tournament.ImageUrl;
             }
             else
             {
                 CrossToastPopUp.Current.ShowToastMessage("Please upload the image.", Plugin.Toast.Abstractions.ToastLength.Long);
                 return;
             }
         }
         if (string.IsNullOrEmpty(imgSource))
         {
             //throw new Exception($"Error while uploading image");
             CrossToastPopUp.Current.ShowToastMessage("Image upload failed try again", Plugin.Toast.Abstractions.ToastLength.Long);
             return;
         }
         var startDateTime = new DateTime(startDatePickerEntry.Date.Year, startDatePickerEntry.Date.Month,
                                          startDatePickerEntry.Date.Day, startTimePickerEntry.Time.Hours, startTimePickerEntry.Time.Minutes,
                                          startTimePickerEntry.Time.Seconds);
         var endDateTime = new DateTime(endDatePickerEntry.Date.Year, endDatePickerEntry.Date.Month,
                                        endDatePickerEntry.Date.Day, endTimePickerEntry.Time.Hours, endTimePickerEntry.Time.Minutes,
                                        endTimePickerEntry.Time.Seconds);
         var isSuccess = false;
         if (isUpdate)
         {
             isSuccess = await remoteUpdateTournament(imgSource, startDateTime, endDateTime);
         }
         else
         {
             isSuccess = await remoteAddNewTournament(imgSource, startDateTime, endDateTime);
         }
         if (isSuccess)
         {
             CrossToastPopUp.Current.ShowToastSuccess("Successfully save the tournament.", Plugin.Toast.Abstractions.ToastLength.Long);
             //nameEntry.Text = string.Empty;
             //detailsEntry.Text = string.Empty;
             //img.Source = "default_cover.png";
             await Navigation.PopModalAsync();
         }
         else
         {
             CrossToastPopUp.Current.ShowToastMessage("Error occured, Please try again.", Plugin.Toast.Abstractions.ToastLength.Long);
         }
     }
     catch (Exception ex)
     {
     }
 }