Пример #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
        /// <summary>
        /// Получение списка локаций рецепта
        /// </summary>
        /// <param name="recipeId">Id рецепта</param>
        /// <returns></returns>
        public RecipeLocationDTO GetLocations(int recipeId)
        {
            var result  = new RecipeLocationDTO();
            Uri url     = new Uri($"{this.url}/recipe/locations/{recipeId}");
            var request = WebRequest.Create(url);

            request.Method = "Get";
            var response = request.GetResponse();

            using (var stream = new StreamReader(response.GetResponseStream()))
            {
                var json = stream.ReadToEnd();
                result = JsonConvert.DeserializeObject <RecipeLocationDTO>(json);
            }
            return(result);
        }
Пример #3
0
        /// <summary>
        /// Обновление локаций рецепта
        /// </summary>
        /// <param name="model">Модель</param>
        /// <returns></returns>
        public bool UpdateLocations(RecipeLocationDTO model)
        {
            var json    = JsonConvert.SerializeObject(model);
            Uri url     = new Uri($"{this.url}/recipe/locations");
            var request = (HttpWebRequest)WebRequest.Create(url);

            request.Method      = "Post";
            request.ContentType = "application/json";
            using (var stream = new StreamWriter(request.GetRequestStream()))
            {
                stream.Write(json);
                stream.Close();
            }
            var response = (HttpWebResponse)request.GetResponse();

            return(response.StatusCode == HttpStatusCode.OK ? true : false);
        }
Пример #4
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("Ошибка при сохранении");
            }
        }