Exemplo 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");
            }
        }
Exemplo n.º 2
0
        public async Task HandleAsync(SendRecipe message, CancellationToken cancellationToken)
        {
            try
            {
                backTo = message.BackTo;

                currentRecipe = message.RecipeModel;

                _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;
                    DisplayUserName        = false;
                    CanAddDeleteFavourites = false;
                }
                else
                {
                    CanEdit                = false;
                    DisplayUserName        = true;
                    UserName               = "******" + currentRecipe.UserName;
                    CanAddDeleteFavourites = true;

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

                await Task.CompletedTask;
            }
            catch (Exception ex)
            {
                _logger.Error("Got exception", ex);
            }
        }
Exemplo n.º 3
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());
            }
        }
Exemplo n.º 4
0
        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;
                    }
                }
            });
        }