public bool SetUserRole(int userId, List <int> selectRoleIds)
        {
            //查询出当前设置角色的用户
            var user = CurrentDbSession.UserDal.LoadEntities(u => u.Id == userId).FirstOrDefault();

            //如果用户之前已经有了角色。先把之前的角色都清空掉。
            if (user != null)
            {
                user.Role.Clear();//EF内部处理了两个集合的变化。
                //e.g  start set{1,2,3}  and  final set{1,2,4}
                //要从第一个集合删除3,第二个集合加上4.这个过程比较复杂。
                //可以像上面那样处理,另一种处理就是清空用户原有的角色,把所有新的final set角色id加给用户

                //把用户已有的角色查询出来。
                var allRoles = CurrentDbSession.RoleDal.LoadEntities(r => selectRoleIds.Contains(r.Id)).ToList();

                foreach (var roleInfo in allRoles)
                {
                    user.Role.Add(roleInfo);
                }

                //foreach (int roleId in selectRoleIds)
                //{
                //    var roleInfo =DbSession.RoleDal.LoadEntities(r => r.Id == roleId).FirstOrDefault();
                //    user.Role.Add(roleInfo);
                //}
            }
            return(CurrentDbSession.SaveChanges() > 0);
        }
Ejemplo n.º 2
0
        //public IDbSession CurrentDbSession
        //{
        //    get
        //    {
        //        //return new DbSession();//暂时
        //        return DbSessionFactory.GetCurrentDbSession();
        //    }
        //}


        //protected IDbSession CurrentDbSession;//当前类或者是子类
        //protected BaseService()
        //{
        //    //CurrentDbSession = DbSessionFactory.GetCurrentDbSession();
        //    SetCurrentDal();//构造函数里面调用了 抽象方法:SetCurrentDal
        //}



        public T Add(T entity)
        {
            CurrentDal.Add(entity);
            CurrentDbSession.SaveChanges();
            return(entity);
            //return CurrentDbSession.UserDal.Add(entity);
        }
Ejemplo n.º 3
0
        public bool DeleteUserInfoList(List <int> list)
        {
            var userInfoList = CurrentDal.LoadEntities(u => list.Contains(u.ID));

            foreach (var userInfo in userInfoList)
            {
                CurrentDal.DeleteEntities(userInfo);
            }
            return(CurrentDbSession.SaveChanges());
        }
Ejemplo n.º 4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="roleId"></param>
        /// <param name="list">被选中的权限ID</param>
        /// <returns></returns>
        public bool SetRoleActionInfo(int roleId, List <int> list)
        {
            var roleInfo = this.CurrentDbSession.RoleInfoDal.LoadEntities(u => u.ID == roleId).FirstOrDefault();

            if (roleInfo != null)
            {
                roleInfo.ActionInfo.Clear();
                foreach (var actionID in list)
                {
                    var actionInfo = this.CurrentDbSession.ActionInfoDal.LoadEntities(u => u.ID == actionID).FirstOrDefault();
                    roleInfo.ActionInfo.Add(actionInfo);
                }
            }
            return(CurrentDbSession.SaveChanges());
        }
Ejemplo n.º 5
0
        public bool ClearUserActionInfo(int actionId, int userId)
        {
            var userActionInfo = this.CurrentDbSession.R_UserInfo_ActionInfoDal.LoadEntities(u => u.ActionInfoID == actionId && u.UserInfoID == userId).FirstOrDefault();

            if (userActionInfo != null)
            {
                this.CurrentDbSession.R_UserInfo_ActionInfoDal.DeleteEntities(userActionInfo);
            }
            else
            {
                return(false);
            }

            return(CurrentDbSession.SaveChanges());
        }
