Exemple #1
0
        public ActionResult DeleteRoles(string[] ids)
        {
            if (ids.Length <= 0)
            {
                return(Json(new { code = 999, msg = "参数有误" }));
            }
            SystemRoleService service = new SystemRoleService();

            object[] obj   = new object[ids.Length];
            string   parms = SqlParameterHelper.GetParameters(ids, ref obj);
            string   sql   = $"delete from SystemRole where id in({parms})";
            int      n     = service.ExcuteSqlParm(sql, obj);

            return(Json(new { code = 0, msg = "success" }));
        }
Exemple #2
0
        public ActionResult DeleteUsers(string[] ids)
        {
            if (ids.Length <= 0)
            {
                return(Json(new { code = 999, msg = "参数有误" }));
            }
            AdminUserService service = new AdminUserService();

            object[] obj   = new object[ids.Length];
            string   parms = SqlParameterHelper.GetParameters(ids, ref obj);
            string   sql   = $"update admin_user set deletemark=1 where id in({parms})";

            int n = service.ExcuteSqlParm(sql, obj);

            return(Json(new { code = 0, msg = "success" }));
        }
Exemple #3
0
        public ActionResult EditRole(RoleAndRloeValues rolevalModel)
        {
            var result = ResModelFactory.ResDefault();
            //
            SystemRoleService service = new SystemRoleService();
            SystemRole        oldRole = service.GetEntitys(p => p.ID == rolevalModel.Id).FirstOrDefault();

            oldRole.RoleName    = rolevalModel.RoleName;
            oldRole.Description = rolevalModel.Description;
            //传过来的 角色权限
            List <SystemRoleValue> rolevalues = new List <SystemRoleValue>();

            if (rolevalModel.TreeData != null)
            {
                foreach (var rval in rolevalModel.TreeData)
                {
                    SystemRoleValue roleval = new SystemRoleValue();
                    roleval.ID     = Guid.NewGuid().ToString();
                    roleval.RoleId = rolevalModel.Id;
                    roleval.MenuId = rval.id;
                    roleval.Action = "View,Show,Add,Modify,Delete";
                    rolevalues.Add(roleval);
                    InitRoleVal(rolevalues, rval.children ?? new List <TreeDataViewModel>().ToArray(), rolevalModel.Id);
                }
            }
            //角色是增加还是减少
            SystemRoleValueService       rservice   = new SystemRoleValueService();
            IQueryable <SystemRoleValue> oldroleval = rservice.GetEntitys(p => p.RoleId == rolevalModel.Id);

            List <string> oldmids = oldroleval.Select(s => s.MenuId).ToList();
            List <string> newmids = rolevalues.Select(t => t.MenuId).ToList();

            //得到增加的menuid
            List <string> add = new List <string>();
            //得到减少的menuid
            List <string> decrease = new List <string>();

            if (oldmids.Count() > 0 && newmids.Count() > 0)
            {
                decrease = oldmids.Except(newmids).ToList();
                add      = newmids.Except(oldmids).ToList();
            }
            else if (oldmids.Count() > 0 && newmids.Count() <= 0)
            {
                decrease = oldmids;
            }
            else if (oldmids.Count() <= 0 && newmids.Count() > 0)
            {
                add = newmids;
            }

            //删除减少的权限
            object[] obj   = new object[decrease.Count() + 1];
            string   parms = string.Empty;
            string   sql   = string.Empty;

            if (decrease.Count > 0)
            {
                parms = SqlParameterHelper.GetParameters(decrease.ToArray(), ref obj);
                sql   = $"delete from SystemRoleValue where roleid=@roleid and menuid in({parms})";
                obj[decrease.Count()] = new SqlParameter("@roleid", rolevalModel.Id);
            }
            //var add = new List<SystemRoleValue>();
            //if (add.Count > 0)
            //{
            //    add = rolevalues.Where(p => add.Contains(p.MenuId)).ToList();
            //}
            bool isok = service.EditRole(oldRole, rolevalues.Where(p => add.Contains(p.MenuId)).ToList(), sql, obj);

            return(Json(result, JsonRequestBehavior.AllowGet));
        }