Exemplo n.º 1
0
        private List <int> GetPermissionMembersID(ISession session, int CommunityID, string ServiceCode, int Permission)
        {
            iCommunity community = session.Get <Community>(CommunityID);

            if (community == null && CommunityID == 0)
            {
                return(GetPortalPermissionMembersID(session, ServiceCode, Permission));
            }
            else if (community == null)
            {
                return(new List <int>());
            }

            iModuleDefinition CommunityModule;

            try
            {
                CommunityModule = (from cModule in session.Linq <CommunityModuleAssociation>()
                                   where cModule.Enabled && cModule.Service.Available && cModule.Community == community && cModule.Service.Code == ServiceCode
                                   select cModule.Service).FirstOrDefault <ModuleDefinition>();
            }
            catch (Exception ex)
            {
                CommunityModule = null;
            }

            if (CommunityModule == null)
            {
                return(new List <int>());
            }
            else
            {
                //Find all Role perission for the input community and the input service
                List <CommunityRoleModulePermission> RolePermissionList = (from crmp in session.Linq <CommunityRoleModulePermission>()
                                                                           where crmp.Community == community && crmp.Service == CommunityModule
                                                                           select crmp).ToList <CommunityRoleModulePermission>();
                // Find ONLY roles !
                List <int> RolesList = (from o in RolePermissionList
                                        where PermissionHelper.CheckPermissionSoft(Permission, o.PermissionInt)
                                        select o.Role.Id).ToList <int>();

                if (RolesList.Count == 0)
                {
                    return(new List <int>());
                }
                else
                {
                    List <int> UsersID = (from Subscription sub in session.Linq <Subscription>()
                                          where sub.Community == community && sub.Accepted && sub.Enabled && sub.Role.Id > 0 && RolesList.Contains(sub.Role.Id)
                                          select sub.Person.Id).ToList <int>();

                    return(UsersID);
                }
            }
        }
Exemplo n.º 2
0
        public List <int> GetCommunityMembersID(int CommunityID)
        {
            using (ISession session = NHSessionHelper.GetSession())
            {
                DataContext dc        = new DataContext(session);
                iCommunity  community = dc.GetById <Community>(CommunityID);
                List <int>  Members   = (from sub in session.Linq <Subscription>() where sub.Community == community && sub.Enabled && sub.Enabled && sub.Role.Id > 0  select sub.Person.Id).ToList <int>();

                return(Members);
            }
        }
Exemplo n.º 3
0
        //private bool RepositoryUserIsInRole(ISession session, int UserID,int RoleID, long FatherID,int CommunityID, int Permission)
        //{
        //    bool iResponse = false;
        //    if (FatherID == 0)
        //        iResponse = true;
        //    else
        //    {
        //        while (FatherID > 0)
        //        {
        //            CommunityFile oFolder = session.Get<CommunityFile>(FatherID);
        //            if (oFolder != null)
        //            {
        //                iResponse = (from ca in session.Linq<CommunityFileCommunityAssignment>() where ca.AssignedTo == oFolder.CommunityOwner && ca.File == oFolder && ca.Deny == false select ca.AssignedTo.Id).Any();
        //                if (iResponse == false && CommunityID==0)
        //                    iResponse = (from ca in session.Linq<CommunityFilePersonTypeAssignment>() where ca.AssignedTo == RoleID && ca.File == oFolder && ca.Deny == false select ca.AssignedTo).Any();
        //                else if (iResponse == false && CommunityID > 0)
        //                    iResponse = (from ca in session.Linq<CommunityFileRoleAssignment>() where ca.AssignedTo.Id  == RoleID && ca.File == oFolder && ca.Deny == false select ca.AssignedTo).Any();

        //                if (!iResponse)
        //                    iResponse = (from ca in session.Linq<CommunityFilePersonAssignment>() where ca.AssignedTo.Id == UserID && ca.File == oFolder && ca.Deny == false select ca.AssignedTo).Any();
        //            }
        //            else
        //                iResponse = false;
        //            if (iResponse)
        //                FatherID = oFolder.FolderId;
        //            else
        //                FatherID = 0;
        //        }
        //    }
        //    return iResponse;
        //}
        private List <int> GetByRolePermissionMembersID(ISession session, int idCommunity, string moduleCode, List <int> AssignedRoles, int Permission)
        {
            iCommunity community = session.Get <Community>(idCommunity);

            if (community == null && idCommunity == 0)
            {
                return(GetByTypePermissionMembersID(session, moduleCode, AssignedRoles, Permission));
            }
            else if (community == null)
            {
                return(new List <int>());
            }

            iModuleDefinition CommunityModule;

            try
            {
                CommunityModule = (from cModule in session.Linq <CommunityModuleAssociation>()
                                   where cModule.Enabled && cModule.Service.Available && cModule.Community == community && cModule.Service.Code == moduleCode
                                   select cModule.Service).FirstOrDefault <ModuleDefinition>();
            }
            catch (Exception ex)
            {
                CommunityModule = null;
            }

            if (CommunityModule == null)
            {
                return(new List <int>());
            }
            else
            {
                //Find all Role perission for the input community and the input service
                List <CommunityRoleModulePermission> RolePermissionList = (from crmp in session.Linq <CommunityRoleModulePermission>()
                                                                           where crmp.Community == community && crmp.Service == CommunityModule && AssignedRoles.Contains(crmp.Role.Id)
                                                                           select crmp).ToList <CommunityRoleModulePermission>();
                // Find ONLY roles !
                List <int> RolesList = (from o in RolePermissionList
                                        where PermissionHelper.CheckPermissionSoft(Permission, o.PermissionInt)
                                        select o.Role.Id).ToList <int>();

                if (RolesList.Count == 0)
                {
                    return(new List <int>());
                }
                else
                {
                    return((from LazySubscription sub in session.Linq <LazySubscription>()
                            where sub.IdCommunity == idCommunity && sub.Accepted && sub.Enabled && sub.IdRole > 0 && RolesList.Contains(sub.IdRole)
                            select sub.IdPerson).ToList().Distinct().ToList());
                }
            }
        }
