public ActionResult CreateMenuItem(MenuItem menuItem) { if (ModelState.IsValid) { if (menuItem.ImageFile != null) { //Add image logic string fileName = Path.GetFileNameWithoutExtension(menuItem.ImageFile.FileName); string extension = Path.GetExtension(menuItem.ImageFile.FileName); //add date time now to make unique names always fileName = DateTime.Now.ToString("yymmssfff") + extension; menuItem.ImagePath = "~/Images/" + fileName; fileName = Path.Combine(Server.MapPath("~/Images/"), fileName); //save in folder images menuItem.ImageFile.SaveAs(fileName); } _menuItemService.CreateMenuItem(menuItem); ModelState.Clear(); return(RedirectToAction("Details", "MenuItems", new { id = menuItem.MenuItemId })); } var cuisines = _cuisineService.GetCuisines(); var restaurants = _restaurantService.GetRestaurants(); ViewBag.CuisineId = new SelectList(cuisines, "CuisineId", "CuisineName", menuItem.CuisineId); ViewBag.RestaurantId = new SelectList(restaurants, "RestaurantId", "RestaurantName", menuItem.RestaurantId); return(View(menuItem)); }
public JsonResult Create(MenuItemDetailView vm) { CreateMenuItemRequest request = new CreateMenuItemRequest(); request.MenuItemName = vm.MenuItemName; request.ParentId = vm.ParentId; request.MenuItemUrl = vm.MenuItemUrl; CreateMenuItemResponse response = _menuItemService.CreateMenuItem(request); return(Json(response)); }
public async Task <ShowMenuItemViewModel> Create(CreateMenuItemViewModel createMenuItemViewModel) { var createMenuItemDto = _mapper.Map <MenuItemDto>(createMenuItemViewModel); var createdDto = await _menuItemService.CreateMenuItem(createMenuItemDto); _unitOfWork.Complete(); var showMenuItemViewModel = _mapper.Map <ShowMenuItemViewModel>(createdDto); return(showMenuItemViewModel); }
public IActionResult Create(MenuItem menuItem) { if (ModelState.IsValid) { menuItemService.CreateMenuItem(menuItem); menuItemService.SaveMenuItem(); return(RedirectToAction("Index", "MenuItem")); } ViewBag.ParentMenuItemId = new SelectList(menuItemService.GetMenuItems(), "Id", "Name", menuItem.ParentMenuItemId); ViewBag.MenuId = new SelectList(menuService.GetMenus(), "Id", "Name", menuItem.MenuId); return(View(menuItem)); }
public MenuItem CreateMenuItem(MenuItem menuItem) { _menuItemService.CreateMenuItem(menuItem); return(menuItem); }