//constructor public PictureDetailViewModel(PicturesViewModel viewModel, IPicturePostStore pictureStore, IPageService pageService) { if (viewModel == null) { throw new ArgumentNullException(nameof(viewModel)); } _pictureStore = pictureStore; _pageService = pageService; SaveCommand = new Command(async() => await Save()); PickPictureCommand = new Command(async() => await PickPicture()); Post = new PicturePost { ID = viewModel.ID, PictureTitle = viewModel.PictureTitle, PictureCategory = viewModel.PictureCategory, PictureLocation = viewModel.PictureLocation, PictureTime = viewModel.PictureTime, PictureRating = viewModel.PictureRating, PicturePath = viewModel.PicturePath }; }
//when u select a post private async Task SelectPicture(PicturesViewModel post) { if (post == null) { return; } SelectedPost = null; await _pageService.PushAsync(new PicturesDetailPage(post)); }
//deleting a picture private async Task DeletePicture(PicturesViewModel picturesViewModel) { if (await _pageService.DisplayAlert("Warning", $"Are you sure you want to delete {picturesViewModel.PictureTitle}?", "Yes", "No")) { Posts.Remove(picturesViewModel); PicturePost contact = await _postStore.GetPicturePost(picturesViewModel.ID); await _postStore.DeletePicturePost(contact); } }
//reset the picture category private async Task ResetPictureCategory(PicturesViewModel post) { post.PictureCategory = ""; }
//reset the picture rating private async Task ResetPictureRating(PicturesViewModel post) { post.PictureRating = 0; }