Ejemplo n.º 6
0
        public bool SetUserRoleInfo(int userId, List <int> roleIdList)
        {
            //找到userID的用户,再通过roleIDList将用户的角色改了(添加或者删除)
            var userinfo = this.CurrentDal.LoadEntities(u => u.ID == userId).FirstOrDefault();

            if (userinfo != null)
            {
                userinfo.RoleInfo.Clear();
                foreach (var roleId in roleIdList)
                {
                    var role = this.CurrentDbSession.RoleInfoDal.LoadEntities(u => u.ID == roleId).FirstOrDefault();
                    userinfo.RoleInfo.Add(role);
                }
            }
            return(CurrentDbSession.SaveChanges());
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 为角色分配权限
        /// </summary>
        /// <param name="roleId">角色编号</param>
        /// <param name="actionIdList">权限编号列表</param>
        /// <returns></returns>
        public bool SetRoleActionInfo(int roleId, List <int> actionIdList)
        {
            //获取角色信息.
            var role = CurrentDbSession.RoleDal.LoadEntities(r => r.Id == roleId).FirstOrDefault();

            if (role != null)
            {
                role.ActionInfo.Clear();
                foreach (int actionId in actionIdList)
                {
                    var actionInfo = CurrentDbSession.ActionInfoDal.LoadEntities(a => a.Id == actionId).FirstOrDefault();
                    role.ActionInfo.Add(actionInfo);
                }
                return(CurrentDbSession.SaveChanges() > 0);
            }
            return(false);
        }
        public bool SetUserActionInfo(int actionId, int userId, bool isPass)
        {
            //判断userId以前是否有了该actionId,如果有了只需要修改isPass状态,否则插入。
            var r_userInfo_actionInfo = CurrentDbSession.R_User_ActionInfoDal.LoadEntities(a => a.ActionInfoId == actionId && a.UserId == userId).FirstOrDefault();

            if (r_userInfo_actionInfo == null)
            {
                R_User_ActionInfo userInfoActionInfo = new R_User_ActionInfo();
                userInfoActionInfo.ActionInfoId = actionId;
                userInfoActionInfo.UserId       = userId;
                userInfoActionInfo.IsPass       = isPass;
                CurrentDbSession.R_User_ActionInfoDal.Add(userInfoActionInfo);
            }
            else
            {
                r_userInfo_actionInfo.IsPass = isPass;
                CurrentDbSession.R_User_ActionInfoDal.Update(r_userInfo_actionInfo);
            }
            return(CurrentDbSession.SaveChanges() > 0);
        }
        //最不能用的。纯菜鸟
        //UserDal dal =new UserDal();

        //一般鸟
        //private IUserDal dal = new Guanghui.OA.EFDAL.UserDal();

        //private IUserDal dal = new Guanghui.OA.ADONETDAL.UserDal();

        //鸟:
        //private IUserDal dal = DalFactory.GetUserDal();//走了抽象工厂了。


        //private IUserDal dal;
        //private IDbSession dbSession;
        //public UserService()
        //{
        //    dbSession = DbSessionFactory.GetCurrentDbSession();
        //     dal= dbSession.UserDal;
        //}


        ////依赖注入。Spring.Net


        //public User Add(User user)
        //{
        //    //一个业务方法,一般都会操作多个表。


        //     dal.Add(user);
        //     dbSession.SaveChanges();
        //    dal.Delete(user);
        //    dal.Update(user);
        //    dbSession.SaveChanges();

        //    return user;

        //}
        #endregion

        #region 批量删除
        public int DeleteUsers(IList <int> ids)
        {
            //foreach (var id in ids)
            //{
            //    var user = DbSession.UserDal.LoadEntities(u => u.Id == id).FirstOrDefault();
            //    if (user != null)
            //    {
            //        user.DelFlag = (short)Guanghui.OA.Model.Enum.DelFlagEnum.Deleted;
            //    }
            //}
            //return DbSession.SaveChanges();

            var userList = CurrentDbSession.UserDal.LoadEntities(u => ids.Contains(u.Id));

            foreach (var user in userList)
            {
                //DbSession.UserDal.Delete(user);
                user.DelFlag = (short)Guanghui.OA.Model.Enum.DelFlagEnum.Deleted;
            }
            return(CurrentDbSession.SaveChanges());
        }
Ejemplo n.º 10
0
        //最不能用的。纯菜鸟
        //RoleDal dal =new RoleDal();

        //一般鸟
        //private IRoleDal dal = new Guanghui.OA.EFDAL.RoleDal();

        //private IRoleDal dal = new Guanghui.OA.ADONETDAL.RoleDal();

        //鸟:
        //private IRoleDal dal = DalFactory.GetRoleDal();//走了抽象工厂了。


        //private IRoleDal dal;
        //private IDbSession dbSession;
        //public RoleService()
        //{
        //    dbSession = DbSessionFactory.GetCurrentDbSession();
        //     dal= dbSession.RoleDal;
        //}


        ////依赖注入。Spring.Net


        //public Role Add(Role Role)
        //{
        //    //一个业务方法,一般都会操作多个表。


        //     dal.Add(Role);
        //     dbSession.SaveChanges();
        //    dal.Delete(Role);
        //    dal.Update(Role);
        //    dbSession.SaveChanges();

        //    return Role;

        //}
        #endregion

        #region 批量删除
        public int DeleteRoles(IList <int> ids)
        {
            //foreach (var id in ids)
            //{
            //    var role = DbSession.RoleDal.LoadEntities(u => u.Id == id).FirstOrDefault();
            //    if (role != null)
            //    {
            //        role.DelFlag = (short)Guanghui.OA.Model.Enum.DelFlagEnum.Deleted;
            //    }
            //}
            //return DbSession.SaveChanges();

            var roles = CurrentDbSession.RoleDal.LoadEntities(u => ids.Contains(u.Id));

            foreach (var role in roles)
            {
                //role.DelFlag = (short)Guanghui.OA.Model.Enum.DelFlagEnum.Deleted;
                //DbSession.RoleDal.Delete(role);
            }
            return(CurrentDbSession.SaveChanges());
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 实现radio按钮的禁止允许
        /// </summary>
        /// <param name="actionId">权限编号</param>
        /// <param name="userId">用户编号</param>
        /// <param name="isPass"></param>
        /// <returns></returns>
        public bool SetUserActionInfo(int actionId, int userId, bool isPass)
        {
            //var userInfo = this.CurrentDbSession.UserInfoDal.LoadEntities(u=>u.ID==userId).FirstOrDefault();
            //var isExt = (from a in userInfo.R_UserInfo_ActionInfo
            //            where a.ActionInfoID == actionId
            //            select a).FirstOrDefault();

            var isExt = this.CurrentDbSession.R_UserInfo_ActionInfoDal.LoadEntities(u => u.UserInfoID == userId && u.ActionInfoID == actionId).FirstOrDefault();

            if (isExt != null)
            {
                isExt.IsPass = isPass;
                this.CurrentDbSession.R_UserInfo_ActionInfoDal.EditEntities(isExt);
            }
            else
            {
                R_UserInfo_ActionInfo r_UserInfo_ActionInfo = new R_UserInfo_ActionInfo();
                r_UserInfo_ActionInfo.ActionInfoID = actionId;
                r_UserInfo_ActionInfo.UserInfoID   = userId;
                r_UserInfo_ActionInfo.IsPass       = isPass;
                this.CurrentDbSession.R_UserInfo_ActionInfoDal.AddEntities(r_UserInfo_ActionInfo);
            }
            return(CurrentDbSession.SaveChanges());
        }
Ejemplo n.º 12
0
 /// <summary>
 /// 添加数据
 /// </summary>
 /// <param name="entity"></param>
 /// <returns></returns>
 public T AddEntity(T entity)
 {
     CurrentDal.AddEntity(entity);
     CurrentDbSession.SaveChanges();
     return(entity);
 }
Ejemplo n.º 13
0
 /// <summary>
 /// 更新
 /// </summary>
 /// <param name="entity"></param>
 /// <returns></returns>
 public bool EditEntity(T entity)
 {
     CurrentDal.EditEntity(entity);
     return(CurrentDbSession.SaveChanges());
 }
Ejemplo n.º 14
0
 /// <summary>
 /// 删除
 /// </summary>
 /// <param name="entity"></param>
 /// <returns></returns>
 public bool DeleteEntity(T entity)
 {
     CurrentDal.DeleteEntity(entity);
     return(CurrentDbSession.SaveChanges());
 }
Ejemplo n.º 15
0
 public bool Update(T entity)
 {
     CurrentDal.Update(entity);
     return(CurrentDbSession.SaveChanges() > 0);
 }