Beispiel #1
0
        public async Task <IActionResult> AddPizza(AddPizzaModel model)
        {
            byte[] imageData = null;
            // считываем переданный файл в массив байтов
            using (var binaryReader = new BinaryReader(model.Img.OpenReadStream()))
            {
                imageData = binaryReader.ReadBytes((int)model.Img.Length);
            }
            db.Pizza.Add(new Pizza {
                Name = model.Name, Img = imageData, Description = model.Description, Price = model.Price, Category = model.Category, Weigth = model.Weight
            });
            await db.SaveChangesAsync();

            return(RedirectToAction("Index", "Home"));
        }
        public ActionResult AddPizza(AddPizzaModel model)
        {
            var ingredients = HttpContext.Request.Form.Get("Ingredients").Split(',').Select(int.Parse);

            foreach (var ingredient in ingredients)
            {
                model.Ingredients.Add(new PizzaIngredient
                {
                    IngredientId = ingredient
                });
            }

            _pizzaRepository.Add(model.Name, model.Size, model.Thickness, model.Ingredients);
            return(RedirectToAction("Menu", "List"));
        }