コード例 #1
0
        private void Save()
        {
            var recipe = new RecipeDTO();

            recipeApi          = new RecipeAPI();
            recipe.Name        = this.name;
            recipe.Description = this.description;
            recipe.Products    = ProductsRecipe.Select(x => new ProductRecipeDTO()
            {
                ProductId = x.ProductId,
                Value     = x.Value
            }).ToList();
            var newRecipe      = recipeApi.Create(recipe);
            var recipeLocation = new RecipeLocationDTO();

            recipeLocation.Id        = newRecipe.Id;
            recipeLocation.Locations = LocationsRecipe.Select(x => new LocationDTO()
            {
                Id = x.Id
            }).ToList();
            var flagResult = recipeApi.UpdateLocations(recipeLocation);

            if (flagResult)
            {
                MessageBox.Show("Рецепт создан");
            }
            if (!flagResult)
            {
                MessageBox.Show("Ошибка при создании");
            }
        }
コード例 #2
0
        public ActionResult Search(FormCollection col)
        {
            SearchItems searchItems = default(SearchItems);

            // added this items to the model in a struct so we can continue using same search items
            // ternary : if hidden element is null, use original search page element, else use hidden element

            searchItems.query               = col["hquery"] == null ? col["SearchQuery"] : col["hquery"];
            searchItems.cuisine             = col["hcuisine"] == null ? col["Cuisine"] : col["hcuisine"];
            searchItems.ingredients         = col["hingredients"] == null ? col["Ingredients"] : col["hingredients"];
            searchItems.diets               = col["hdiets"] == null ? col["Diets"] : col["hdiets"];
            searchItems.excludedIngredients = col["hexcludedIngredients"] == null ? col["ExcludedIngredients"] : col["hexcludedIngredients"];
            searchItems.intolerances        = col["hintolerances"] == null ? col["Intolerances"] : col["hintolerances"];
            searchItems.type  = col["htype"] == null ? col["Type"] : col["htype"];
            searchItems.index = col["hindex"] == null ? 0 : Convert.ToInt32(col["hindex"]) + 1;

            // update to search model when that is created
            Models.HomeContent h = new Models.HomeContent
            {
                searchItems = searchItems,
                // get recipes to display
                SearchResults = RecipeAPI.RecipeSearch(searchItems.query, searchItems.cuisine, searchItems.ingredients,
                                                       searchItems.diets, searchItems.excludedIngredients, searchItems.intolerances, searchItems.type, searchItems.index)

                                // get the user object when we set up users
            };

            return(View(h));
        }
コード例 #3
0
        public ActionResult Index( )
        {
            Models.HomeContent h = new Models.HomeContent
            {
                // get recipes to display
                RecipesToDisplay = RecipeAPI.Get5RandomAPIRecipes( )

                                   // get the user object when we set up users
            };

            return(View(h));
        }
コード例 #4
0
        public ActionResult Recipe(  )
        {
            // update to search model when that is created
            Models.HomeContent h = new Models.HomeContent
            {
                // get recipes to display
                SingleRecipe = RecipeAPI.GetRecipeById(Convert.ToString(RouteData.Values["id"]))

                               // get the user object when we set up users
            };

            return(View(h));
        }
コード例 #5
0
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }

            app.UseRouting();

            app.UseEndpoints(endpoints =>
            {
                CookAPI.MapAPIEndpoints(endpoints);
                RecipeAPI.MapAPIEndpoints(endpoints);
                IngredientAPI.MapAPIEndpoints(endpoints);
                TagAPI.MapAPIEndpoints(endpoints);
                IngredientTagAPI.MapAPIEndpoints(endpoints);
                ShoppingListAPI.MapAPIEndpoints(endpoints);
                MealPlanAPI.MapAPIEndpoints(endpoints);
            });
        }
コード例 #6
0
        private void PopulateRecipes()
        {
            //First check RecipeAPI for recipe
            //Check if its not a promotion Item and check mystic forge
            //Get Item object and search for recipe in item

            RecipeIDs = new List <int>(RecipeAPI.RecipesForItem(ItemID));
            if (RecipeIDs != null && RecipeIDs.Count > 0)
            {
                var test = Recipe; //Cheaty way to load recipe for debugging purpose
            }
            else if ((RecipeIDs == null || RecipeIDs.Count <= 0) && !ItemAPI.IsPromotionItem(ItemID))
            {
                List <Recipe> mysticForgeRecipes = RecipeAPI.GetMysticForgeRecipe(ItemID);
                if (mysticForgeRecipes.Count <= 0)
                {
                    return;
                }

                foreach (Recipe recipe in mysticForgeRecipes)
                {
                    RecipeIDs.Add(recipe.ID);
                }
                Recipe = mysticForgeRecipes[0];
            }
            else
            {
                if (Item.Details != null && Item.Details.RecipeID != 0)
                {
                    Recipe = RecipeAPI.GetRecipe(Item.Details.RecipeID);
                    if (Recipe != null)
                    {
                        RecipeIDs = new List <int>()
                        {
                            Recipe.ID
                        }
                    }
                    ;
                }
            }
        }
