Exemplo n.º 1
0
        private void RunFavoriteCommand(object obj)
        {
            //var userid = DependencyService.Get<IFacebook>().UserId;
            //await RamseyConnection.SaveFavoriteAsync(recipeMeta.RecipeID, userid);

            if (!loadedRecipe)
            {
                Analytics.TrackEvent("TriedChangingFavoriteBeforeRecipeLoaded", new Dictionary <string, string> {
                    { "loadedRecipe", loadedRecipe.ToString() }
                });
                return;
            }

            IsFavorite = !IsFavorite;

            Analytics.TrackEvent("changeFavorite", new Dictionary <string, string> {
                { "IsFavorite", IsFavorite.ToString() }
            });

            OnPropertyChanged(nameof(IsFavorite));

            try
            {
                //Save or unsave recipe
                var savedRecipes = User.User.SavedRecipes;
                // save
                if (IsFavorite && !savedRecipes.Any(p => p.Name == recipe.Name))
                {
                    savedRecipes.Insert(0, recipe);
                    User.User.SavedRecipes = savedRecipes;
                }
                // unsave
                else if (!IsFavorite && savedRecipes.Any(p => p.Name == recipe.Name))
                {
                    int toRemoveIndex = -1;
                    for (int i = 0; i < savedRecipes.Count; i++)
                    {
                        if (recipe.RecipeID == savedRecipes[i].RecipeID)
                        {
                            toRemoveIndex = i;
                            break;
                        }
                    }
                    if (toRemoveIndex != -1)
                    {
                        savedRecipes.RemoveAt(toRemoveIndex);
                        User.User.SavedRecipes = savedRecipes;
                    }
                }
            }
            catch (Exception ex) { Crashes.TrackError(ex); }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns a <see cref="System.String"/> that represents the current <see cref="TuxedoBerries.ScenePanel.SceneEntity"/>.
        /// </summary>
        /// <returns>A <see cref="System.String"/> that represents the current <see cref="TuxedoBerries.ScenePanel.SceneEntity"/>.</returns>
        public override string ToString()
        {
            var builder = new StringBuilder();

            builder.Append("{");
            // Name
            builder.Append("\"name\":");
            builder.Append("\"");
            builder.Append(Name);
            builder.Append("\",");
            // Full Path
            builder.Append("\"full_path\":");
            builder.Append("\"");
            builder.Append(FullPath);
            builder.Append("\",");
            // GUID
            builder.Append("\"guid\":");
            builder.Append("\"");
            builder.Append(GUID);
            builder.Append("\",");
            // SnapshotPath
            builder.Append("\"screenshot_path\":");
            builder.Append("\"");
            builder.Append(ScreenshotPath);
            builder.Append("\",");
            // IsFavorite
            builder.Append("\"is_favorite\":");
            builder.Append(IsFavorite.ToString().ToLower());
            builder.Append(",");
            // InBuild
            builder.Append("\"in_build\":");
            builder.Append(InBuild.ToString().ToLower());
            builder.Append(",");
            // IsEnabled
            builder.Append("\"is_enabled\":");
            builder.Append(IsEnabled.ToString().ToLower());
            builder.Append(",");
            // BuildIndex
            builder.Append("\"build_index\":");
            builder.Append(BuildIndex);

            builder.Append("}");
            return(builder.ToString());
        }