Beispiel #1
0
        private void fillCourseOperationsTable()
        {
            Operations.Rows.Clear();

            foreach (FxCourseOperations operation in TeacherHelper.CourseOperations())
            {
                TableRow  operationRow  = new TableRow();
                TableCell operationCell = new TableCell();

                CheckBox operationCheckBox = new CheckBox();
                operationCheckBox.Text = operation.Name;

                operationCheckBox.AutoPostBack    = true;
                operationCheckBox.CheckedChanged += new EventHandler(operationCheckBox_CheckedChanged);

                CheckBox delegateCheckBox = new CheckBox();
                delegateCheckBox.Text = delegateStr;

                TblPermissions permission = TeacherHelper.CurrentUserPermissionForCourse(course, operation);
                if (permission == null || !permission.CanBeDelagated)
                {
                    operationCheckBox.Enabled = false;
                    delegateCheckBox.Enabled  = false;
                }
                else
                {
                    operationCheckBox.ID      = permission.ID.ToString();
                    operationCheckBox.Checked = TeacherHelper.AreParentAndChildByCourse(permission, teacher, course);
                    if (operationCheckBox.Checked)
                    {
                        delegateCheckBox.Checked = TeacherHelper.CanChildDelegateCourse(permission, teacher, course);
                    }
                    else
                    {
                        delegateCheckBox.Enabled = false;
                    }
                }

                TableCell leftCell = new TableCell();
                leftCell.HorizontalAlign = HorizontalAlign.Left;
                leftCell.Controls.Add(operationCheckBox);

                TableCell rightCell = new TableCell();
                rightCell.HorizontalAlign = HorizontalAlign.Right;
                rightCell.Controls.Add(delegateCheckBox);

                operationRow.Cells.Add(leftCell);
                operationRow.Cells.Add(rightCell);
                Operations.Rows.Add(operationRow);
            }
        }
Beispiel #2
0
        private void UpdateCourseButton_Click()
        {
            foreach (TableRow operationRow in Operations.Rows)
            {
                CheckBox operationCheckBox = operationRow.Cells[0].Controls[0] as CheckBox;
                CheckBox delegateCheckBox  = operationRow.Cells[1].Controls[0] as CheckBox;

                if (operationCheckBox.Enabled)
                {
                    TblPermissions     parentPermission = ServerModel.DB.Load <TblPermissions>(int.Parse(operationCheckBox.ID));
                    FxCourseOperations operation        = ServerModel.DB.Load <FxCourseOperations>(parentPermission.CourseOperationRef.Value);

                    TblPermissions childPermission = TeacherHelper.GetPermissionForCourse(parentPermission, teacher, course, operation);
                    if (operationCheckBox.Checked)
                    {
                        if (childPermission == null)
                        {
                            TeacherHelper.Share(TeacherHelper.CurrentUserPermissionForCourse(course, operation), teacher.ID, delegateCheckBox.Checked);
                        }
                        else
                        {
                            if (childPermission.CanBeDelagated && !delegateCheckBox.Checked)
                            {
                                TeacherHelper.RemoveChildPermissions(childPermission);
                            }

                            childPermission.CanBeDelagated = delegateCheckBox.Checked;
                            ServerModel.DB.Update <TblPermissions>(childPermission);
                        }
                    }
                    else
                    {
                        if (childPermission != null)
                        {
                            TeacherHelper.RemoveChildPermissions(childPermission);
                            ServerModel.DB.Delete <TblPermissions>(childPermission.ID);
                        }
                    }
                }
            }

            Redirect(BackUrl);
        }