public async Task <IActionResult> Create([Bind("DishId,Name,Price,Image,DishCategoryId")] Dish dish, IFormCollection collection, IFormFile file)
        {
            var filePath = Path.GetTempFileName();

            using (var stream = new FileStream(filePath, FileMode.Create))
            {
                await file.CopyToAsync(stream);
            }
            dish.Image = LoadImage.GetPictureData(filePath);

            List <Ingredient> testList = new List <Ingredient>();

            foreach (var item in collection.Keys.Where(m => m.StartsWith("ingredient-")))
            {
                var listIngredient = _context.Ingredients.FirstOrDefault(d => d.IngredientId == Int32.Parse(item.Remove(0, 11)));
                testList.Add(listIngredient);
                DishIngredient di = new DishIngredient()
                {
                    Dish = dish, Ingredient = listIngredient
                };
                _context.DishIngredients.Add(di);
            }

            if (ModelState.IsValid)
            {
                _context.Add(dish);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["DishCategoryId"] = new SelectList(_context.DishCategories, "DishCategoryId", "Description", dish.DishCategoryId);
            return(View(dish));
        }
Exemplo n.º 2
0
        public Dish CreateNewDish(CreateViewModel createDish)
        {
            var categories = _context.Categories.ToList();
            var newDish    = new Dish
            {
                DishId   = _context.Dishes.Last().DishId + 1,
                Category = new Category
                {
                    CategoryId = createDish.Dish.Category.CategoryId,
                    Name       = categories.FirstOrDefault(c => c.CategoryId == createDish.Dish.Category.CategoryId).Name
                },
                Name    = createDish.Dish.Name,
                Price   = createDish.Dish.Price,
                Picture = createDish.Dish.Picture
            };
            var ingredients = _context.Ingredients.ToList();

            foreach (var dishIngredient in createDish.Ingredients)
            {
                if (dishIngredient.Selected)
                {
                    var newDishIngredient = new DishIngredient
                    {
                        Dish         = newDish,
                        DishId       = newDish.DishId,
                        Ingredient   = ingredients.FirstOrDefault(i => i.IngredientId == int.Parse(dishIngredient.Value)),
                        IngredientId = int.Parse(dishIngredient.Value)
                    };
                    newDish.DishIngredients.Add(newDishIngredient);
                }
            }
            return(newDish);
        }
Exemplo n.º 3
0
        public Dish DishCreator()
        {
            var ingredientTomatoe = new Ingredient {
                Name = "Tomatoe", IngredientPrice = 5
            };
            var ingredientCheese = new Ingredient {
                Name = "Cheese", IngredientPrice = 5
            };

            var pizzaCategory = new Category {
                CategoryId = 1, Name = "Pizza"
            };

            var margeritha = new Dish {
                DishId = 1, Name = "Margeritha", Price = 79, Category = pizzaCategory, CategoryId = pizzaCategory.CategoryId
            };
            var margerithaCheese = new DishIngredient {
                Ingredient = ingredientCheese, Dish = margeritha
            };
            var margerithaTomatoe = new DishIngredient {
                Ingredient = ingredientTomatoe, Dish = margeritha
            };

            margeritha.DishIngredients = new List <DishIngredient> {
                margerithaCheese, margerithaTomatoe
            };

            return(margeritha);
        }
Exemplo n.º 4
0
        public async Task <IActionResult> Create([Bind("Name, Price, DishIngredients, AllIngredients, CategoryId")] CreateEditDishViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                Dish createdDish = new Dish()
                {
                    Name       = viewModel.Name,
                    Price      = viewModel.Price,
                    CategoryId = viewModel.CategoryId
                };
                _context.Add(createdDish);

                List <Ingredient> allIngredients = _context.Ingredients.Where(i => viewModel.AllIngredients.Where(y => y.Checked).Any(x => x.IngredientId == i.IngredientId)).ToList();

                foreach (var ingredient in allIngredients)
                {
                    DishIngredient dishIngredient = new DishIngredient()
                    {
                        Dish       = createdDish,
                        Ingredient = ingredient
                    };
                    _context.DishIngredients.Add(dishIngredient);
                }

                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View("index", "home"));
        }
        public async Task <DishIngredient> Create(DishIngredient ingredientDish)
        {
            _context.DishIngredient.Add(ingredientDish);
            await _context.SaveChangesAsync();

            return(ingredientDish);
        }