Exemplo n.º 4
0
        public List <int> GetCommunityRoleMembersID(int CommunityID, int RoleID)
        {
            using (ISession session = NHSessionHelper.GetSession())
            {
                DataContext dc      = new DataContext(session);
                List <int>  Members = new List <int>();
                if (CommunityID == 0)
                {
                    Members = (from p in session.Linq <Person>() where p.TypeID == RoleID && p.isDisabled == false select p.Id).ToList <int>();
                }
                else
                {
                    iCommunity community = dc.GetById <Community>(CommunityID);
                    Members = (from sub in session.Linq <Subscription>() where sub.Community == community && sub.Enabled && sub.Enabled && sub.Role.Id == RoleID select sub.Person.Id).ToList <int>();
                }

                return(Members);
            }
        }
Exemplo n.º 5
0
        public List <int> GetPermissionMembersID(int CommunityID, int ServiceID, int Permission)
        {
            using (ISession session = NHSessionHelper.GetSession())
            {
                DataContext dc        = new DataContext(session);
                iCommunity  community = dc.GetById <Community>(CommunityID);
                if (community == null && CommunityID == 0)
                {
                    return(GetPortalPermissionMembersID(ServiceID, Permission));
                }
                else if (community == null)
                {
                    return(new List <int>());
                }

                iModuleDefinition CommunityModule;
                try{
                    CommunityModule = (from cModule in session.Linq <CommunityModuleAssociation>()
                                       where cModule.Enabled && cModule.Service.Available && cModule.Community == community && cModule.Service.Id == ServiceID
                                       select cModule.Service).FirstOrDefault <ModuleDefinition>();
                }
                catch (Exception ex) {
                    CommunityModule = null;
                }

                if (CommunityModule == null)
                {
                    return(new List <int>());
                }
                else
                {
                    //Find all Role perission for the input community and the input service
                    List <CommunityRoleModulePermission> RolePermissionList = (from crmp in session.Linq <CommunityRoleModulePermission>()
                                                                               where crmp.Community == community && crmp.Service == CommunityModule
                                                                               select crmp).ToList <CommunityRoleModulePermission>();
                    // Find ONLY roles !
                    List <int> RolesList = (from o in RolePermissionList
                                            where PermissionHelper.CheckPermissionSoft(Permission, o.PermissionInt)
                                            select o.Role.Id).ToList <int>();

                    if (RolesList.Count == 0)
                    {
                        return(new List <int>());
                    }
                    else
                    {
                        //List<int> UsersID = (from r in RolesList
                        //                     join Subscription sub in session.Linq<Subscription>() on r equals sub.Role
                        //                     where sub.Community == community && sub.Accepted && sub.Enabled && sub.Role.Id > 0
                        //                     select sub.Person.Id)..ToList<int>();

                        List <SmallRolePerson> rpList = (from Subscription sub in session.Linq <Subscription>()
                                                         where sub.Community == community && sub.Accepted && sub.Enabled && sub.Role.Id > 0 && RolesList.Contains(sub.Role.Id)
                                                         select new SmallRolePerson(sub.Role.Id, sub.Person.Id)).ToList <SmallRolePerson>();

                        List <int> UsersID = (from Subscription sub in session.Linq <Subscription>()
                                              where sub.Community == community && sub.Accepted && sub.Enabled && sub.Role.Id > 0 && RolesList.Contains(sub.Role.Id)
                                              select sub.Person.Id).ToList <int>();

                        //(from roleID in RolesList
                        //                 join SmallRolePerson rp in rpList on roleID equals rp.RoleID
                        //                 select rp.PersonID).ToList<int>();
                        return(UsersID);
                    }
                }
            }
        }