Beispiel #1
0
        public bool IsUserRoleForCHGSite(long userId, long CHGSiteId, long roleId)
        {
            var roleEntity = UserRoleTypes.Find(roleId);

            //Check for CRO
            if (roleEntity.Name == "CRO")
            {
                return(true);
            }

            //Check for CAC
            if (roleEntity.Name == "CAC")
            {
                return(true);
            }

            //Check for CEO and DBD
            if (roleEntity.Name == "CEO" || roleEntity.Name == "DBD")
            {
                return(UserCHGSites.Where(p => p.UserId == UserId && p.Deleted == false && p.CHGSiteId == CHGSiteId).Count() > 0);
            }


            var items = (
                from os in OrganizationServiceTypes
                join rs in RegionServiceTypes on os.ServiceTypeId equals rs.ServiceTypeId
                join s in CHGSites on rs.RegionTypeId equals s.RegionTypeId
                where
                os.Deleted == false &&
                rs.Deleted == false &&
                s.Deleted == false
                select new
            {
                OrganizationId = os.OrganizationId,
                ServiceTypeId = os.ServiceTypeId,
                RegionTypeId = rs.RegionTypeId,
                CHGSiteId = s.CHGSiteId
            }).ToList();

            //Check for AVP
            if (roleEntity.Name == "AVP")
            {
                return((from c in UserRegions.Where(p => p.Deleted == false).ToList() join ur in UserRoles on c.UserId equals ur.UserId join i in items on c.RegionTypeId equals i.RegionTypeId where c.Deleted == false && c.UserId == userId && i.CHGSiteId == CHGSiteId && ur.User.Deleted == false && ur.User.Enabled == true && ur.UserRoleTypeId == roleId select c).Count() > 0);
            }

            //Add more permission checks here.

            return(false);
        }
Beispiel #2
0
        public List <User> GetRoleUsersForCHGSite(long CHGSiteId, long roleId)
        {
            var roleEntity = UserRoleTypes.Find(roleId);

            //Check for CRO
            if (roleEntity.Name == "CRO")
            {
                return(UserRoles.Include("UserRoleType").Include("User").Where(p => p.Deleted == false && p.UserRoleType.Name == "CRO" && p.User.Deleted == false && p.User.Enabled == true).Select(p => p.User).ToList());
            }

            if (roleEntity.Name == "CAC")
            {
                return(UserRoles.Include("UserRoleType").Include("User").Where(p => p.Deleted == false && p.UserRoleType.Name == "CAC" && p.User.Deleted == false && p.User.Enabled == true).Select(p => p.User).ToList());
            }


            if (roleEntity.Name == "CEO" || roleEntity.Name == "DBD")
            {
                return((from ur in UserRoles join us in UserCHGSites on ur.UserId equals us.UserId where us.Deleted == false && ur.Deleted == false && ur.UserRoleTypeId == roleId && us.CHGSiteId == CHGSiteId && us.User.Deleted == false && us.User.Enabled == true select us.User).Distinct().ToList());
            }


            var items = (
                from os in OrganizationServiceTypes
                join rs in RegionServiceTypes on os.ServiceTypeId equals rs.ServiceTypeId
                join s in CHGSites on rs.RegionTypeId equals s.RegionTypeId
                where
                os.Deleted == false &&
                rs.Deleted == false &&
                s.Deleted == false
                select new
            {
                OrganizationId = os.OrganizationId,
                ServiceTypeId = os.ServiceTypeId,
                RegionTypeId = rs.RegionTypeId,
                CHGSiteId = s.CHGSiteId
            }).ToList();


            if (roleEntity.Name == "AVP")
            {
                return((from u in UserRegions.Where(p => p.Deleted == false).ToList() join ur in UserRoles on u.UserId equals ur.UserId join i in items on u.RegionTypeId equals i.RegionTypeId where u.Deleted == false && i.CHGSiteId == CHGSiteId && ur.Deleted == false && ur.User.Deleted == false && ur.User.Enabled == true && ur.UserRoleTypeId == roleId select u.User).Distinct().ToList());
            }

            return(null);
        }
Beispiel #3
0
 public UserRoleType GetRole(long roleId)
 {
     return(UserRoleTypes.Find(roleId));
 }