Ejemplo n.º 1
0
        public async Task AddOrDeleteFavourites()
        {
            try
            {
                if (_AddOrdDeleteFavourites == AddOrdDeleteFromFavourites.Add)
                {
                    _loggedUser.FavouriteRecipes.Add(_recipeId.ToString());
                }
                else
                {
                    _loggedUser.FavouriteRecipes.Remove(_recipeId.ToString());
                }

                LoggedUser loggedUser = new LoggedUser
                {
                    Id               = _loggedUser.Id,
                    Email            = _loggedUser.Email,
                    UserName         = _loggedUser.UserName,
                    FavouriteRecipes = _loggedUser.FavouriteRecipes
                };

                var result = await _aPIHelper.EditUser(loggedUser);

                if (result)
                {
                    if (await AlreadyFavourites())
                    {
                        _AddOrdDeleteFavourites = AddOrdDeleteFromFavourites.Delete;
                        FavouritesImage         = ImageConstants.StarFull;
                    }
                    else
                    {
                        _AddOrdDeleteFavourites = AddOrdDeleteFromFavourites.Add;
                        FavouritesImage         = ImageConstants.StarEmpty;
                    }

                    if (lastVised == UserOrPublicOrFavouritesRecipes.PublicResipes)
                    {
                        MessagingService.Current.SendMessage(EventMessages.ReloadPublicRecipesEvent);
                    }
                    else if (lastVised == UserOrPublicOrFavouritesRecipes.FavouritesRecipes)
                    {
                        MessagingService.Current.SendMessage(EventMessages.ReloadFavouritesRecipesEvent);
                    }
                }

                //_reloadNeeded = true;

                //await Back();
            }
            catch (Exception ex)
            {
                // _logger.Error("Got exception", ex);
                await Application.Current.MainPage.DisplayAlert("Błąd", ex.Message, "Ok");
            }
        }
Ejemplo n.º 2
0
        public async Task AddOrDeleteFavourites()
        {
            try
            {
                if (_AddOrdDeleteFavourites == AddOrdDeleteFromFavourites.Add)
                {
                    _loggedUser.FavouriteRecipes.Add(_recipeId.ToString());
                }
                else
                {
                    _loggedUser.FavouriteRecipes.Remove(_recipeId.ToString());
                }

                LoggedUser loggedUser = new LoggedUser
                {
                    Id               = _loggedUser.Id,
                    Email            = _loggedUser.Email,
                    UserName         = _loggedUser.UserName,
                    FavouriteRecipes = _loggedUser.FavouriteRecipes
                };

                var result = await _aPIHelper.EditUser(loggedUser);

                _reloadNeeded = true;

                if (AlreadyFavourites())
                {
                    _AddOrdDeleteFavourites = AddOrdDeleteFromFavourites.Delete;
                    FavouritesImage         = ImageConstants.StarFull;
                }
                else
                {
                    _AddOrdDeleteFavourites = AddOrdDeleteFromFavourites.Add;
                    FavouritesImage         = ImageConstants.StarEmpty;
                }
            }
            catch (Exception ex)
            {
                _logger.Error("Got exception", ex);
                MessageBox.Show(ex.Message, ex.GetType().ToString());
            }
        }