public void DeletePhoto () { var assignment = new Assignment { TotalItems = 1 }; var photo = new Photo (); viewModel.Photos = new List<Photo> { photo }; var task = viewModel.DeletePhotoAsync (assignment, photo); task.Wait (); Assert.That (viewModel.Photos.Count, Is.EqualTo (0)); }
/// <summary> /// Set the photo for this cell /// </summary> public void SetPhoto(Photo photo) { //Free up the previous image if there was one if (image != null) image.Dispose (); date.Text = photo.Date.ToShortTimeString () + " " + photo.Date.ToShortDateString (); description.Text = photo.Description; this.photo.Image = image = photo.Image.ToUIImage (); }
/// <summary> /// Saves a photo /// </summary> public Task SavePhotoAsync (Assignment assignment, Photo photo) { bool newPhoto = photo.Id == 0; //Update the date photo.Date = DateTime.Now; return service .SavePhotoAsync (photo) .ContinueOnCurrentThread (t => { if (newPhoto) { if (photos == null) photos = new List<Photo> (); photos.Add (photo); OnPropertyChanged ("Photos"); } }); }
private async void OnItemClick (object sender, ItemClickEventArgs e) { var element = e.ClickedItem as FrameworkElement; switch (element.Name) { case "addSignature": assignmentViewModel.AddSignatureCommand.Invoke (); break; case "markComplete": { //signature control does not work at the moment, just allow it to proceed w/o signature for now. //if (assignmentViewModel.Signature == null) { // await new MessageDialog ("No signature!").ShowAsync (); //} var dialog = new MessageDialog ("Are you sure?", "Complete?"); bool yesComplete = false; dialog.Commands.Add (new UICommand ("Yes", _ => yesComplete = true)); dialog.Commands.Add (new UICommand ("No")); await dialog.ShowAsync (); if (yesComplete) { assignmentViewModel.CompleteCommand.Invoke (); } } break; case "addImage": { bool cameraCommand = false, imageCommand = false; var dialog = new MessageDialog ("Take picture with your built in camera or select one from your photo library.", "Add Image"); if (picker.IsCameraAvailable) { dialog.Commands.Add (new UICommand ("Camera", new UICommandInvokedHandler (_ => cameraCommand = true))); } dialog.Commands.Add (new UICommand ("Library", new UICommandInvokedHandler (_ => imageCommand = true))); await dialog.ShowAsync (); if (cameraCommand) { try { var mediaFile = await picker.TakePhotoAsync (new StoreCameraMediaOptions()); var photo = new Photo (); await mediaFile.GetStream ().LoadBytes ().ContinueWith (t => { photo.Image = t.Result; }); photoViewModel.PhotoSelectedCommand.Invoke (photo); Helpers.NavigateTo<ImagesPage> (); } catch(Exception exc) { Debug.WriteLine (exc.Message); //this could happen if they cancel, etc. } } else if (imageCommand) { try { var mediaFile = await picker.PickPhotoAsync (); var photo = new Photo (); await mediaFile.GetStream ().LoadBytes ().ContinueWith (t => { photo.Image = t.Result; }); photoViewModel.PhotoSelectedCommand.Invoke (photo); Helpers.NavigateTo<ImagesPage> (); } catch (Exception exc) { Debug.WriteLine (exc.Message); //this could happen if they cancel, etc. } } } break; default: await new MessageDialog ("Coming soon!").ShowAsync (); break; } }
public Task <int> DeletePhotoAsync(Photo photo, CancellationToken cancellationToken = default(CancellationToken)) { return(Database.GetConnection(cancellationToken).DeleteAsync(photo)); }
/// <summary> /// Save the photo /// </summary> private void SavePhoto () { Photo savePhoto = Photo; if (savePhoto == null) { savePhoto = new Photo (); savePhoto.Image = imageBitmap.ToByteArray (); } savePhoto.Description = optionalCaption.Text; savePhoto.AssignmentId = Assignment.Id; photoViewModel.SavePhotoAsync (Assignment, savePhoto) .ContinueWith (_ => { activity.RunOnUiThread (() => { var fragment = Activity.FragmentManager.FindFragmentById<ConfirmationFragment> (Resource.Id.contentFrame); fragment.ReloadConfirmation (); Dismiss (); }); }); }
/// <summary> /// Deletes a photo /// </summary> public Task DeletePhotoAsync (Assignment assignment, Photo photo) { return service .DeletePhotoAsync (photo) .ContinueOnCurrentThread (t => { if (photos != null) photos.Remove (photo); }); }
public Task<int> DeletePhotoAsync (Photo photo, CancellationToken cancellationToken) { return Task.Factory.StartNew (() => 1); }
public void DeletePhoto () { var assignmentTask = service.GetAssignmentsAsync (CancellationToken.None); assignmentTask.Wait (); var assignment = assignmentTask.Result.First (); var photo = new Photo { AssignmentId = assignment.Id, Image = new byte [] { 255 } }; var task = service.SavePhotoAsync (photo, CancellationToken.None); task.Wait (); var deleteTask = service.DeletePhotoAsync (photo, CancellationToken.None); deleteTask.Wait (); Assert.That (deleteTask.Result, Is.EqualTo (1)); }
public Task<int> DeletePhotoAsync (Photo photo, CancellationToken cancellationToken = default(CancellationToken)) { return Database.GetConnection (cancellationToken).DeleteAsync (photo); }
public Task<int> SavePhotoAsync (Photo photo, CancellationToken cancellationToken) { if (photo.Id == 0) return Database.GetConnection (cancellationToken).InsertAsync (photo); else return Database.GetConnection (cancellationToken).UpdateAsync (photo); }