コード例 #7
0
        public RecipeDetailViewModel(int recipeId)
        {
            recipeApi = new RecipeAPI();
            var recipe = recipeApi.Get(recipeId);

            this.recipeId    = recipe.Id;
            this.Name        = recipe.Name;
            this.Description = recipe.Description;
            var products = recipe.Products.Select(x => new ProductRecipe()
            {
                ProductName = x.ProductName,
                Value       = x.Value
            });

            Products = new ObservableCollection <ProductRecipe>(products);
            var recipeLocation = recipeApi.GetLocations(recipeId);
            var locations      = recipeLocation.Locations.Select(x => new Model.Location()
            {
                Name = x.Name
            });

            Locations   = new ObservableCollection <Model.Location>(locations);
            EditCommand = new Command(Edit);
        }
コード例 #8
0
ファイル: RecipeViewModel.cs プロジェクト: megaded/Restoran
        public RecipeViewModel()
        {
            recipeAPI = new RecipeAPI();
            var recipes = recipeAPI.GetAll().Select(x => new Model.Recipe()
            {
                Id          = x.Id,
                Name        = x.Name,
                Description = x.Description,
                Detail      = new Command((() =>
                {
                    this.Detail(x.Id);
                })),
                Edit = new Command((() =>
                {
                    this.Edit(x.Id);
                })),
                Delete = new Command((() =>
                {
                    this.Delete();
                }))
            });

            Recipes = new ObservableCollection <Model.Recipe>(recipes);
        }
コード例 #9
0
        public RecipeEditViewModel(int recipeId)
        {
            this.recipeId = recipeId;
            recipeApi     = new RecipeAPI();
            var recipeProduct = recipeApi.Get(this.recipeId);

            this.name        = recipeProduct.Name;
            this.description = recipeProduct.Description;
            SaveCommand      = new Command(Save);

            #region Продукты

            var productsRecipe = recipeProduct.Products.Select(x => new Model.ProductRecipe()
            {
                ProductId     = x.ProductId,
                ProductName   = x.ProductName,
                Value         = x.Value,
                AddCommand    = new Command((() => AddProduct(x.ProductId))),
                RemoveCommand = new Command((() => RemoveProduct(x.ProductId)))
            });
            ProductsRecipe = new ObservableCollection <ProductRecipe>(productsRecipe);

            var productsApi = new ProductsAPI();
            var products    = productsApi.GetAll().Select(x => new ProductRecipe()
            {
                ProductId     = x.Id,
                ProductName   = x.Name,
                Value         = 0,
                AddCommand    = new Command((() => AddProduct(x.Id))),
                RemoveCommand = new Command((() => RemoveProduct(x.Id)))
            });

            Products = new ObservableCollection <ProductRecipe>();
            foreach (var product in products)
            {
                if (ProductsRecipe.All(p => p.ProductId != product.ProductId))
                {
                    Products.Add(product);
                }
            }
            #endregion

            #region Локации
            var recipeLocations = recipeApi.GetLocations(this.recipeId);
            var locationsRecipe = recipeLocations.Locations.Select(x => new Model.Location()
            {
                Id            = x.Id,
                Name          = x.Name,
                AddCommand    = new Command((() => AddLocation(x.Id))),
                RemoveCommand = new Command((() => RemoveLocation(x.Id)))
            });
            LocationsRecipe = new ObservableCollection <Model.Location>(locationsRecipe);
            var locationApi = new LocationAPI();
            var locations   = locationApi.GetAll().Select(x => new Model.Location()
            {
                Id            = x.Id,
                Name          = x.Name,
                AddCommand    = new Command((() => AddLocation(x.Id))),
                RemoveCommand = new Command((() => RemoveLocation(x.Id)))
            });
            Locations = new ObservableCollection <Model.Location>();
            foreach (var location in locations)
            {
                if (LocationsRecipe.All(l => l.Id != location.Id))
                {
                    Locations.Add(location);
                }
            }
            #endregion
        }