示例#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);
        }
示例#2
0
        public List <CHGSite> GetUserSites(long userId)
        {
            List <CHGSite> sites = new List <CHGSite>();

            foreach (var role in GetUserRoles(userId))
            {
                switch (role.Name)
                {
                case "CRO":
                    sites.AddRange(CHGSites.Where(p => p.Deleted == false).ToList());
                    break;

                case "CAC":
                    sites.AddRange(CHGSites.Where(p => p.Deleted == false).ToList());
                    break;

                case "SLH":
                    sites.AddRange((from c in UserServices.Where(p => p.Deleted == false && p.UserId == userId) join d in CHGSites.Where(p => p.Deleted == false) on c.ServiceTypeId equals d.ServiceTypeId select d).ToList());
                    break;

                case "AVP":
                    sites.AddRange((from c in UserRegions.Where(p => p.Deleted == false && p.UserId == userId) join d in CHGSites.Where(p => p.Deleted == false) on c.RegionTypeId equals d.RegionTypeId select d).ToList());
                    break;

                case "CEO":
                    sites.AddRange((from c in UserCHGSites.Where(p => p.Deleted == false && p.UserId == userId) join d in CHGSites.Where(p => p.Deleted == false) on c.CHGSiteId equals d.CHGSiteId select d).ToList());
                    break;

                case "DBD":
                    sites.AddRange((from c in UserCHGSites.Where(p => p.Deleted == false && p.UserId == userId) join d in CHGSites.Where(p => p.Deleted == false) on c.CHGSiteId equals d.CHGSiteId select d).ToList());
                    break;

                case "CL":
                    sites.AddRange((from c in UserCHGSites.Where(p => p.Deleted == false && p.UserId == userId) join d in CHGSites.Where(p => p.Deleted == false) on c.CHGSiteId equals d.CHGSiteId select d).ToList());
                    break;
                }
            }
            return(sites.Distinct().ToList());
        }