public ActionResult AddMenu(Sys_MenuModel model)
 {
     InsertBaseData(model);
     if (model.parentID == Guid.Empty)
     {
         model.menuLevel = 1;
     }
     else
     {
         model.menuLevel = 2;
     }
     try
     {
         string url        = string.Format("{0}/Component/InsertMenu", ConfigurationManager.AppSettings["APIAddress"]);
         string statusCode = string.Empty;
         bool   isSuccess  = Convert.ToBoolean(HttpClientHelpClass.PostResponse <Sys_MenuModel>(url, model, ConfigurationManager.AppSettings["APIToken"], out statusCode));
         if (isSuccess)
         {
             return(Json(new OperationResult(OperationResultType.Success, "添加成功!")));
         }
         else
         {
             return(Json(new OperationResult(OperationResultType.Warning, "添加失败!")));
         }
     }
     catch (Exception e)
     {
         return(Json(new OperationResult(OperationResultType.Warning, "添加失败!", e.Message)));
     }
 }
Beispiel #2
0
        public bool UpdateMenu([FromBody] Sys_MenuModel model)
        {
            Mapper.CreateMap <Sys_MenuModel, Sys_Menu>();                             // 配置
            Sys_Menu        menu       = Mapper.Map <Sys_MenuModel, Sys_Menu>(model); // 使用AutoMapper自动映射
            IComponentLogic IComponent = container.Resolve <IComponentLogic>();

            return(IComponent.UpdateMenu(menu));
        }
        public ActionResult ModifyMenu(Guid id)
        {
            ViewBag.menu = GetMenuSelectList();
            string        url   = string.Format("{0}/Component/GetMenu?id={1}", ConfigurationManager.AppSettings["APIAddress"], id);
            Sys_MenuModel model = HttpClientHelpClass.GetResponse <Sys_MenuModel>(url, ConfigurationManager.AppSettings["APIToken"]);

            return(PartialView("MenuForm", model));
        }
        public ActionResult AddMenu()
        {
            Sys_MenuModel model = new Sys_MenuModel {
                menuID = Guid.NewGuid()
            };

            ViewBag.menu = GetMenuSelectList();
            return(PartialView("MenuForm", model));
        }
Beispiel #5
0
        public Sys_MenuModel GetMenu(Guid id)
        {
            IComponentLogic IComponent = container.Resolve <IComponentLogic>();
            Sys_Menu        menu       = IComponent.GetMenu(id);

            Mapper.CreateMap <Sys_Menu, Sys_MenuModel>();                     // 配置
            Sys_MenuModel model = Mapper.Map <Sys_Menu, Sys_MenuModel>(menu); // 使用AutoMapper自动映射

            return(model);
        }
