Example #1
0
        /// <summary>
        /// 设置用户角色
        /// </summary>
        /// <param name="UserID"></param>
        /// <param name="RoleID"></param>
        /// <param name="IsHas">ture设置 false移除</param>
        public void SetUserRole(string UserID, string RoleID)
        {
            using (var factory = new BaseAccess())
            {
                //如果传入的roleid为空的话移除改用户对对应的所有角色
                if (string.IsNullOrWhiteSpace(RoleID))
                {
                    var entity = factory.GetAll <UserRoleEntity>(Specification <UserRoleEntity> .Create(c => c.UserID == UserID));
                    factory.Delete <UserRoleEntity>(entity);
                }
                else
                {
                    var entity = factory.GetAll <UserRoleEntity>(Specification <UserRoleEntity> .Create(c => c.UserID == UserID));
                    factory.Delete <UserRoleEntity>(entity);
                    var Rids = RoleID.Split(',');
                    foreach (var item in Rids)
                    {
                        var spec = Specification <UserRoleEntity> .Create(c => c.UserID == UserID && c.RoleID == item);

                        bool bl = factory.IsExists <UserRoleEntity>(spec);
                        if (!bl)
                        {
                            var userRole = new UserRoleEntity()
                            {
                                RoleID = item, UserID = UserID
                            };
                            factory.Insert <UserRoleEntity>(userRole);
                        }
                    }
                }
            }
        }
Example #2
0
        /// <summary>
        /// 删除多个对象
        /// </summary>
        /// <param name="IDs">需要删除数据的ID,使用“,”分隔</param>
        public void Del(string IDs)
        {
            using (var factory = new BaseAccess())
            {
                try
                {
                    foreach (var id in IDs.Split(','))
                    {
                        var model = factory.GetSingle <OrganizationEntity>(id);
                        if (model != null)
                        {
                            //获取所有子节点
                            List <OrganizationEntity> childrens = new List <OrganizationEntity>()
                            {
                                model
                            };
                            childrens = GetChilds(factory, model.ID, childrens);
                            foreach (var c in childrens)
                            {
                                factory.Delete <OrganizationEntity>(c, false);
                            }
                        }
                    }
                    factory.Commit();

                    //清理缓存
                    CacheshipFactory.Instance.ClearOrganCache();
                }
                catch (Exception ex)
                {
                    factory.Rollback();
                    throw ex;
                }
            }
        }
Example #3
0
 /// <summary>
 /// 设置分组用户
 /// </summary>
 /// <param name="OrganID"></param>
 /// <param name="UserID"></param>
 /// <param name="IsHas">ture设置 false移除</param>
 public void SetUserOrgan(string OrganID, string UserID, bool IsHas)
 {
     using (var factory = new BaseAccess())
     {
         //获取用户的所有分组
         var UserAllOrgan = factory.GetAll <UserOrganizationEntity>(Specification <UserOrganizationEntity> .Create(c => c.UserID == UserID));
         if (IsHas)
         {
             //增加
             if (UserAllOrgan == null || UserAllOrgan.Count == 0 || UserAllOrgan.Count(c => c.OrganizationID == OrganID) == 0)
             {
                 var organUser = new UserOrganizationEntity()
                 {
                     OrganizationID = OrganID,
                     UserID         = UserID,
                     IsDefault      = UserAllOrgan.Count(c => c.IsDefault == (int)YesNo.Yes) == 0 ? (int)YesNo.Yes : (int)YesNo.No
                 };
                 factory.Insert <UserOrganizationEntity>(organUser);
             }
         }
         else
         {
             //移除
             if (UserAllOrgan != null && UserAllOrgan.Count(c => c.OrganizationID == OrganID) > 0)
             {
                 factory.Delete <UserOrganizationEntity>(UserAllOrgan.Where(c => c.OrganizationID == OrganID).First());
             }
         }
     }
 }
Example #4
0
 /// <summary>
 /// 设置角色菜单
 /// </summary>
 /// <param name="RoleID"></param>
 /// <param name="MenuIDs"></param>
 public void SetRoleMenus(string RoleID, List <string> MenuIDs)
 {
     using (var factory = new BaseAccess())
     {
         try
         {
             if (!string.IsNullOrEmpty(RoleID))
             {
                 var menus_old = factory.GetAll <MenuRoleEntity>(Specification <MenuRoleEntity> .Create(c => c.RoleID == RoleID));
                 factory.Delete <MenuRoleEntity>(menus_old, false);
                 if (MenuIDs != null)
                 {
                     foreach (string id in MenuIDs)
                     {
                         var entity = new MenuRoleEntity()
                         {
                             ID     = Guid.NewGuid().ToString(),
                             RoleID = RoleID,
                             MenuID = id
                         };
                         factory.Insert <MenuRoleEntity>(entity, false);
                     }
                 }
                 factory.Commit();
             }
         }
         catch (Exception ex)
         {
             factory.Rollback();
             throw ex;
         }
     }
 }
