Пример #1
0
        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)));
        }
Пример #2
0
        public IActionResult CreateMenuItem(MenuItemViewModel model)
        {
            var translateClient = new GoogleTranslateClient(_googleTranslateConfig);
            var menuItem        = new MenuItem
            {
                Name = new LocalizationSet
                {
                    Localizations = new List <Localization>
                    {
                        Heplers.Localization(translateClient.TranslateToRussian(model.Name), Culture.RuCode),
                        Heplers.Localization(translateClient.TranslateToEnglish(model.Name), Culture.EnCode),
                        Heplers.Localization(translateClient.TranslateToKorean(model.Name), Culture.KoCode)
                    }
                },
                Order      = model.Order,
                MenuId     = model.MenuId,
                CustomUrl  = model.CustomUrl,
                Action     = model.Action,
                Controller = model.Controller,
                IsHidden   = model.IsHidden,
                PageId     = model.PageId
            };

            _menuItemService.AddMenuItem(menuItem);

            return(RedirectToAction("MenuItems", new { Id = model.MenuId }));
        }
Пример #3
0
        public ActionResult AddOrUpdate(MenuItemPostViewModel entity)
        {
            SetAddOrUpdateViewBags(entity.Id);

            if (ModelState.IsValid)
            {
                if (entity.Id.HasValue)
                {
                    TempData["result"] = menuItemService.UpdateMenuItem(entity);
                }
                else
                {
                    TempData["result"] = menuItemService.AddMenuItem(entity);
                }
            }

            return(View());
        }