Example #1
0
        public static List <PermEx> GetRolePerms(string RoleName)
        {
            using (UserRoleDBDataContext Context = new UserRoleDBDataContext(ConStr))
            {
                Context.DeferredLoadingEnabled = false;

                return(Context.ExecuteQuery <PermEx>(@"SELECT P.PermName, ISNULL(RP.Reading,0) Reading, 
                ISNULL(RP.Writing,0) as Writing, ISNULL(RP.Updating,0) as Updating, 
                ISNULL(RP.Deleting,0) as Deleting, P.[Group], 
                CASE P.[Type] WHEN 0 THEN 'Form' WHEN 1 THEN 'Kontrol' ELSE 'None' END as Tip  
                FROM usr.Perm(nolock) P 
                LEFT JOIN usr.RolePerm(nolock) RP ON P.PermName=RP.PermName AND RP.RoleName={0} 
                WHERE P.Active=1", RoleName).ToList());
            }
        }
Example #2
0
        public static bool InsertUpdateRolePerm(string rolName, List <PermEx> rolePermList, string userID = "")
        {
            using (TransactionScope Scope = new TransactionScope())
            {
                using (UserRoleDBDataContext Context = new UserRoleDBDataContext(ConStr))
                {
                    List <MUser> UserList = Context.ExecuteQuery <MUser>("SELECT Kod FROM usr.Users(Nolock) WHERE RoleName={0} AND Admin=0", rolName).ToList();

                    foreach (PermEx rPerm in rolePermList)
                    {
                        Context.ExecuteCommand(@"IF (SELECT COUNT(ID) FROM usr.RolePerm (Nolock) WHERE RoleName={0} AND PermName={1})=0
                        INSERT INTO usr.RolePerm (RoleName, PermName, Reading, Writing, Updating, Deleting, RecordUser, ModifiedUser) 
                                    VALUES ({0}, {1}, {2}, {3}, {4}, {5}, {6}, {6})
                        ELSE
                        UPDATE usr.RolePerm SET Reading={2}, Writing={3}, Updating={4}, Deleting={5}, 
                               ModifiedDate=Getdate(), ModifiedUser={6} 
                               WHERE RoleName={0} AND PermName={1}"
                                               , rolName, rPerm.PermName, rPerm.Reading, rPerm.Writing, rPerm.Updating, rPerm.Deleting, userID);


                        foreach (var user in UserList)
                        {
                            Context.ExecuteCommand(@"IF (SELECT COUNT(UserName) FROM usr.UserPerm(Nolock) WHERE UserName={0} AND PermName={1})=0
                            INSERT INTO usr.UserPerm (UserName, PermName, Reading, Writing, Updating, Deleting, RecordUser, ModifiedUser) 
                                        VALUES ({0}, {1}, {2}, {3}, {4}, {5}, {6}, {6})
                            ELSE
                            UPDATE usr.UserPerm SET Reading={2}, Writing={3}, Updating={4}, Deleting={5}, 
                                   ModifiedDate=GetDate(), ModifiedUser={6} 
                                   WHERE UserName={0} AND PermName={1}"
                                                   , user.Kod, rPerm.PermName, rPerm.Reading, rPerm.Writing, rPerm.Updating, rPerm.Deleting, userID);
                        }
                    }
                }

                Scope.Complete();
            }
            return(true);
        }
Example #3
0
        public static List <UserPerm> LoginYetkileriniGetir(int tip, string sirketKodu, string userName)
        {
            using (UserRoleDBDataContext Context = new UserRoleDBDataContext(ConStr))
            {
                Context.DeferredLoadingEnabled = false;
                //return Context.UserPerms.Where(x=> x.UserName == userName).ToList();
                return(Context.ExecuteQuery <UserPerm>(@"
                SELECT {0} as UserName, P.PermName,  
                        CASE WHEN (Select Admin From usr.Users(Nolock) Where Kod={0} AND Sirket={1} AND Tip={2})=1 
	                    THEN Cast(1 as Bit) ELSE ISNULL(UP.Reading,0) END Reading,
	                   
                        CASE WHEN (Select Admin From usr.Users(Nolock) Where Kod={0} AND Sirket={1} AND Tip={2})=1 
	                    THEN Cast(1 as Bit) ELSE ISNULL(UP.Writing,0) END Writing,
                       
                        CASE WHEN (Select Admin From usr.Users(Nolock) Where Kod={0} AND Sirket={1} AND Tip={2})=1 
	                    THEN Cast(1 as Bit) ELSE ISNULL(UP.Updating,0) END Updating,
	                   
                        CASE WHEN (Select Admin From usr.Users(Nolock) Where Kod={0} AND Sirket={1} AND Tip={2})=1 
	                    THEN Cast(1 as Bit) ELSE ISNULL(UP.Deleting,0) END Deleting
                FROM usr.Perm (Nolock) P 
                LEFT JOIN usr.UserPerm (Nolock) UP ON P.PermName=UP.PermName AND UP.UserName={0}"
                                                       , userName, sirketKodu, tip).ToList());
            }
        }