Example #5
0
 /// <summary>
 /// 设置角色系统
 /// </summary>
 /// <param name="UserID"></param>
 /// <param name="RoleID"></param>
 /// <param name="IsHas">ture设置 false移除</param>
 public void SetAppRole(string AppID, string RoleID, bool IsHas)
 {
     using (var factory = new BaseAccess(base._DBConfigPath))
     {
         var appRole = factory.GetSingle <SYS_AppRoleEntity>(Specification <SYS_AppRoleEntity> .Create(c => c.AppID == AppID && c.RoleID == RoleID));
         if (IsHas)
         {
             //增加
             if (appRole == null || string.IsNullOrEmpty(appRole.ID))
             {
                 appRole = new SYS_AppRoleEntity()
                 {
                     RoleID = RoleID, AppID = AppID
                 };
                 factory.Insert <SYS_AppRoleEntity>(appRole);
             }
         }
         else
         {
             //移除
             if (appRole != null && !string.IsNullOrEmpty(appRole.ID))
             {
                 factory.Delete <SYS_AppRoleEntity>(appRole);
             }
         }
     }
 }
Example #6
0
        /// <summary>
        /// 删除多个对象
        /// </summary>
        /// <param name="IDs">需要删除数据的ID,使用“,”分隔</param>
        public void Del(string IDs)
        {
            using (var factory = new BaseAccess())
            {
                factory.Delete <RoleEntity>(IDs);

                //清理缓存
                CacheshipFactory.Instance.ClearRoleCache();
            }
        }
Example #7
0
        /// <summary>
        /// 删除用户
        /// </summary>
        /// <param name="IDs">用户ID,逗号“,”隔开</param>
        /// <returns></returns>
        public bool DelUsers(string IDs)
        {
            using (var factory = new BaseAccess(base._DBConfigPath))
            {
                try
                {
                    string[] userIDs = IDs.Split(',');
                    factory.Delete <UserEntity>(userIDs, false);
                    //循环删除用户分组
                    var userOrgans = factory.GetAll <UserOrganizationEntity>(Specification <UserOrganizationEntity> .Create(c => userIDs.Contains(c.UserID)));
                    foreach (var userOrgan in userOrgans)
                    {
                        factory.Delete <UserOrganizationEntity>(userOrgan, false);
                    }
                    //循环删除用户角色
                    var userRoles = factory.GetAll <UserRoleEntity>(Specification <UserRoleEntity> .Create(c => userIDs.Contains(c.UserID)));
                    foreach (var userRole in userRoles)
                    {
                        factory.Delete <UserRoleEntity>(userRole, false);
                    }
                    factory.Commit();

                    //清理缓存
                    foreach (var id in userIDs)
                    {
                        Manage.Open.CacheshipFactory.Instance.ClearSSOUserCache(id);
                    }
                    return(true);
                }
                catch (Exception ex)
                {
                    factory.Rollback();
                    return(false);
                }
            }
        }
Example #8
0
        /// <summary>
        /// 删除多个对象
        /// </summary>
        /// <param name="IDs">需要删除数据的ID,使用“,”分隔</param>
        public void Del(string IDs)
        {
            using (var factory = new BaseAccess())
            {
                try
                {
                    foreach (var id in IDs.Split(','))
                    {
                        var model = factory.GetSingle <Sys_DictionaryEntity>(id);
                        if (model != null)
                        {
                            //获取所有子节点
                            List <Sys_DictionaryEntity> childrens = new List <Sys_DictionaryEntity>()
                            {
                                model
                            };
                            childrens = GetChilds(factory, model.ID, childrens);
                            foreach (var c in childrens)
                            {
                                //清除缓存
                                if ((c.IsCache ?? 0) == 1)
                                {
                                    Manage.Open.CacheshipFactory.Instance.ClearDictionaryCache(c.DictType);
                                }

                                factory.Delete <Sys_DictionaryEntity>(c, false);
                            }
                        }
                    }
                    factory.Commit();
                }
                catch (Exception ex)
                {
                    factory.Rollback();
                    throw ex;
                }
            }
        }
Example #9
0
 public static int Delete(object primaryKey)
 {
     return(BaseAccess <TEntity, TFileFields> .Delete(primaryKey));
 }