private void fillCurriculumOperationsTable() { Operations.Rows.Clear(); foreach (FxCurriculumOperations operation in TeacherHelper.CurriculumsOperations()) { 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.CurrentUserPermissionForCurriculum(curriculum, operation); if (permission == null || !permission.CanBeDelagated) { operationCheckBox.Enabled = false; delegateCheckBox.Enabled = false; } else { operationCheckBox.ID = permission.ID.ToString(); operationCheckBox.Checked = TeacherHelper.AreParentAndChildByCurriculum(permission, teacher, curriculum); if (operationCheckBox.Checked) { delegateCheckBox.Checked = TeacherHelper.CanChildDelegateCurriculum(permission, teacher, curriculum); } 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); } }
private void UpdateCurriculumButton_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)); FxCurriculumOperations operation = ServerModel.DB.Load <FxCurriculumOperations>(parentPermission.CurriculumOperationRef.Value); TblPermissions childPermission = TeacherHelper.GetPermissionForCurriculum(parentPermission, teacher, curriculum, operation); if (operationCheckBox.Checked) { if (childPermission == null) { TeacherHelper.Share(TeacherHelper.CurrentUserPermissionForCurriculum(curriculum, 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); }