예제 #1
0
        private void RemoveProduct(int productId)
        {
            var product = ProductsRecipe.Single(x => x.ProductId == productId);

            ProductsRecipe.Remove(product);
            Products.Add(product);
        }
예제 #2
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("Ошибка при создании");
            }
        }
예제 #3
0
 public void AddRecipe(Recipe recipe, List <Product> products)
 {
     if (context.Recipes.Where(x => x.Name == recipe.Name) == null)
     {
         context.Recipes.Add(recipe);
         foreach (var product in products)
         {
             if (context.Products.Where(x => x.Name == product.Name) == null)
             {
                 context.Products.Add(product);
             }
             else
             {
             }
         }
         context.SaveChanges();
         foreach (var product in products)
         {
             ProductsRecipe productsRecipes = new ProductsRecipe();
             productsRecipes.RecipeId  = recipe.Id;
             productsRecipes.ProductId = product.Id;
             context.ProductsRecipes.Add(productsRecipes);
         }
     }
     else
     {
     }
 }
예제 #4
0
        private void AddProduct(int productId)
        {
            var product = Products.Single(x => x.ProductId == productId);

            if (product != null)
            {
                Products.Remove(product);
                ProductsRecipe.Add(product);
            }
        }
예제 #5
0
        private void Save()
        {
            var modelLocations = new RecipeLocationDTO()
            {
                Id          = this.recipeId,
                Name        = this.name,
                Description = this.description,
                Locations   = LocationsRecipe.Select(x => new LocationDTO()
                {
                    Id = x.Id
                }).ToList()
            };
            var resultFlag = recipeApi.UpdateLocations(modelLocations);

            if (resultFlag)
            {
                var modelProducts = new RecipeDTO()
                {
                    Id          = this.recipeId,
                    Name        = this.name,
                    Description = this.description,
                    Products    = ProductsRecipe.Select(x => new ProductRecipeDTO()
                    {
                        ProductId = x.ProductId,
                        Value     = x.Value
                    }).ToList()
                };
                resultFlag = recipeApi.UpdateProducts(modelProducts);
                if (resultFlag)
                {
                    MessageBox.Show("Успешно сохранено");
                }
                if (!resultFlag)
                {
                    MessageBox.Show("Ошибка при сохранении");
                }
            }
            if (!resultFlag)
            {
                MessageBox.Show("Ошибка при сохранении");
            }
        }