public AddOrEditViewModel(IRecipesEndPointAPI RecipesEndPointAPI) { _recipesEndPointAPI = RecipesEndPointAPI; SubmitCommand = new Command(async() => await Submit()); AddIngredientCommand = new Command(async() => await AddIngredient()); DeleteIngredientCommand = new Command(async() => await DeleteIngredient()); SelectImageCommand = new Command(async() => await OpenFile()); DeleteImageCommand = new Command(async() => await DeleteFile()); Title = "Dodaj"; ImagePath = ImageConstants.LoadDefaultImage; SubmitText = "Dodaj"; MessagingService.Current.Unsubscribe <RecipeModel>(EventMessages.EditRecipeEvent); MessagingService.Current.Subscribe <RecipeModel>(EventMessages.EditRecipeEvent, (sender, arg) => { Title = "Edytuj"; _addOrEdit = AddOrEdit.Edit; _recipeId = arg.RecipeId; SubmitText = "Zaktualizuj"; RecipeName = arg.Name; RecipeIngredients = new ObservableCollection <string>(arg.Ingredients.ToList()); RecipeInstructions = arg.Instruction; ImagePath = arg.ImagePath; IsPublic = arg.IsPublic; OnPropertyChanged(nameof(CanDeleteImage)); }); }
public RecipesViewModel(IRecipesEndPointAPI RecipesEndPointAPI, ILoggedUser loggedUser, IEventAggregator EventAggregator, IMapper mapper) { _mapper = mapper; _recipesEndPointAPI = RecipesEndPointAPI; _loggedUser = loggedUser; _eventAggregator = EventAggregator; _eventAggregator.SubscribeOnPublishedThread(this); }
public AddRecipeViewModel(IRecipesEndPointAPI RecipesEndPointAPI, IEventAggregator EventAggregator) { _recipesEndPointAPI = RecipesEndPointAPI; _eventAggregator = EventAggregator; _eventAggregator.SubscribeOnPublishedThread(this); SubmitText = "Dodaj"; ImagePath = ImageConstants.DefaultImage; }
public RecipePreviewViewModel(IRecipesEndPointAPI RecipesEndPointAPI, ILoggedUser loggedUser, IEventAggregator EventAggregator, IAPIHelper aPIHelper) { _recipesEndPointAPI = RecipesEndPointAPI; _loggedUser = loggedUser; _aPIHelper = aPIHelper; _eventAggregator = EventAggregator; _eventAggregator.SubscribeOnPublishedThread(this); CanEdit = false; }
public RecipesViewModel(IRecipesEndPointAPI RecipesEndPointAPI, ILoggedUser loggedUser, IMapper mapper) { Title = "Moje przepisy"; RefreshCommand = new Command(async() => await RefreshData(_currentRecipes)); BackCommand = new Command(async() => await RecipesBack()); NextCommand = new Command(async() => await RecipesNext()); _recipesEndPointAPI = RecipesEndPointAPI; _loggedUser = loggedUser; _mapper = mapper; MessagingService.Current.Unsubscribe(EventMessages.ReloadUserRecipesEvent); MessagingService.Current.Subscribe(EventMessages.ReloadUserRecipesEvent, async(sender) => { _currentRecipes = UserOrPublicOrFavouritesRecipes.UserRecipes; await RefreshData(_currentRecipes); }); MessagingService.Current.Unsubscribe(EventMessages.ReloadPublicRecipesEvent); MessagingService.Current.Subscribe(EventMessages.ReloadPublicRecipesEvent, async(sender) => { _currentRecipes = UserOrPublicOrFavouritesRecipes.PublicResipes; await RefreshData(_currentRecipes); }); MessagingService.Current.Unsubscribe(EventMessages.ReloadFavouritesRecipesEvent); MessagingService.Current.Subscribe(EventMessages.ReloadFavouritesRecipesEvent, async(sender) => { _currentRecipes = UserOrPublicOrFavouritesRecipes.FavouritesRecipes; await RefreshData(_currentRecipes); }); MessagingService.Current.Unsubscribe(EventMessages.LogOffEvent); MessagingService.Current.Subscribe(EventMessages.LogOffEvent, (sender) => { LogOffUser(); }); }
public RecipePreviewViewModel(IRecipesEndPointAPI recipesEndPointAPI, IMapper mapper, ILoggedUser loggedUser, IAPIHelper aPIHelper) { EditCommand = new Command(() => Edit()); DeleteCommand = new Command(async() => await Delete()); FavouriteCommand = new Command(async() => await AddOrDeleteFavourites()); _recipesEndPointAPI = recipesEndPointAPI; _mapper = mapper; _loggedUser = loggedUser; _aPIHelper = aPIHelper; CanEdit = false; MessagingService.Current.Unsubscribe <RecipeAndTitlePage>(EventMessages.RecipesPreviewEvent); MessagingService.Current.Subscribe <RecipeAndTitlePage>(EventMessages.RecipesPreviewEvent, async(sender, arg) => { if (arg.Title == "Moje przepisy") { lastVised = UserOrPublicOrFavouritesRecipes.UserRecipes; } else if (arg.Title == "Odkrywaj przepisy") { lastVised = UserOrPublicOrFavouritesRecipes.PublicResipes; } else if (arg.Title == "Ulubione przepisy") { lastVised = UserOrPublicOrFavouritesRecipes.FavouritesRecipes; } RecipeModel recipeModel = _mapper.Map <RecipeModel>(arg.RecipeModelDisplay); currentRecipe = recipeModel; Title = arg.RecipeModelDisplay.Name; _recipeId = currentRecipe.RecipeId; RecipeName = currentRecipe.Name; RecipeIngredients = (currentRecipe.Ingredients).ToList(); RecipeInstructions = currentRecipe.Instruction; ImagePath = currentRecipe.ImagePath; if (!currentRecipe.IsPublic || currentRecipe.UserName == _loggedUser.UserName) { CanEdit = true; CanAddDeleteFavourites = false; } else { CanEdit = false; UserName = "******" + currentRecipe.UserName; CanAddDeleteFavourites = true; if (await AlreadyFavourites()) { _AddOrdDeleteFavourites = AddOrdDeleteFromFavourites.Delete; FavouritesImage = ImageConstants.StarFull; } else { _AddOrdDeleteFavourites = AddOrdDeleteFromFavourites.Add; FavouritesImage = ImageConstants.StarEmpty; } } }); }