Esempio n. 1
0
		public async void SendPhoto (byte[] image)
		{
			if (cameraPage.IsMemberImage) {
				if (CrossConnectivity.Current.IsConnected) {
					MemberImageDTO memberImageDTO = new MemberImageDTO ();
					memberImageDTO.ProfileID = cameraPage.SelectedUser.ProfileID;
					memberImageDTO.GymID = cameraPage.SelectedUser.GymID;
					memberImageDTO.ImageBytes = Convert.ToBase64String (image);
					int response = await CoachServices.PostMemberImage (memberImageDTO);
					if (response != 1) {
						DependencyService.Get<ICustomDialog> ().Display (StringConstants._ImageSubmissionFailedPrompt, "OK");
					} else {
						DependencyService.Get<ICustomDialog> ().Display ("Image Saved!", "OK");
						await App.Current.MainPage.Navigation.PopAsync (false);
						await App.Current.MainPage.Navigation.PopAsync (false);
						await App.Current.MainPage.Navigation.PushAsync (new MemberProfilePage (cameraPage.SelectedUser, image));
					}
				} else {
					DependencyService.Get<ICustomDialog> ().Display (StringConstants._FeatureConnectivityDepencyMessage, "OK");
				}

			} else {
				var navigationPage = new NavigationPage (new TrainerImagePage (image)) {
					BarBackgroundColor = Color.Blue,
					BarTextColor = Color.White
				};

				await App.Current.MainPage.Navigation.PushModalAsync (navigationPage, false);
			}
		}
Esempio n. 2
0
		public static async Task<int> PostMemberImage(MemberImageDTO memberImageDTO)
		{
			String serviceType = "SaveMemberImage";
			string rawJSON = JsonConvert.SerializeObject(memberImageDTO);
			var stringResponse = await BaseCoachServices.ServiceAPI.Post(serviceType, rawJSON);
			if (stringResponse == "401")
			{
				if (await TokenManager.RefreshToken())
				{
					stringResponse = await BaseCoachServices.ServiceAPI.Post(serviceType, rawJSON);
				}
			}

			int intResponse = 0;
			int.TryParse(stringResponse, out intResponse);

			return intResponse;
		}
		async void OnTapGestureRecognizerTapped(object sender, EventArgs args)
		{

			if (ViewModel.IsBusy)
				return;

			ViewModel.IsBusy = true;
			CircleImage circleImage = sender as CircleImage;
			await circleImage.FadeTo(.2, 100);



			if (CrossConnectivity.Current.IsConnected)
			{
				MediaFile file = null;
				var action = await App.Current.MainPage.DisplayActionSheet("Use camera or select picture from this device?", "Cancel", null, "Camera", "Photo Library");
				if (action == null)
				{
					action = "Cancel";
				}
				if (action == "Camera")
				{
					if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
					{
						await App.Current.MainPage.DisplayAlert("No Camera", ":( No camera available.", "OK");
						IsBusy = false;
						return;
					}
					else {
						file = await CrossMedia.Current.TakePhotoAsync(new StoreCameraMediaOptions
						{
							Directory = "Sample",
							SaveToAlbum = true,
							Name = "test.jpg"
						});
						if (file == null)
						{
							action = "Cancel";
						}

					}
				}
				else {
					if (action == "Photo Library")
					{
						file = await CrossMedia.Current.PickPhotoAsync();
						if (file == null)
						{
							action = "Cancel";
						}
					}
				}

				if (action != "Cancel")
				{

					var imageRotationService = DependencyService.Get<IImageRotation>();

					//byte[] pngByteArray = file.GetStream ().ToByteArray();
					byte[] pngByteArray = imageRotationService.ScaleAndRotateImage(file.Path);
					file.Dispose();

					MemberImageDTO memberImageDTO = new MemberImageDTO();
					memberImageDTO.ProfileID = ViewModel.SelectedUser.ProfileID;
					memberImageDTO.GymID = ViewModel.SelectedUser.GymID;
					memberImageDTO.ImageBytes = Convert.ToBase64String(pngByteArray);
					int response = await CoachServices.PostMemberImage(memberImageDTO);
					if (response != 1)
					{
						DependencyService.Get<ICustomDialog>().Display(StringConstants._ImageSubmissionFailedPrompt, "OK");
					}
					else {
						DependencyService.Get<ICustomDialog>().Display("Image Saved!", "OK");
						await Application.Current.MainPage.Navigation.PopAsync(false);
						await Application.Current.MainPage.Navigation.PushAsync(new MemberProfilePage(ViewModel.SelectedUser, pngByteArray), false);
					}
				}
			}
			else {
				DependencyService.Get<ICustomDialog>().Display(StringConstants._FeatureConnectivityDepencyMessage, "OK");

			}

			await circleImage.FadeTo(1, 100);

			ViewModel.IsBusy = false;
		}