Beispiel #1
0
        /// <summary>
        /// 新增系统代码。
        /// </summary>
        /// <param name="dto">待新增系统代码的信息。</param>
        /// <returns>新系统代码的Id。(-2:Tag重复。)</returns>
        public static string InsertSysCode(SysCodeDTO dto)
        {
            SysCode existingSc = GetSysCodeByTag(dto.Tag);

            if (existingSc != null)
            {
                return("-2");
            }

            Db.SessionFactory.EvictQueries("SysCode");

            SysCode sc = new SysCode();

            sc.Id      = IdGen.GetNextId(typeof(SysCode));
            sc.Tag     = dto.Tag;
            sc.Name    = dto.Name;
            sc.Remark  = dto.Remark;
            sc.OrderId = dto.OrderId;

            SysCodeType sct = Db.Session.Load(typeof(SysCodeType), dto.SysCodeTypeId) as SysCodeType;

            sct.AddSysCode(sc);

            Db.TransInsert(sc);
            return(sc.Id);
        }
Beispiel #2
0
        /// <summary>
        /// 新增模块。
        /// </summary>
        /// <param name="dto">待新增模块的信息。</param>
        /// <returns>新模块的Id。(-2:Tag重复。)</returns>
        public static string InsertModule(ModuleDTO dto)
        {
            Module existingM = GetModuleByTag(dto.Tag);

            if (existingM != null)
            {
                return("-2");
            }

            Db.SessionFactory.EvictQueries("Module");

            //模块基本信息。
            Module m = new Module();

            m.Id        = IdGen.GetNextId(typeof(Module));
            m.Tag       = dto.Tag;
            m.Name      = dto.Name;
            m.Remark    = dto.Remark;
            m.OrderId   = dto.OrderId;
            m.ModuleUrl = dto.ModuleUrl;
            m.Disabled  = dto.Disabled?1:0;

            //模块分类。
            ModuleType mt = Db.Session.Load(typeof(ModuleType), dto.ModuleTypeId) as ModuleType;

            mt.AddModule(m);

            //获取新增模块权限的主键值。
            string[] Ids = null;
            if (dto.ModuleRights.Count > 0)
            {
                Ids = IdGen.GetNextId(typeof(ModuleRight), dto.ModuleRights.Count);
            }

            //向数据库保存模块和模块权限。
            ITransaction transaction = Db.Session.BeginTransaction();

            try
            {
                Db.Session.Save(m);
                for (int i = 0; i < dto.ModuleRights.Count; i++)
                {
                    ModuleRight mr = new ModuleRight();
                    mr.Id       = Ids[i];
                    mr.RightTag = dto.ModuleRights[i].ToString();
                    m.AddModuleRight(mr);
                    Db.Session.Save(mr);
                }
                transaction.Commit();
            }
            catch
            {
                transaction.Rollback();
                throw;
            }

            //返回新模块的Id。
            return(m.Id);
        }
Beispiel #3
0
        /// <summary>
        /// 新增角色。
        /// </summary>
        /// <param name="dto">待新增角色的信息。</param>
        /// <returns>新角色的Id。</returns>
        public static string InsertRole(RoleDTO dto)
        {
            Role r = new Role();

            r.Id      = IdGen.GetNextId(typeof(Role));
            r.Name    = dto.Name;
            r.Remark  = dto.Remark;
            r.OrderId = dto.OrderId;

            RoleType rt = Db.Session.Load(typeof(RoleType), dto.RoleTypeId) as RoleType;

            rt.AddRole(r);

            Db.TransInsert(r);
            return(r.Id);
        }
Beispiel #4
0
        /// <summary>
        /// 新增模块分类。
        /// </summary>
        /// <param name="dto">待新增模块分类的信息。</param>
        /// <returns>新模块分类的Id。</returns>
        public static string InsertModuleType(ModuleTypeDTO dto)
        {
            Db.SessionFactory.EvictQueries("ModuleType");

            ModuleType mt = new ModuleType();

            mt.Id      = IdGen.GetNextId(typeof(ModuleType));
            mt.Name    = dto.Name;
            mt.Remark  = dto.Remark;
            mt.OrderId = dto.OrderId;

            if (dto.ParentModuleTypeId != null && dto.ParentModuleTypeId.Length > 0)
            {
                ModuleType pmt = Db.Session.Load(typeof(ModuleType), dto.ParentModuleTypeId) as ModuleType;
                pmt.AddSubModuleType(mt);
            }

            Db.TransInsert(mt);

            return(mt.Id);
        }
Beispiel #5
0
        /// <summary>
        /// 新增系统代码分类。
        /// </summary>
        /// <param name="dto">待新增系统代码分类的信息。</param>
        /// <returns>新系统代码分类的Id。(-2:Tag重复。)</returns>
        public static string InsertSysCodeType(SysCodeTypeDTO dto)
        {
            SysCodeType existingSct = GetSysCodeTypeByTag(dto.Tag);

            if (existingSct != null)
            {
                return("-2");
            }

            Db.SessionFactory.EvictQueries("SysCodeType");

            SysCodeType sct = new SysCodeType();

            sct.Id      = IdGen.GetNextId(typeof(SysCodeType));
            sct.Tag     = dto.Tag;
            sct.Name    = dto.Name;
            sct.Remark  = dto.Remark;
            sct.OrderId = dto.OrderId;

            Db.TransInsert(sct);
            return(sct.Id);
        }
