コード例 #1
0
        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));
        }
コード例 #2
0
        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));
        }
コード例 #3
0
        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);
        }
コード例 #4
0
ファイル: MenuItemController.cs プロジェクト: ygmrklc/CmsCore
 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));
 }
コード例 #5
0
 public MenuItem CreateMenuItem(MenuItem menuItem)
 {
     _menuItemService.CreateMenuItem(menuItem);
     return(menuItem);
 }