public IActionResult AddAdminMenu(AdminMenu model)
        {
            if (!ModelState.IsValid)
            {
                string messages = string.Join("; ", ModelState.Values
                                              .SelectMany(x => x.Errors)
                                              .Select(x => x.ErrorMessage));

                tip.Message = messages;
                return(Json(tip));
            }
            //判断
            if (AdminMenu.FindCount(AdminMenu._.MenuKey == model.MenuKey, null, null, 0, 0) > 0)
            {
                tip.Message = "菜单KEY已经存在,请填写其他的!";
            }
            IList <TargetEvent> listevent = TargetEvent.FindAll(null, TargetEvent._.Rank.Asc(), null, 0, 0);

            string[] eventkeys           = Request.Form["eventkey"];
            List <AdminMenuEvent> listme = new List <AdminMenuEvent>();

            if (eventkeys != null && eventkeys.Length > 0)
            {
                foreach (string s in eventkeys)
                {
                    if (Utils.IsInt(s))
                    {
                        TargetEvent te = listevent.FirstOrDefault(t => t.Id == int.Parse(s));
                        if (te != null)
                        {
                            AdminMenuEvent tmp = new AdminMenuEvent();
                            tmp.EventId   = te.Id;
                            tmp.EventKey  = te.EventKey;
                            tmp.EventName = te.EventName;
                            tmp.MenuKey   = model.MenuKey;
                            listme.Add(tmp);
                        }
                    }
                }
            }
            model.Insert();
            if (listme != null && listme.Count > 0)
            {
                listme.ForEach(s =>
                {
                    s.MenuId = model.Id;
                });
                listme.Insert();
            }
            tip.Status    = JsonTip.SUCCESS;
            tip.Message   = "添加后台菜单成功";
            tip.ReturnUrl = "close";
            return(Json(tip));
        }
示例#2
0
        public IActionResult Index()
        {
            bool hasData = AdminMenu.FindCount(null, null, null, 0, 0) > 0;

            if (!hasData)
            {
                return(Redirect("/Home/Install"));
            }
            ViewBag.cfg   = cfg;
            ViewBag.about = Article.FindById(1);//关于我们
            return(View("~/Views/Home/Index.cshtml"));
        }
        public IActionResult DelAdminMenu(int id)
        {
            AdminMenu entity = AdminMenu.Find(AdminMenu._.Id == id);

            if (entity == null)
            {
                tip.Message = "系统找不到本记录!";
                return(Json(tip));
            }
            if (AdminMenu.FindCount(AdminMenu._.PId == entity.Id, null, null, 0, 0) > 0)
            {
                tip.Message = "本菜单有下级菜单,不允许删除!";
                return(Json(tip));
            }
            entity.Delete();
            tip.Status  = JsonTip.SUCCESS;
            tip.Message = "删除后台菜单成功";
            return(Json(tip));
        }
示例#4
0
        public IActionResult Index()
        {
            if (Admin.IsAdminLogin())
            {
                return(Redirect("/AdminCP"));
            }

            bool hasData = AdminMenu.FindCount(null, null, null, 0, 0) > 0;

            if (!hasData)
            {
                return(Redirect("/Home/Install"));
            }

            string key = Utils.GetRandomChar(12);

            SessionHelper.WriteSession("des_key", key);
            ViewBag.key = key;
            return(View());
        }