Beispiel #6
0
        /// <summary>
        /// 新增角色分类。
        /// </summary>
        /// <param name="dto">待新增角色分类的信息。</param>
        /// <returns>新角色分类的Id。</returns>
        public static string InsertRoleType(RoleTypeDTO dto)
        {
            Db.SessionFactory.EvictQueries("RoleType");

            RoleType rt = new RoleType();

            rt.Id      = IdGen.GetNextId(typeof(RoleType));
            rt.Name    = dto.Name;
            rt.Remark  = dto.Remark;
            rt.OrderId = dto.OrderId;

            RoleType prt = null;

            if (dto.ParentRoleTypeId != null && dto.ParentRoleTypeId.Length > 0)
            {
                prt = Db.Session.Load(typeof(RoleType), dto.ParentRoleTypeId) as RoleType;
                prt.AddSubRoleType(rt);
            }

            Db.TransInsert(rt);

            return(rt.Id);
        }
Beispiel #7
0
        /// <summary>
        /// 新增部门。
        /// </summary>
        /// <param name="dto">待新增部门的信息。</param>
        /// <returns>新部门的Id。</returns>
        public static string InsertDepartment(DepartmentDTO dto)
        {
            Db.SessionFactory.EvictQueries("Department");

            Department d = new Department();

            d.Id        = IdGen.GetNextId(typeof(Department));
            d.Name      = dto.Name;
            d.Phone     = dto.Phone;
            d.ExtNumber = dto.ExtNumber;
            d.Fax       = dto.Fax;
            d.Remark    = dto.Remark;
            d.OrderId   = dto.OrderId;

            if (dto.ParentDepartmentId != null && dto.ParentDepartmentId.Length > 0)
            {
                Department pd = Db.Session.Load(typeof(Department), dto.ParentDepartmentId) as Department;
                pd.AddSubDepartment(d);
            }

            Db.TransInsert(d);

            return(d.Id);
        }
Beispiel #8
0
        /// <summary>
        /// 更新模块。
        /// </summary>
        /// <param name="dto">待更新模块的信息。</param>
        /// <returns>成功标示。(1:成功;-2:Tag重复。)</returns>
        public static string UpdateModule(ModuleDTO dto)
        {
            Module existingM = GetModuleByTag(dto.Tag);

            if (existingM != null && existingM.Id != dto.Id)
            {
                return("-2");
            }

            Db.SessionFactory.EvictQueries("Module");

            //模块基本信息。
            Module m = Db.Session.Load(typeof(Module), dto.Id) as Module;

            m.Tag       = dto.Tag;
            m.Name      = dto.Name;
            m.Remark    = dto.Remark;
            m.OrderId   = dto.OrderId;
            m.ModuleUrl = dto.ModuleUrl;
            m.Disabled  = dto.Disabled?1:0;

            //待删除的权限。
            ArrayList ToBeRemoved = new ArrayList();

            foreach (var k in m.ModuleRights)
            {
                string key    = k.Key.ToString();
                bool   isFind = false;
                for (int i = 0; i < dto.ModuleRights.Count; i++)
                {
                    if (key == dto.ModuleRights[i].ToString())
                    {
                        isFind = true;
                        break;
                    }
                }
                if (!isFind)
                {
                    ToBeRemoved.Add(key);
                }
            }


            //待增加的权限。
            ArrayList ToBeAdded = new ArrayList();

            for (int i = 0; i < dto.ModuleRights.Count; i++)
            {
                //2017-07-20 修改
                if (!m.ModuleRights.ContainsKey(dto.ModuleRights[i]))
                {
                    ToBeAdded.Add(dto.ModuleRights[i].ToString());
                }
            }

            //获取新增模块权限的主键值。
            string[] Ids = null;
            if (ToBeAdded.Count > 0)
            {
                Ids = IdGen.GetNextId(typeof(ModuleRight), ToBeAdded.Count);
            }

            //向数据库保存新的模块信息和模块权限信息。
            ITransaction transaction = Db.Session.BeginTransaction();

            try
            {
                //删除权限。
                foreach (object key in ToBeRemoved)
                {
                    ModuleRight mr = m.ModuleRights[key] as ModuleRight;
                    mr.RemoveAllPermissions();
                    mr.BreakAwayFromModule();
                    Db.Session.Delete(mr);
                }

                //增加权限。
                for (int i = 0; i < ToBeAdded.Count; i++)
                {
                    ModuleRight newMr = new ModuleRight();
                    newMr.Id       = Ids[i];
                    newMr.RightTag = ToBeAdded[i].ToString();
                    m.AddModuleRight(newMr);
                    Db.Session.Save(newMr);
                }

                Db.Session.Update(m);
                transaction.Commit();

                return("1");
            }
            catch
            {
                transaction.Rollback();
                throw;
            }
        }