Exemplo n.º 6
0
        public async Task Replace(string id, ModifyDishDto request)
        {
            Guid.TryParse(id, out Guid dishId);
            var dish = await _unityOfWork.DishesRepository.Get(dishId);

            dish.Name  = request.Name;
            dish.Price = request.Price;
            dish.DishIngredients.Clear();


            foreach (var requestDishIngredient in request.DishIngredients)
            {
                var ingredient = await _unityOfWork.IngredientsRepository.Get(requestDishIngredient.Key);

                var link = new DishIngredient()
                {
                    Dish       = dish,
                    Ingredient = ingredient,
                    Quantity   = requestDishIngredient.Value
                };

                await _unityOfWork.DishIngredientsRepository.Add(link);
            }

            await _unityOfWork.DishesRepository.Update(dish);

            await _unityOfWork.CommitAsync();
        }
Exemplo n.º 7
0
        public Dish GetEditedDish(EditViewModel editDish)
        {
            var dish = _context.Dishes
                       .Include(d => d.DishIngredients)
                       .ThenInclude(di => di.Ingredient)
                       .Include(d => d.Category)
                       .FirstOrDefault(d => d.DishId == editDish.Dish.DishId);

            dish.Name     = editDish.Dish.Name;
            dish.Price    = editDish.Dish.Price;
            dish.Category = _context.Categories.FirstOrDefault(c => c.CategoryId == editDish.Dish.Category.CategoryId);

            var ingredients = _context.Ingredients.ToList();

            foreach (var item in editDish.Ingredients)
            {
                if (item.Selected)
                {
                    var newDishIngredient = new DishIngredient
                    {
                        Dish         = dish,
                        DishId       = dish.DishId,
                        Ingredient   = ingredients.FirstOrDefault(i => i.IngredientId == int.Parse(item.Value)),
                        IngredientId = int.Parse(item.Value)
                    };
                    dish.DishIngredients.Add(newDishIngredient);
                }
            }
            return(dish);
        }
Exemplo n.º 8
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,DishId,IngredientId")] DishIngredient dishIngredient)
        {
            if (id != dishIngredient.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(dishIngredient);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DishIngredientExists(dishIngredient.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction("Index", "DishIngredients", new { id = dishIngredient.DishId, name = _context.Dish.Where(c => c.Id == dishIngredient.DishId).FirstOrDefault().Name }));
            }
            ViewData["DishId"]       = new SelectList(_context.Dish, "Id", "Name", dishIngredient.DishId);
            ViewData["IngredientId"] = new SelectList(_context.Ingredient, "Id", "Name", dishIngredient.IngredientId);
            return(View(dishIngredient));
        }
Exemplo n.º 9
0
        public async Task <ActionResult <DishIngredient> > PostDishIngredient(DishIngredient dishIngredient)
        {
            _context.DishIngredients.Add(dishIngredient);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetDishIngredient", new { id = dishIngredient.Id }, dishIngredient));
        }
Exemplo n.º 10
0
        public Dish GetDish()
        {
            var a = new Ingredient {
                IngredientId = 1, PriceIfExtra = 5, Name = "Morot"
            };
            var b = new Ingredient {
                IngredientId = 2, PriceIfExtra = 5, Name = "Sallad"
            };

            var sallad = new Category {
                CategoryId = 1, Name = "Sallad"
            };

            var dish = new Dish {
                Name = "Cesar sallad", Category = sallad, DishId = 1, Price = 40
            };

            var aDish = new DishIngredient {
                Dish = dish, DishId = dish.DishId, Ingredient = a, IngredientId = a.IngredientId
            };
            var bDish = new DishIngredient {
                Dish = dish, DishId = dish.DishId, Ingredient = b, IngredientId = b.IngredientId
            };
            var list = new List <DishIngredient>();

            list.Add(aDish);
            list.Add(bDish);
            dish.DishIngredients.AddRange(list);
            return(dish);
        }
