public async Task DeleteAsync(int id, int userId) { if (!Exists(id, userId)) { throw new ValidationException("Unauthorized"); } await _ingredientsRepository.DeleteAsync(id); }
public ShowIngredientsPageViewModel( IIngredientsRepository ingredientsRepository, INavigationService navigationService, IUserInteraction userInteraction) : base(navigationService, ingredientsRepository) { this.WhenAnyObservable(vm => vm.Ingredients.ItemChanged) .ObserveOn(RxApp.MainThreadScheduler) .Where(arg => arg.PropertyName == nameof(DrinkIngredientViewModel.TickSelected)) .Select(arg => (DrinkIngredientViewModel)arg.Sender) .Do(ingredient => SelectedDrinkIngredient = ingredient) .Subscribe(async ingredientViewModel => { var selections = new List <string>() { "Edit", "Delete" }; var result = await userInteraction.DisplayActionSheetAsync( $"{ingredientViewModel.Name} selected!", "Cancel", null, selections.ToArray()); if (result == "Edit") { var navigationParameter = new TypedParameter(typeof(DrinkIngredientViewModel), ingredientViewModel); await navigationService.PushAsync <EditIngredientPageViewModel>(navigationParameter); } else if (result == "Delete") { await ingredientsRepository.DeleteAsync(ingredientViewModel.Ingredient); await ActivateAsync(); } else { ExceptionFactory.Get <NotImplementedException>("That selection is not jet implemented!"); } }); }