Beispiel #6
0
        public Sys_MenuModel GetMenuListByUrl(string url)
        {
            IComponentLogic IComponent = container.Resolve <IComponentLogic>();
            Sys_Menu        menu       = IComponent.GetMenuListByUrl(url);

            Mapper.CreateMap <Sys_Menu, Sys_MenuModel>();                     // 配置
            Sys_MenuModel model = Mapper.Map <Sys_Menu, Sys_MenuModel>(menu); // 使用AutoMapper自动映射

            return(model);
        }
        public void CreateBreadcrumbNavigation(ResultExecutingContext filterContext)
        {
            string        requestUrl = HttpContext.Current.Request.Url.AbsolutePath + HttpContext.Current.Request.Url.Query;
            string        Apiurl     = string.Format("{0}/Component/GetMenuListByUrl?url={1}", ConfigurationManager.AppSettings["APIAddress"], requestUrl);
            Sys_MenuModel menu       = HttpClientHelpClass.GetResponse <Sys_MenuModel>(Apiurl, ConfigurationManager.AppSettings["APIToken"]);

            if (menu != null)
            {
                Apiurl = string.Format("{0}/Component/GetMenuList", ConfigurationManager.AppSettings["APIAddress"]);
                List <Sys_MenuModel> list = HttpClientHelpClass.GetResponse <List <Sys_MenuModel> >(Apiurl, ConfigurationManager.AppSettings["APIToken"]);
                var result = new
                {
                    name  = menu.menuName,
                    pname = list.FirstOrDefault(o => o.menuID == menu.parentID).menuName,
                    purl  = list.FirstOrDefault(o => o.menuID == menu.parentID).menuUrl
                };
                //var result = list.Select(
                //    t => new
                //    {
                //        name = t.menuName,
                //        pname = bll.GetMenuList().FirstOrDefault(o => o.menuID == t.parentID).menuName,
                //        purl = bll.GetMenuList().FirstOrDefault(o => o.menuID == t.parentID).menuUrl
                //    }).FirstOrDefault();
                string breadcrumbStr = string.Format("<li><a href=\"{0}\">{1}</a></li><li class=\"active\">{2}</li>", result.purl, result.pname, result.name);
                breadcrumbStr = string.Format("<ol class=\"breadcrumb\"><li><a href=\"#\"><i class=\"fa fa-dashboard\"></i> 主页</a></li>{0}</ol>", breadcrumbStr);
                ((ViewResult)filterContext.Result).ViewBag.PageTitle  = MvcHtmlString.Create("<h1>" + result.name + "<small> " + result.pname + "</small></h1>");
                ((ViewResult)filterContext.Result).ViewBag.Breadcrumb = MvcHtmlString.Create(breadcrumbStr);
            }
            //AuthenticationBll bll = new AuthenticationBll();
            //List<Sys_MenuInfo> list = bll.GetMenuList().Where(t => t.enable == true && t.menuUrl == requestUrl).ToList();
            //if (list.Count > 0)
            //{
            //    var result = list.Select(
            //        t => new
            //        {
            //            name = t.menuName,
            //            pname = bll.GetMenuList().FirstOrDefault(o => o.menuID == t.parentID).menuName,
            //            purl = bll.GetMenuList().FirstOrDefault(o => o.menuID == t.parentID).menuUrl
            //        }).FirstOrDefault();
            //    string breadcrumbStr = string.Format("<li><a href=\"{0}\">{1}</a></li><li class=\"active\">{2}</li>", result.purl, result.pname, result.name);
            //    breadcrumbStr = string.Format("<ol class=\"breadcrumb\"><li><a href=\"#\"><i class=\"fa fa-dashboard\"></i> 主页</a></li>{0}</ol>", breadcrumbStr);
            //    ((ViewResult)filterContext.Result).ViewBag.PageTitle = MvcHtmlString.Create("<h1>" + result.name + "<small> " + result.pname + "</small></h1>");
            //    ((ViewResult)filterContext.Result).ViewBag.Breadcrumb = MvcHtmlString.Create(breadcrumbStr);
            //}
        }
        public void CreatePermission(ResultExecutingContext filterContext)
        {
            string     cookieName = FormsAuthentication.FormsCookieName;                        //读取登录授权Cookies的名称
            HttpCookie authCookie = System.Web.HttpContext.Current.Request.Cookies[cookieName]; //接收这个Cookies
            //System.Web.HttpContext.Current.Request.Cookies.Remove("");
            FormsAuthenticationTicket authTicket = null;

            try
            {
                authTicket = FormsAuthentication.Decrypt(authCookie.Value);//我们知道MVC登录授权的Cookies是加密的,所以我们在此需要解密
            }
            catch (Exception ex)
            {
                //filterContext.HttpContext.Response.Redirect("/Account/Login");//否则跳转至登陆页
                return;
            }
            if (authTicket != null && filterContext.HttpContext.User.Identity.IsAuthenticated)//如果Cookies不为Null 也通过验证
            {
                string        UserID     = authTicket.Name;
                EmployeModel  model      = JsonConvert.DeserializeObject <EmployeModel>(authTicket.UserData);
                string        requestUrl = HttpContext.Current.Request.Url.AbsolutePath + HttpContext.Current.Request.Url.Query;
                string        Apiurl     = string.Format("{0}/Component/GetMenuListByUrl?url={1}", ConfigurationManager.AppSettings["APIAddress"], requestUrl);
                Sys_MenuModel menu       = HttpClientHelpClass.GetResponse <Sys_MenuModel>(Apiurl, ConfigurationManager.AppSettings["APIToken"]);
                //Sys_MenuModel menu = list.Where(t => t.enable == true && t.menuUrl == requestUrl).FirstOrDefault();
                if (menu != null)
                {
                    Apiurl = string.Format("{0}/Component/GetButtonByRoleAndUrl?roleID={1}&menuID={2}", ConfigurationManager.AppSettings["APIAddress"], model.fk_roleID, menu.menuID);
                    List <Sys_ButtonModel> btnList = HttpClientHelpClass.GetResponse <List <Sys_ButtonModel> >(Apiurl, ConfigurationManager.AppSettings["APIToken"]);
                    string btnToolBarHTML          = "";
                    foreach (var btn in btnList)
                    {
                        //btnToolBarHTML = string.Format("<div class=\"btn-toolbar\">{0}</div>", btnToolBarHTML);
                        btnToolBarHTML += string.Format("<button class=\"btn btn-primary margin\" onclick=\"{0}\">{1}</button>", btn.func, btn.btnName);
                    }
                    btnToolBarHTML = string.Format("<div class=\"btn-toolbar\">{0}</div>", btnToolBarHTML);
                    ((ViewResult)filterContext.Result).ViewBag.btnToolBar = MvcHtmlString.Create(btnToolBarHTML);
                }
                //CommonMethod.setCookieForMIn("UserName", UserName, 30);//用于全局,加载用户信息
            }
            //else
            //{
            //    filterContext.HttpContext.Response.Redirect("/Account/Login");//否则跳转至登陆页
            //}
        }