public ActionResult Create([Bind(Include = "Id,NameCategory,Comment")] MenuCategory menuCategory, HttpPostedFileBase uploadedFile) { if (ModelState.IsValid) { string directory = Server.MapPath(Url.Content("~/Content/Images")); menuCategory.Photo = ImageFiles.AddFile(directory, uploadedFile); menuCategoryRepository.Add(menuCategory); return(RedirectToAction("Index")); } return(View(menuCategory)); }
public ActionResult Create([Bind(Include = "Id,NameDish,CompositionDish,Weight,Photo,Price,MenuCategoryId")] Dish dish, HttpPostedFileBase uploadedFile) { if (ModelState.IsValid) { string directory = Server.MapPath(Url.Content("~/Content/Images")); dish.Photo = ImageFiles.AddFile(directory, uploadedFile); dishRepository.Add(dish); return(RedirectToAction("Index")); } var menuCategories = menuCategoryRepository.MenuCategories.ToList(); ViewBag.MenuCategoryId = new SelectList(menuCategories, "Id", "NameCategory", dish.MenuCategoryId); return(View(dish)); }