示例#5
0
        public IActionResult Install()
        {
            string lockPath = $"{_env.WebRootPath}{Path.DirectorySeparatorChar}install.lock";

            if (System.IO.File.Exists(lockPath))
            {
                return(EchoTip("COMCMS系统已经安装过,如果需要重新安装,请删除程序wwwroot目录下的install.lock文件!", false, "/"));
            }
            //判断数据库类型 mysql mssql 暂时只支持这两种
            string sqltype         = "mysql";
            string sqlProviderName = Utils.GetSetting("connectionStrings:dbconn:providerName");

            if (sqlProviderName == "System.Data.SqlClient")
            {
                sqltype = "mssql";
            }
            bool hasData = AdminMenu.FindCount(null, null, null, 0, 0) > 0;

            ViewBag.hasData = hasData;
            ViewBag.sqltype = sqltype;
            return(View());
        }
        public IActionResult EditAdminMenu(AdminMenu model)
        {
            if (!ModelState.IsValid)
            {
                string messages = string.Join("; ", ModelState.Values
                                              .SelectMany(x => x.Errors)
                                              .Select(x => x.ErrorMessage));
                tip.Message = messages;
                return(Json(tip));
            }
            if (model.Id <= 0)
            {
                tip.Message = "错误参数传递!";
                return(Json(tip));
            }
            AdminMenu entity = AdminMenu.Find(AdminMenu._.Id == model.Id);

            if (entity == null)
            {
                tip.Message = "系统找不到本记录!";
                return(Json(tip));
            }
            //赋值
            entity.MenuName = model.MenuName;
            //如果key修改了。判断是否有存在
            if (entity.MenuKey != model.MenuKey)
            {
                if (AdminMenu.FindCount(AdminMenu._.MenuKey == model.MenuKey & AdminMenu._.Id != entity.Id, null, null, 0, 0) > 0)
                {
                    tip.Message = "您修改的菜单KEY已经存在,请填写其他的!";
                    return(Json(tip));
                }
                entity.MenuKey = model.MenuKey;
            }
            entity.Link      = model.Link;
            entity.IsHide    = model.IsHide;
            entity.ClassName = model.ClassName;
            entity.Rank      = model.Rank;
            if (entity.PId != model.PId)
            {
                //重新获取level和location
                entity.Level    = AdminMenu.GetNewLevel(model.PId);
                entity.Location = AdminMenu.GetNewLocation(model.PId);
            }
            entity.PId = model.PId;
            entity.Update();

            //处理权限
            IList <AdminMenuEvent> oldevent = AdminMenuEvent.FindAll(AdminMenuEvent._.MenuId == entity.Id, null, null, 0, 0);

            //所有的权限
            IList <TargetEvent> listevent = TargetEvent.FindAll(TargetEvent._.Id > 0, TargetEvent._.Rank.Asc(), null, 0, 0);

            //新的权限
            string[] eventkeys           = Request.Form["eventkey"];
            List <AdminMenuEvent> listme = new List <AdminMenuEvent>();

            if (eventkeys != null && eventkeys.Length > 0)
            {
                foreach (string s in eventkeys)
                {
                    if (Utils.IsInt(s))
                    {
                        TargetEvent te = listevent.FirstOrDefault(t => t.Id == int.Parse(s));
                        if (te != null)
                        {
                            AdminMenuEvent tmp = new AdminMenuEvent();
                            tmp.EventId   = te.Id;
                            tmp.EventKey  = te.EventKey;
                            tmp.EventName = te.EventName;
                            tmp.MenuKey   = model.MenuKey;
                            tmp.MenuId    = entity.Id;
                            listme.Add(tmp);
                        }
                    }
                }
            }

            //判断是否在旧的里面
            listme.ForEach(s =>
            {
                var oe = oldevent.FirstOrDefault(o => o.EventId == s.EventId);
                //如果是旧列表存在,则删掉旧列表里面的,然后更新自己
                if (oe != null)
                {
                    s.Id = oe.Id;
                    s.Update();
                    oldevent.Remove(oe);
                }
                else
                {
                    //如果不存在,则是新增的。直接新增处理
                    s.Insert();
                }
            });
            //如果还有,则删除旧列表里面的
            if (oldevent != null && oldevent.Count > 0)
            {
                oldevent.Delete();
            }

            tip.Status    = JsonTip.SUCCESS;
            tip.Message   = "编辑后台菜单成功";
            tip.ReturnUrl = "close";
            return(Json(tip));
        }