public ActionResult Subjects_Select(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 = 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));
                }

                return(View(new GridModel <FeaturePermissionGridRowModel> {
                    Data = featurePermissions
                }));
            }
            finally
            {
                featureManager?.Dispose();
                featurePermissionManager?.Dispose();
                subjectManager?.Dispose();
            }
        }
Beispiel #2
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();
            }
        }