コード例 #1
0
        public bool Deserialize()
        {
            bool success = false;

            if (FileStream != null)
            {
                try
                {
                    ECurrent = (ERecipe)BFormatter.Deserialize(FileStream);

                    success = true;
                }
                catch (SerializationException exception)
                {
                    Error = "Invalid file contents";
                }
                catch (Exception exception)
                {
                    Error = exception.ToString();
                }
            }
            else
            {
                Error = "No open filestream";
            }


            return(success);
        }
コード例 #2
0
        public ERecipe ConvertRecipe(Recipe recipe)
        {
            ERecipe converted = new ERecipe()
            {
                Id         = recipe.Id,
                Title      = recipe.Title,
                Time       = recipe.Time,
                Cost       = recipe.Cost,
                Servings   = recipe.Servings,
                CategoryId = recipe.CategoryId,
                Category   = new ECategory()
                {
                    Id   = recipe.Category.Id,
                    Name = recipe.Category.Name
                }
            };

            List <ERecipeIngredient> recipeIngredients = new List <ERecipeIngredient>();

            foreach (RecipeIngredient item in recipe.RecipeIngredients)
            {
                recipeIngredients.Add(new ERecipeIngredient()
                {
                    Id         = item.Id,
                    Ingredient = new EIngredient()
                    {
                        Id   = item.Ingredient.Id,
                        Name = item.Ingredient.Name
                    },
                    Quantity     = item.Quantity,
                    RecipeID     = item.RecipeID,
                    IngredientID = item.IngredientID
                });
            }

            converted.RecipeIngredients = recipeIngredients;

            List <EStep> steps = new List <EStep>();

            foreach (Step item in recipe.Steps)
            {
                steps.Add(new EStep()
                {
                    Id       = item.Id,
                    Content  = item.Content,
                    Order    = item.Order,
                    RecipeID = item.RecipeID
                });
            }

            converted.Steps = steps;

            return(converted);
        }
コード例 #3
0
        public bool Convert()
        {
            bool success = false;

            if (FileStream != null && Current != null)
            {
                ECurrent = ConvertRecipe(Current);
            }
            else
            {
                Error = "Recipe or filestream not set";
            }

            return(success);
        }
コード例 #4
0
        public ViewERecipe(ERecipe recipe)
        {
            DataContext = recipe;

            InitializeComponent();
        }