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("Ошибка при создании");
            }
        }
Beispiel #2
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("Ошибка при сохранении");
            }
        }