Example #1
0
        private void LoadUserRoles()
        {
            BusinessLogic.UserRoleManager        userRoleManager  = new BusinessLogic.UserRoleManager();
            List <BusinessEntity.UserRoleEntity> userRoleEntities = userRoleManager.GetAll();

            listViewUserRole.Items.Clear();
            if (userRoleEntities == null)
            {
                MessageBox.Show("Sorry database error occured, please try again.");
            }
            else
            {
                foreach (BusinessEntity.UserRoleEntity userRoleEntity in userRoleEntities)
                {
                    ListViewItem item = new ListViewItem(userRoleEntity.ID.ToString());
                    item.SubItems.Add(userRoleEntity.User.Username);
                    item.SubItems.Add(userRoleEntity.Role.Name);

                    listViewUserRole.Items.Add(item);
                }
            }
        }
        public void ApplySecurityRoles(string username)
        {
            BusinessLogic.UserRoleManager        userRoleManager = new BusinessLogic.UserRoleManager();
            List <BusinessEntity.UserRoleEntity> userRoles       = userRoleManager.GetAll().Where(x => x.User.Username == username).ToList();

            //Officer
            manageTraineeToolStripMenuItem.Enabled = false;
            searchTraineeToolStripMenuItem.Enabled = false;

            //Administrator
            manageUserToolStripMenuItem.Enabled = false;

            //Administrator
            toolStripButtonCourse.Enabled = false;

            //Officer
            toolStripButtonTraineeCourse.Enabled = false;

            //Cashier
            toolStripButtonPayment.Enabled = false;

            //reports
            //Officer, Manager, Cashier
            traineeListToolStripMenuItem.Enabled       = false;
            traineeCourseListToolStripMenuItem.Enabled = false;
            traineePaymentToolStripMenuItem.Enabled    = false;

            //Manager
            traineeSummaryByRegistrationDateToolStripMenuItem.Enabled = false;
            traineeSummaryByGenderToolStripMenuItem.Enabled           = false;
            traineeSummaryByAcademicLevelToolStripMenuItem.Enabled    = false;
            traineeSummaryByCourseToolStripMenuItem.Enabled           = false;

            //Cashier, Manager
            paymentSummaryByPaymentDateToolStripMenuItem.Enabled = false;
            paymentSummaryByCourseToolStripMenuItem.Enabled      = false;

            if (userRoles.Where(x => x.Role.Name == "Administrator").Count() > 0)
            {
                manageUserToolStripMenuItem.Enabled = true;

                toolStripButtonCourse.Enabled = true;
            }

            if (userRoles.Where(x => x.Role.Name == "Manager").Count() > 0)
            {
                traineeListToolStripMenuItem.Enabled       = true;
                traineeCourseListToolStripMenuItem.Enabled = true;
                traineePaymentToolStripMenuItem.Enabled    = true;

                traineeSummaryByRegistrationDateToolStripMenuItem.Enabled = true;
                traineeSummaryByGenderToolStripMenuItem.Enabled           = true;
                traineeSummaryByAcademicLevelToolStripMenuItem.Enabled    = true;
                traineeSummaryByCourseToolStripMenuItem.Enabled           = true;

                paymentSummaryByPaymentDateToolStripMenuItem.Enabled = true;
                paymentSummaryByCourseToolStripMenuItem.Enabled      = true;
            }

            if (userRoles.Where(x => x.Role.Name == "Officer").Count() > 0)
            {
                manageTraineeToolStripMenuItem.Enabled = true;
                searchTraineeToolStripMenuItem.Enabled = true;

                toolStripButtonTraineeCourse.Enabled = true;

                traineeListToolStripMenuItem.Enabled       = true;
                traineeCourseListToolStripMenuItem.Enabled = true;
                traineePaymentToolStripMenuItem.Enabled    = true;
            }

            if (userRoles.Where(x => x.Role.Name == "Cashier").Count() > 0)
            {
                toolStripButtonPayment.Enabled = true;

                traineeListToolStripMenuItem.Enabled       = true;
                traineeCourseListToolStripMenuItem.Enabled = true;
                traineePaymentToolStripMenuItem.Enabled    = true;

                paymentSummaryByPaymentDateToolStripMenuItem.Enabled = true;
                paymentSummaryByCourseToolStripMenuItem.Enabled      = true;
            }
        }