Exemplo n.º 1
0
        public ActionResult CreateMenu(int categoryId, int?parentId)
        {
            var   vMenu  = new Navigation();
            NavIM newDto = _mapper.Map <NavIM>(vMenu);

            newDto.CategoryId = categoryId;
            newDto.ParentId   = parentId;
            return(PartialView("_MenuCreate", newDto));
        }
Exemplo n.º 2
0
        public async Task <JsonResult> EditMenu(NavIM menu)
        {
            if (ModelState.IsValid)
            {
                // Menu vMenu = _mapper.Map<Menu>(menu);

                var orgNav = await _context.Navigations.FindAsync(menu.Id);

                var im = _mapper.Map(menu, orgNav);


                im.UpdatedBy   = User.Identity.Name;
                im.UpdatedDate = DateTime.Now;

                _context.Entry(im).State = EntityState.Modified;
                await _context.SaveChangesAsync();


                var cacheKey = "NAVIGATION";
                _cache.Invalidate(cacheKey);
                // _menuService.ResetSort(orgMenu.CategoryId);
                //  var menus = _menuService.GetLevelMenusByCategoryId(vMenu.CategoryId);
                AR.Id = im.CategoryId;
                //// using a Model
                //string html = view.Render("Emails/Test", new Product("Apple"));

                //// using a Dictionary<string, object>
                //var viewData = new Dictionary<string, object>();
                //viewData["Name"] = "123456";

                //string html = view.Render("Emails/Test", viewData);
                //AR.Data = await _viewRenderService.RenderToStringAsync("_MenuList", menus);

                var pm = new PageMeta
                {
                    Title       = menu.SEOTitle,
                    Description = menu.SEODescription,
                    Keywords    = menu.SEOKeywords,
                    ModuleType  = (short)ModuleType.MENU,
                    ObjectId    = menu.Url
                };

                await CreatedUpdatedPageMetaAsync(_context, pm);


                AR.SetSuccess("已成功保存菜单");
                return(Json(AR));
            }

            AR.Setfailure("编辑菜单失败");
            return(Json(AR));
        }
Exemplo n.º 3
0
        public async Task <JsonResult> CreateMenu(NavIM menu)
        {
            if (ModelState.IsValid)
            {
                var vMenu = _mapper.Map <Navigation>(menu);
                if (menu.ParentId != null)
                {
                    var parentMenu = await _context.Navigations.FindAsync(vMenu.ParentId.Value);

                    vMenu.LayoutLevel = parentMenu.LayoutLevel + 1;
                }
                else
                {
                    vMenu.LayoutLevel = 0;
                }

                vMenu.CreatedBy   = User.Identity.Name;
                vMenu.CreatedDate = DateTime.Now;

                _context.Add(vMenu);
                await _context.SaveChangesAsync();

                var pm = new PageMeta
                {
                    Title       = menu.SEOTitle,
                    Description = menu.SEODescription,
                    Keywords    = menu.SEOKeywords,
                    ModuleType  = (short)ModuleType.MENU,
                    ObjectId    = vMenu.Url
                };

                await CreatedUpdatedPageMetaAsync(_context, pm);


                //  var menus = _menuService.GetLevelMenusByCategoryId(vMenu.CategoryId);
                AR.Id = menu.CategoryId;
                //AR.Data = ViewComponent("MenuList", new { categoryId = menu.CategoryId });  //await _viewRenderService.RenderToStringAsync("Admin/Menu/_MenuList", menus);
                var cacheKey = "NAVIGATION";
                _cache.Invalidate(cacheKey);

                AR.SetSuccess("已成功新增菜单");
                return(Json(AR));
            }

            AR.Setfailure("编辑菜单失败");
            return(Json(AR));
            //   return RedirectToAction("Index");
        }
Exemplo n.º 4
0
        public async Task <ActionResult> EditMenu(int id)
        {
            var vMenu = await _context.Navigations.FindAsync(id);

            NavIM dto = _mapper.Map <NavIM>(vMenu);

            var pm = await _context.PageMetas.FirstOrDefaultAsync(d => d.ModuleType == (short)ModuleType.MENU && d.ObjectId == dto.Url);

            if (pm != null)
            {
                dto.SEOTitle       = pm.Title;
                dto.SEOKeywords    = pm.Keywords;
                dto.SEODescription = pm.Description;
            }

            return(PartialView("_MenuEdit", dto));
        }