Exemple #1
0
        public ActionResult Groups_Select(GridCommand command)
        {
            var groupManager = new GroupManager();

            try
            {
                var groups = new List <GroupGridRowModel>();
                int count  = groupManager.Groups.Count();
                if (command != null)// filter subjects based on grid filter settings
                {
                    FilterExpression  filter  = TelerikGridHelper.Convert(command.FilterDescriptors.ToList());
                    OrderByExpression orderBy = TelerikGridHelper.Convert(command.SortDescriptors.ToList());

                    groups = groupManager.GetGroups(filter, orderBy, command.Page, command.PageSize, out count).Select(GroupGridRowModel.Convert).ToList();
                }
                else
                {
                    groups = groupManager.Groups.Select(GroupGridRowModel.Convert).ToList();
                    count  = groupManager.Groups.Count();
                }

                return(View(new GridModel <GroupGridRowModel> {
                    Data = groups, Total = count
                }));
            }
            finally
            {
                groupManager.Dispose();
            }
        }
        public ActionResult Subjects_Select(GridCommand command, long entityId, long instanceId)
        {
            var subjectManager          = new SubjectManager();
            var entityPermissionManager = new EntityPermissionManager();

            try
            {
                var subjectsDb = new List <Subject>();
                var count      = 0;
                if (command != null)// filter subjects based on grid filter settings
                {
                    FilterExpression  filter  = TelerikGridHelper.Convert(command.FilterDescriptors.ToList());
                    OrderByExpression orderBy = TelerikGridHelper.Convert(command.SortDescriptors.ToList());

                    subjectsDb = subjectManager.GetSubjects(filter, orderBy, command.Page, command.PageSize, out count);
                }
                else
                {
                    subjectsDb = subjectManager.Subjects.ToList();
                    count      = subjectsDb.Count();
                }

                var subjects = new List <EntityPermissionGridRowModel>();
                //using (PartyManager partyManager = new PartyManager())

                //foreach (var subject in subjectsDb)
                //{
                //    var rights = entityPermissionManager.GetRights(subject.Id, entityId, instanceId);
                //    var effectiveRights = entityPermissionManager.GetEffectiveRights(subject.Id, entityId, instanceId);

                //    subjects.Add(EntityPermissionGridRowModel.Convert(subject, rights, effectiveRights));
                //}

                var rightsDic          = entityPermissionManager.GetRights(subjectsDb, entityId, instanceId);
                var effectiveRightsDic = entityPermissionManager.GetEffectiveRights(subjectsDb, entityId, instanceId);

                foreach (var item in rightsDic)
                {
                    var subject         = subjectsDb.Where(s => s.Id.Equals(item.Key)).FirstOrDefault();
                    var rights          = item.Value;
                    var effectiveRights = effectiveRightsDic[item.Key];

                    subjects.Add(EntityPermissionGridRowModel.Convert(subject, rights, effectiveRights));
                }

                return(View(new GridModel <EntityPermissionGridRowModel> {
                    Data = subjects, Total = count
                }));
            }
            finally
            {
                subjectManager.Dispose();
                entityPermissionManager.Dispose();
            }
        }
Exemple #3
0
        public ActionResult Subjects_Select(GridCommand command, long featureId)
        {
            FeaturePermissionManager featurePermissionManager = null;
            SubjectManager           subjectManager           = null;
            FeatureManager           featureManager           = null;

            try
            {
                featurePermissionManager = new FeaturePermissionManager();
                subjectManager           = new SubjectManager();
                featureManager           = new FeatureManager();

                var feature = featureManager.FindById(featureId);

                var featurePermissions = new List <FeaturePermissionGridRowModel>();

                if (feature == null)
                {
                    return(View(new GridModel <FeaturePermissionGridRowModel> {
                        Data = featurePermissions
                    }));
                }

                var subjects = new List <Subject>();
                int count    = subjectManager.Subjects.Count();
                ViewData["subjectsGridTotal"] = count;
                if (command != null)// filter subjects based on grid filter settings
                {
                    FilterExpression  filter  = TelerikGridHelper.Convert(command.FilterDescriptors.ToList());
                    OrderByExpression orderBy = TelerikGridHelper.Convert(command.SortDescriptors.ToList());

                    subjects = subjectManager.GetSubjects(filter, orderBy, command.Page, command.PageSize, out count);
                }
                else
                {
                    subjects = subjectManager.Subjects.ToList();
                }


                //foreach (var subject in subjects)
                //{
                //    var rightType = featurePermissionManager.GetPermissionType(subject.Id, feature.Id);
                //    var hasAccess = featurePermissionManager.HasAccess(subject.Id, feature.Id);

                //    featurePermissions.Add(FeaturePermissionGridRowModel.Convert(subject, featureId, rightType, hasAccess));
                //}

                var subjectIds        = subjects.Select(s => s.Id);
                var userPermissionDic = featurePermissionManager.GetPermissionType(subjectIds, feature.Id);
                var userHasAccessDic  = featurePermissionManager.HasAccess(subjects, feature.Id);

                foreach (var item in userPermissionDic)
                {
                    var subject   = subjects.Where(s => s.Id.Equals(item.Key)).FirstOrDefault();
                    var rightType = item.Value;
                    var hasAccess = userHasAccessDic[item.Key];

                    featurePermissions.Add(FeaturePermissionGridRowModel.Convert(subject, featureId, rightType, hasAccess));
                }


                return(View(new GridModel <FeaturePermissionGridRowModel> {
                    Data = featurePermissions, Total = count
                }));
            }
            finally
            {
                featureManager?.Dispose();
                featurePermissionManager?.Dispose();
                subjectManager?.Dispose();
            }
        }