public async Task <IActionResult> CreatePost() { model.MenuItem.SubCategoryId = Convert.ToInt32(Request.Form["SubCategoryId"].ToString()); if (!ModelState.IsValid) { return(View(model)); } if (model.Img != null) { await menuItemService.AddMenuItem(model.MenuItem); model.MenuItem.Image = ProcessUploadedFile(model); } else { await menuItemService.AddMenuItem(model.MenuItem); var menuItemFromDb = await menuItemService.GetMenuItemById(model.MenuItem.Id); string webRootPath = hostEnvironment.WebRootPath; var uploads = Path.Combine(webRootPath, @"images\" + SD.DefaultFoodImage); System.IO.File.Copy(uploads, webRootPath + @"\images\MenuItem\" + model.MenuItem.Id + ".png"); menuItemFromDb.Image = @"\images\MenuItem\" + model.MenuItem.Id + ".png"; } await menuItemService.Commit(); return(RedirectToAction(nameof(Index))); }
public IActionResult Create(MenuItem menuItem) { if (ModelState.IsValid) { _menuItemService.Create(menuItem); _menuItemService.Commit(); return(RedirectToAction("Index")); } ViewBag.Menu = new SelectList(_menuService.GetAll(), "Id", "Name", menuItem.MenuId); return(View(menuItem)); }