Esempio n. 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Receipe"/> class.
 /// </summary>
 /// <param name="title">The title.</param>
 /// <param name="author">The author.</param>
 /// <param name="publicationDate">The publication date.</param>
 /// <param name="dishType">Type of the dish.</param>
 /// <param name="rating">The rating.</param>
 /// <param name="difficulty">The difficulty.</param>
 /// <param name="cost">The cost.</param>
 /// <param name="vegetarian">if set to <c>true</c> [vegetarian].</param>
 /// <param name="withAlcohol">if set to <c>true</c> [with alcohol].</param>
 /// <param name="planEntry">The plan entry.</param>
 public Receipe(String title, String author, DateTime publicationDate, DishType dishType, int rating, int difficulty, int cost, bool vegetarian, bool withAlcohol, PlanningEntry planEntry)
 {
     this.Title           = title;
     this.Author          = author;
     this.PublicationDate = publicationDate;
     this.DishType        = dishType;
     this.Rating          = new Rating(rating);
     this.Difficulty      = new Difficulty(difficulty);
     this.Cost            = new Cost(cost);
     this.Vegetarian      = vegetarian;
     this.WithAlcohol     = withAlcohol;
     this.PlanningEntry   = planEntry;
     this.ingredients     = new List <Ingredient>();
 }
Esempio n. 2
0
        /// <summary>
        /// Gets an instance of the class, with the given name.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <returns></returns>
        public static DishType GetInstance(String name)
        {
            DishType instance;

            if (instances.ContainsKey(name))
            {
                instance = instances[name];
            }
            else
            {
                instance = new DishType(name);
                instances.Add(name, instance);
            }

            return(instance);
        }
Esempio n. 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Receipe"/> class.
        /// </summary>
        /// <param name="jsonString">The json string.</param>
        public Receipe(String jsonString)
        {
            JsonObject jsonObject = JsonObject.Parse(jsonString);

            this.Id              = (int)jsonObject.GetNamedNumber("Id");
            this.Title           = jsonObject.GetNamedString("Title");
            this.Author          = jsonObject.GetNamedString("Author");
            this.PublicationDate = Convert.ToDateTime(jsonObject.GetNamedString("PublicationDate"));
            this.DishType        = DishType.GetInstance(jsonObject.GetNamedObject("DishType").GetNamedString("Name"));
            this.Rating          = new Rating(jsonObject.GetNamedObject("Rating").Stringify());
            this.Difficulty      = new Difficulty(jsonObject.GetNamedObject("Difficulty").Stringify());
            this.Cost            = new Cost(jsonObject.GetNamedObject("Cost").Stringify());
            this.Vegetarian      = jsonObject.GetNamedBoolean("Vegetarian");
            this.HtmlReceipe     = jsonObject.GetNamedString("HtmlReceipe");
            try
            {
                if (jsonObject.GetNamedString("ToDoInstructions") != null)
                {
                    this.ToDoInstructions = jsonObject.GetNamedString("ToDoInstructions");
                }
            }
            catch
            {
            }
            this.WithAlcohol = jsonObject.GetNamedBoolean("WithAlcohol");
            this.Image       = jsonObject.GetNamedString("Image");
            this.Description = jsonObject.GetNamedString("Description");

            this.ingredients = new List <Ingredient>();

            JsonArray ingredientsJson = jsonObject.GetNamedArray("Ingredients");

            foreach (var ingredientObject in ingredientsJson)
            {
                Ingredient ingredient = new Ingredient(JsonObject.Parse(ingredientObject.Stringify()));
                ingredients.Add(ingredient);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Gets the receipe from json item.
        /// </summary>
        /// <param name="item">The item.</param>
        /// <returns></returns>
        private Receipe getReceipeFromJSONItem(JsonObject item)
        {
            Receipe receipe = new Receipe();

            foreach (var property in item)
            {
                if (property.Value.Stringify() != "null")
                {
                    switch (property.Key)
                    {
                    case "author":
                        receipe.Author = property.Value.GetString();
                        break;

                    case "cost":
                        receipe.Cost = new Cost((int)property.Value.GetNumber());
                        break;

                    case "difficulty":
                        receipe.Difficulty = new Difficulty((int)property.Value.GetNumber());
                        break;

                    case "dishType":
                        JsonObject dishType = property.Value.GetObject();
                        foreach (var dishTypeProperty in dishType)
                        {
                            if (dishTypeProperty.Key == "label")
                            {
                                receipe.DishType = DishType.GetInstance(dishTypeProperty.Value.GetString());
                            }
                        }
                        break;

                    case "id":
                        receipe.Id = (int)property.Value.GetNumber();
                        break;

                    case "isVegetarian":
                        receipe.Vegetarian = property.Value.GetBoolean();
                        break;

                    case "published":
                        receipe.PublicationDate = getDateTimeFromString(property.Value.GetString());
                        break;

                    case "rating":
                        receipe.Rating = new Rating((int)property.Value.GetNumber());
                        break;

                    case "title":
                        receipe.Title = property.Value.GetString();
                        break;

                    case "withAlcohol":
                        receipe.WithAlcohol = property.Value.GetBoolean();
                        break;

                    case "pictures":
                        var    picturesArray = property.Value.GetArray();
                        string found         = "";
                        if (picturesArray != null)
                        {
                            var pictureObject = picturesArray[1];
                            foreach (var picture in pictureObject.GetObject())
                            {
                                if (picture.Key == "url")
                                {
                                    found = picture.Value.GetString();
                                }
                            }
                        }
                        receipe.Image = found;
                        break;
                    }
                }
            }

            return(receipe);
        }
Esempio n. 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Receipe"/> class.
 /// </summary>
 /// <param name="title">The title.</param>
 /// <param name="author">The author.</param>
 /// <param name="publicationDate">The publication date.</param>
 /// <param name="dishType">Type of the dish.</param>
 /// <param name="rating">The rating.</param>
 /// <param name="difficulty">The difficulty.</param>
 /// <param name="cost">The cost.</param>
 /// <param name="vegetarian">if set to <c>true</c> [vegetarian].</param>
 /// <param name="withAlcohol">if set to <c>true</c> [with alcohol].</param>
 /// <param name="image">The image.</param>
 public Receipe(String title, String author, DateTime publicationDate, DishType dishType, int rating, int difficulty, int cost, bool vegetarian, bool withAlcohol, string image) :
     this(title, author, publicationDate, dishType, rating, difficulty, cost, vegetarian, withAlcohol)
 {
     this.Image = image;
 }