Exemplo n.º 11
0
        public async Task <IActionResult> PutDishIngredient(int id, DishIngredient dishIngredient)
        {
            if (id != dishIngredient.Id)
            {
                return(BadRequest());
            }

            _context.Entry(dishIngredient).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!DishIngredientExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Exemplo n.º 12
0
        public void TotalPriceForCart()
        {
            var dish = new Dish {
                Name = "Capricciosa", DishId = 1, Price = 80, DishIngredients = new List <DishIngredient>()
            };
            var ingredient1 = new Ingredient {
                Name = "Bacon", IngredientId = 1, Price = 10
            };
            var ingredient2 = new Ingredient {
                Name = "Cheese", IngredientId = 2, Price = 5
            };
            var dishIngredients1 = new DishIngredient {
                DishId = 1, IngredientId = 1, Dish = dish, Ingredient = ingredient1
            };
            var dishIngredients2 = new DishIngredient {
                DishId = 1, IngredientId = 2, Dish = dish, Ingredient = ingredient2
            };

            dish.DishIngredients.Add(dishIngredients1);
            dish.DishIngredients.Add(dishIngredients2);
            var shoppingCart = new ShoppingCart {
                ShoppingCartId = 4, CartItems = new List <CartItem>()
            };
            var cartItems = new CartItem {
                DishId = 1, CartItemId = 1, ShoppingCartId = 4, Quantity = 1, Price = 80, Dish = dish
            };

            shoppingCart.CartItems.Add(cartItems);

            var calculationService = new CartCalculationService();
            var totalAmount        = calculationService.TotalForCart(shoppingCart);

            Assert.Equal(80, totalAmount);
        }
        public async Task AddDish(Dish dish, string ingredients, string picturePath)
        {
            var course = await this.db.Courses.FirstOrDefaultAsync(cid => cid.Id == dish.CourseId);

            var dishIngredients = new List <DishIngredient>();

            if (!string.IsNullOrEmpty(ingredients))
            {
                var rawIngredients = ingredients.Split(',', StringSplitOptions.RemoveEmptyEntries);

                foreach (var ingredient in rawIngredients)
                {
                    var dishIngredient = new DishIngredient()
                    {
                        IngredientId = ingredient,
                        DishId       = dish.Id
                    };

                    dishIngredients.Add(dishIngredient);
                }
            }

            dish.PicturePath = picturePath;
            dish.Course      = course;
            dish.Ingredient  = dishIngredients;

            await this.db.Dishes.AddAsync(dish);

            await this.db.SaveChangesAsync();
        }
        public async Task <IActionResult> Edit(int id, [Bind("DishId,Name,Price,DishCategoryId")] Dish dish, IFormCollection collection, IFormFile file)
        {
            if (file != null)
            {
                var filePath = Path.GetTempFileName();
                using (var stream = new FileStream(filePath, FileMode.Create))
                {
                    await file.CopyToAsync(stream);
                }
                dish.Image = LoadImage.GetPictureData(filePath);
            }
            else
            {
                dish.Image = await _context.Dishes.Where(x => x.DishId == dish.DishId).Select(x => x.Image).FirstOrDefaultAsync();
            }

            _dishService.RemoveIngredients(id);
            List <Ingredient> testList = new List <Ingredient>();

            foreach (var item in collection.Keys.Where(m => m.StartsWith("ingredient-")))
            {
                var listIngredient = _context.Ingredients.FirstOrDefault(d => d.IngredientId == Int32.Parse(item.Remove(0, 11)));
                testList.Add(listIngredient);
                DishIngredient di = new DishIngredient()
                {
                    Dish = dish, Ingredient = listIngredient
                };
                _context.DishIngredients.Add(di);
            }

            if (id != dish.DishId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(dish);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DishExists(dish.DishId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["DishCategoryId"] = new SelectList(_context.DishCategories, "DishCategoryId", "Description", dish.DishCategoryId);
            return(View(dish));
        }
Exemplo n.º 15
0
        public async Task AddIngredientToDish(int dishId, int ingredientId)
        {
            var relation = new DishIngredient {
                DishId = dishId, IngredientId = ingredientId
            };
            await _context.DishIngredients.AddAsync(relation);

            await _context.SaveChangesAsync();
        }
Exemplo n.º 16
0
        public async Task <IActionResult> Create(int dishId, [Bind("Id,DishId,IngredientId")] DishIngredient dishIngredient)
        {
            dishIngredient.DishId = dishId;
            if (ModelState.IsValid)
            {
                _context.Add(dishIngredient);
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", "DishIngredients", new { id = dishId, name = _context.Dish.Where(c => c.Id == dishId).FirstOrDefault().Name }));
            }
            return(View(dishIngredient));
        }
Exemplo n.º 17
0
        public async Task <IActionResult> Edit(int id, [Bind("DishId,Name,Price,CategoryId")] Dish dish, IFormCollection form)
        {
            if (id != dish.DishId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var dishToEdit = await _context.Dishes.
                                     Include(d => d.DishIngredients).
                                     SingleOrDefaultAsync(m => m.DishId == id);

                    dishToEdit.Name       = dish.Name;
                    dishToEdit.Price      = dish.Price;
                    dishToEdit.CategoryId = dish.CategoryId;
                    foreach (var dishIngredient in dishToEdit.DishIngredients)
                    {
                        _context.Remove(dishIngredient);
                    }

                    await _context.SaveChangesAsync();

                    foreach (var ingredient in _ingredientService.GetIngredients())
                    {
                        var dishIngredient = new DishIngredient
                        {
                            Ingredient     = ingredient,
                            Dish           = dish,
                            checkboxAnswer = form.Keys.Any(x => x == $"checkboxes-{ingredient.IngredientId}")
                        };
                        dishToEdit.DishIngredients.Add(dishIngredient);
                    }
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DishExists(dish.DishId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(dish));
        }
Exemplo n.º 18
0
 public void DishIngredientAdd(DishIngredient item)
 {
     try
     {
         this.DishIngredientList.Add(item);
         this.SaveChanges();
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         throw;
     }
 }
Exemplo n.º 19
0
        public static IngredientDTO CreateFromDishIngredientDomain(DishIngredient di)
        {
            if (di == null)
            {
                return(null);
            }

            var ingredient = CreateFromDomain(di.Ingredient);

            ingredient.Amount = di.Amount;

            return(ingredient);
        }
Exemplo n.º 20
0
            public async Task <bool> Handle(Command command, CancellationToken cancellationToken)
            {
                var dishIngredient = new DishIngredient
                {
                    DishId       = command.DishId,
                    IngredientId = command.IngredientId
                };

                _context.DishIngredients.Add(dishIngredient);
                await _context.SaveChangesAsync();

                return(true);
            }
Exemplo n.º 21
0
 public void DishIngredientDelete(DishIngredient item)
 {
     try
     {
         DishIngredientList.Attach(item);
         DishIngredientList.Remove(item);
         this.SaveChanges();
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         throw;
     }
 }
Exemplo n.º 22
0
        public async Task <IResponseDto> Create(CreateDishDto request)
        {
            IDictionary <Guid, IngredientOnStock> usedIngredients = new Dictionary <Guid, IngredientOnStock>();
            bool isAvailable = true;
            var  dishIngredientsEnumerator = request.DishIngredients.GetEnumerator();

            while (dishIngredientsEnumerator.MoveNext() && isAvailable == true)
            {
                double quantity = dishIngredientsEnumerator.Current.Value;

                var usedIngredient = await _unityOfWork.IngredientsRepository.Get(dishIngredientsEnumerator.Current.Key);

                if (usedIngredient == null)
                {
                    return(null);
                }

                usedIngredients.Add(usedIngredient.Id, usedIngredient);
                if (usedIngredient.Quantity < quantity)
                {
                    isAvailable = false;
                }
            }
            dishIngredientsEnumerator.Dispose();

            Dish createdDish = Dish.Create(request.Name, request.Price, isAvailable);
            var  id          = createdDish.Id;
            await _unityOfWork.DishesRepository.Add(createdDish);

            dishIngredientsEnumerator = request.DishIngredients.GetEnumerator();
            while (dishIngredientsEnumerator.MoveNext())
            {
                DishIngredient link = new DishIngredient()
                {
                    Dish       = createdDish,
                    Ingredient = usedIngredients[dishIngredientsEnumerator.Current.Key],
                    Quantity   = dishIngredientsEnumerator.Current.Value
                };
                await _unityOfWork.DishIngredientsRepository.Add(link);

                Console.WriteLine(link);
            }
            dishIngredientsEnumerator.Dispose();

            await _unityOfWork.CommitAsync();

            var dishDto = _mapper.Map <DishDto>(createdDish);

            return(SuccessResponseDto.Create(dishDto));
        }
Exemplo n.º 23
0
        public async Task InsertDishedIntoDb()
        {
            var dishDb = await _dishesRepository.CheckIfExistsItems();

            if (dishDb)
            {
                return;
            }
            var projectRootPath   = _hostingEnvironment.ContentRootPath;
            var fullFileDirectory = Path.Combine(projectRootPath, StaticDocumentsDirectories.JsonFiles);

            if (!Directory.Exists(fullFileDirectory))
            {
                throw new ApplicationException(Errors.DirectoryDoesNotExist);
            }
            var fullFileName = Path.Combine(fullFileDirectory, "dishes-sample-data.json");

            if (!File.Exists(fullFileName))
            {
                throw new ApplicationException(Errors.FileDoesNotExist);
            }
            var jsonString = File.ReadAllText(fullFileName);
            var jsonModel  = JsonConvert.DeserializeObject <List <JsonDishes> >(jsonString);

            foreach (var item in jsonModel)
            {
                var dish = new Dishes
                {
                    Id       = item.id,
                    Name     = item.name,
                    ParentId = item.parentId
                };
                dish.UpdatedOn = dish.UpdatedOn = DateTime.Parse((item.updatedOn).ToString());
                await _dishesRepository.Create(dish);

                foreach (var item2 in item.ingredients)
                {
                    var ingredient = new DishIngredient
                    {
                        DishesId     = dish.Id,
                        Amount       = item2.amount,
                        IngredientId = item2.ingredientId
                    };

                    await _dishesIngredientsRepository.Create(ingredient);
                }
                await _dishesRepository.Save();
            }
        }
Exemplo n.º 24
0
        public async Task <IActionResult> Edit(int id, [Bind("DishId,Name,Price, CategoryId")] Dish dish, IFormCollection form)
        {
            if (id != dish.DishId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    var dishToEdit = _context.Dishes.Include(x => x.DishIngredients).FirstOrDefault(x => x.DishId == id);

                    foreach (var ingre in dishToEdit.DishIngredients)
                    {
                        _context.Remove(ingre);
                    }
                    _context.SaveChanges();

                    foreach (var i in _ingredientService.GetIngredients())
                    {
                        var dishIngredient = new DishIngredient()
                        {
                            Ingredient = i,
                            Dish       = dish,
                            Enabled    = form.Keys.Any(x => x == $"IngredientBox-{i.IngredientId}")
                        };
                        _context.DishIngredients.Add(dishIngredient);
                    }

                    //_context.Update(dish);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!DishExists(dish.DishId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Menu)));
            }
            return(View(dish));
        }
Exemplo n.º 25
0
        public void TotalPriceFor_CartItemIngredients_ForSpecificCartItem()
        {
            var dish = new Dish {
                Name = "Capricciosa", DishId = 1, Price = 80, DishIngredients = new List <DishIngredient>()
            };
            var ingredient1 = new Ingredient {
                Name = "Bacon", IngredientId = 1, Price = 10
            };
            var ingredient2 = new Ingredient {
                Name = "Cheese", IngredientId = 2, Price = 5
            };
            var ingredient3 = new Ingredient {
                Name = "Extra", IngredientId = 3, Price = 15
            };
            var dishIngredients1 = new DishIngredient {
                DishId = 1, IngredientId = 1, Dish = dish, Ingredient = ingredient1
            };
            var dishIngredients2 = new DishIngredient {
                DishId = 1, IngredientId = 2, Dish = dish, Ingredient = ingredient2
            };

            dish.DishIngredients.Add(dishIngredients1);
            dish.DishIngredients.Add(dishIngredients2);
            var cartItem = new CartItem {
                CartItemId = 1, Dish = dish, DishId = 1, CartItemIngredients = new List <CartItemIngredient>()
            };
            var cartItemIngredient1 = new CartItemIngredient {
                CartItemId = 1, CartItem = cartItem, IngredientId = 1, Ingredient = ingredient1
            };
            var cartItemIngredient2 = new CartItemIngredient {
                CartItemId = 2, CartItem = cartItem, IngredientId = 2, Ingredient = ingredient2
            };
            var cartItemIngredient3 = new CartItemIngredient {
                CartItemId = 3, CartItem = cartItem, IngredientId = 3, Ingredient = ingredient3
            };

            cartItem.CartItemIngredients.Add(cartItemIngredient1);
            cartItem.CartItemIngredients.Add(cartItemIngredient2);
            cartItem.CartItemIngredients.Add(cartItemIngredient3);


            var calculationService = new CartCalculationService();
            var totalPrice         = calculationService.TotalPriceForCartItemIngredients(cartItem);

            Assert.Equal(15, totalPrice);
        }
Exemplo n.º 26
0
        public void DishIngredientChange(DishIngredient item)
        {
            try
            {
                var ser = DishIngredientList.Where(x => x.Id == item.Id).First();

                ser.Quantity      = item.Quantity;
                ser.IngredientsId = item.IngredientsId;
                ser.DishId        = item.DishId;
                this.SaveChanges();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
Exemplo n.º 27
0
 public Dish UpdateIngredientsToDish(List <int> newIngredients, List <int> oldIngredients, Dish dish)
 {
     foreach (var number in newIngredients)
     {
         var dishIng = new DishIngredient {
             Ingredient = _context.Ingredients.FirstOrDefault(x => x.IngredientId == number), Dish = dish
         };
         _context.DishIngredients.Add(dishIng);
         _context.SaveChanges();
     }
     foreach (var number in oldIngredients)
     {
         var dishIng = _context.DishIngredients.FirstOrDefault(x => x.IngredientId == number);
         _context.DishIngredients.Remove(dishIng);
     }
     _context.Update(dish);
     _context.SaveChanges();
     return(dish);
 }
Exemplo n.º 28
0
        public async Task <IActionResult> Create([Bind("DishId,Name,Price, CategoryId")] Dish dish, IFormCollection form)
        {
            if (ModelState.IsValid)
            {
                foreach (var ingredient in _ingredientService.GetIngredients())
                {
                    var dishIngredient = new DishIngredient
                    {
                        Ingredient     = ingredient,
                        Dish           = dish,
                        checkboxAnswer = form.Keys.Any(x => x == $"checkboxes-{ingredient.IngredientId}")
                    };
                    _context.DishIngredients.Add(dishIngredient);
                }

                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(dish));
        }
Exemplo n.º 29
0
        private static void addIngredients(NoodleDContext db, Dish dish)
        {
            // добавить ингредиенты
            DishIngredient ingr;

            ingr = new DishIngredient()
            {
                RowGUID = Guid.NewGuid(), Price = 19, DishGUID = dish.RowGUID, RowPosition = 1
            };
            LangStringLib.SetValues(db, ingr.RowGUID, FieldTypeIDEnum.Name, "Двойной соус терияки", "Подвійний соус теріякі", "Double teriyaki sauce");
            db.DishIngredient.Add(ingr);

            ingr = new DishIngredient()
            {
                RowGUID = Guid.NewGuid(), Price = 9, DishGUID = dish.RowGUID, RowPosition = 2
            };
            LangStringLib.SetValues(db, ingr.RowGUID, FieldTypeIDEnum.Name, "Двойная фасоль стручковая", "Подвійна квасоля стручкова", "Double runner beans");
            db.DishIngredient.Add(ingr);

            ingr = new DishIngredient()
            {
                RowGUID = Guid.NewGuid(), Price = 23, DishGUID = dish.RowGUID, RowPosition = 3
            };
            LangStringLib.SetValues(db, ingr.RowGUID, FieldTypeIDEnum.Name, "Двойная курица", "Подвійна курка", "Double chicken");
            db.DishIngredient.Add(ingr);

            ingr = new DishIngredient()
            {
                RowGUID = Guid.NewGuid(), Price = 13, DishGUID = dish.RowGUID, RowPosition = 4
            };
            LangStringLib.SetValues(db, ingr.RowGUID, FieldTypeIDEnum.Name, "Двойной деревестный гриб", "Подвійний дерев'янистий гриб", "Double tree fungus");
            db.DishIngredient.Add(ingr);

            ingr = new DishIngredient()
            {
                RowGUID = Guid.NewGuid(), Price = 18, DishGUID = dish.RowGUID, RowPosition = 5
            };
            LangStringLib.SetValues(db, ingr.RowGUID, FieldTypeIDEnum.Name, "Двойные грибы шампиньоны", "Подвійні гриби печериці", "Double champignons");
            db.DishIngredient.Add(ingr);
        }
Exemplo n.º 30
0
        public async Task <IActionResult> Create([Bind("DishId,Name,Price, CategoryId")] Dish dish, IFormCollection iFormCollection)
        {
            if (ModelState.IsValid)
            {
                foreach (var i in _ingredientService.GetIngredients())
                {
                    var dishIngredient = new DishIngredient()
                    {
                        Ingredient = i,
                        Dish       = dish,
                        Enabled    = iFormCollection.Keys.Any(x => x == $"IngredientBox-{i.IngredientId}")
                    };
                    _context.DishIngredients.Add(dishIngredient);
                }

                // _context.Add(dish);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Menu)));
            }
            return(View(dish));
        }