コード例 #1
0
        private void SetRights(Entities objectContext, Role currRole)
        {
            Tools.CheckObjectContext(objectContext);
            if (currRole == null)
            {
                throw new ArgumentNullException("currRole");
            }

            Role_Right currRight = objectContext.Role_RightSet.FirstOrDefault(rr => rr.Right.ID == UserRights.SearchForUsers && rr.Role.ID == currRole.ID);
            if (currRight == null)
            {
                throw new InvalidOperationException("role doesn't have set right ID : 1");
            }

            searchForUsersEnabled = currRight.enabled;
            searchForUsersVisible = currRight.visible;

            currRight = objectContext.Role_RightSet.FirstOrDefault(rr => rr.Right.ID == UserRights.AddReport && rr.Role.ID == currRole.ID);
            if (currRight == null)
            {
                throw new InvalidOperationException("role doesn't have set right ID : 2");
            }

            addReportEnabled = currRight.enabled;
            addReportVisible = currRight.visible;

            currRight = objectContext.Role_RightSet.FirstOrDefault(rr => rr.Right.ID == UserRights.SeeVisibleReports && rr.Role.ID == currRole.ID);
            if (currRight == null)
            {
                throw new InvalidOperationException("role doesn't have set right ID : 3");
            }

            seeVisibleReportsEnabled = currRight.enabled;
            seeVisibleReportsVisible = currRight.visible;

            currRight = objectContext.Role_RightSet.FirstOrDefault(rr => rr.Right.ID == UserRights.SeeDeletedReports && rr.Role.ID == currRole.ID);
            if (currRight == null)
            {
                throw new InvalidOperationException("role doesn't have set right ID : 4");
            }

            seeDeletedReportsEnabled = currRight.enabled;
            seeDeletedReportsVisible = currRight.visible;

            currRight = objectContext.Role_RightSet.FirstOrDefault(rr => rr.Right.ID == UserRights.MarkReportAsSolved && rr.Role.ID == currRole.ID);
            if (currRight == null)
            {
                throw new InvalidOperationException("role doesn't have set right ID : 5");
            }

            markReportAsResolvedEnabled = currRight.enabled;
            markReportAsResolvedVisible = currRight.visible;

            currRight = objectContext.Role_RightSet.FirstOrDefault(rr => rr.Right.ID == UserRights.DeleteReports && rr.Role.ID == currRole.ID);
            if (currRight == null)
            {
                throw new InvalidOperationException("role doesn't have set right ID : 6");
            }

            deleteReportEnabled = currRight.enabled;
            deleteReportVisible = currRight.visible;
        }