Пример #1
0
        }                                       // Min permssible value that can be entered for numerical columns

        /// <summary>
        /// Creates a typed column based off the existing column
        /// </summary>
        /// <returns>CourseDataColumn: Creates a typed column (numeric or string column)</returns>
        public CourseDataColumn ConvertToTypedColumn()
        {
            CourseDataColumn newCol;

            if (DataType == ColumnDataType.Number)
            {
                newCol = new NumericDataColumn()
                {
                    Name          = Name,
                    DataType      = DataType,
                    ColumnType    = ColumnType,
                    CalcRule      = CalcRule,
                    RelatedDataId = RelatedDataId,
                    ColMaxValue   = ColMaxValue,
                    ColMinValue   = ColMinValue,
                    Rows          = new List <NumericDataRow>()
                };
            }
            else
            {
                newCol = new StringDataColumn()
                {
                    Name          = Name,
                    DataType      = DataType,
                    ColumnType    = ColumnType,
                    CalcRule      = CalcRule,
                    RelatedDataId = RelatedDataId,
                    ColMaxValue   = ColMaxValue,
                    ColMinValue   = ColMinValue,
                    Rows          = new List <StringDataRow>()
                };
            }
            return(newCol);
        }
Пример #2
0
        /// <summary>
        /// Loads an instance of the Course Data Table from a dynamic JSON representation of the table
        /// </summary>
        /// <param name="table">The dynamic JSON representation of the table</param>
        /// <returns>CourseDataTable: A re-representation of the Canvas Gradebook for the purposes of this system</returns>
        public static CourseDataTable LoadDataTableFromDynamicObject(dynamic table)
        {
            var newTable = new CourseDataTable
            {
                CourseId = table.courseId,
                AssignmentGradeColumns = new List <CourseDataColumn>(),
                CustomDataColumns      = new List <CourseDataColumn>(),
                Students = new List <DataTableStudent>()
            };

            foreach (var col in table.assignmentGradeColumns)
            {
                var newCol = new NumericDataColumn
                {
                    Name          = col.name,
                    DataType      = col.dataType,
                    ColumnId      = col.columnId,
                    ColumnType    = col.columnType,
                    CalcRule      = col.calcRule,
                    RelatedDataId = col.relatedDataId,
                    ColMaxValue   = col.colMaxValue,
                    ColMinValue   = col.colMinValue,
                    Rows          = new List <NumericDataRow>()
                };
                foreach (var row in col.rows)
                {
                    var newRow = new NumericDataRow
                    {
                        ColumnId       = row.columnId,
                        AssociatedUser = new DataTableStudent
                        {
                            Id   = row.associatedUser.id,
                            Name = row.associatedUser.name
                        },
                        ValueChanged = row.valueChanged,
                        Value        = row.value,
                        NewValue     = row.newValue
                    };
                    newCol.Rows.Add(newRow);
                }
                newTable.AssignmentGradeColumns.Add(newCol);
            }
            foreach (var col in table.customDataColumns)
            {
                if (col.dataType == ColumnDataType.Number)
                {
                    var newCol = new NumericDataColumn
                    {
                        Name          = col.name,
                        DataType      = col.dataType,
                        ColumnId      = col.columnId,
                        ColumnType    = col.columnType,
                        CalcRule      = col.calcRule,
                        RelatedDataId = col.relatedDataId,
                        ColMaxValue   = col.colMaxValue,
                        ColMinValue   = col.colMinValue,
                        Rows          = new List <NumericDataRow>()
                    };

                    foreach (var row in col.rows)
                    {
                        var newRow = new NumericDataRow
                        {
                            ColumnId       = row.columnId,
                            AssociatedUser = new DataTableStudent
                            {
                                Id   = row.associatedUser.id,
                                Name = row.associatedUser.name
                            },
                            ValueChanged = row.valueChanged,
                            Value        = row.value,
                            NewValue     = row.newValue
                        };
                        newCol.Rows.Add(newRow);
                    }

                    newTable.AssignmentGradeColumns.Add(newCol);
                }
                else
                {
                    var newCol = new StringDataColumn
                    {
                        Name          = col.name,
                        DataType      = col.dataType,
                        ColumnId      = col.columnId,
                        ColumnType    = col.columnType,
                        CalcRule      = col.calcRule,
                        RelatedDataId = col.relatedDataId,
                        ColMaxValue   = col.colMaxValue,
                        ColMinValue   = col.colMinValue,
                        Rows          = new List <StringDataRow>()
                    };

                    foreach (var row in col.rows)
                    {
                        var newRow = new StringDataRow
                        {
                            ColumnId       = row.columnId,
                            AssociatedUser = new DataTableStudent
                            {
                                Id   = row.associatedUser.id,
                                Name = row.associatedUser.name
                            },
                            ValueChanged = row.valueChanged,
                            Value        = row.value,
                            NewValue     = row.newValue
                        };
                        newCol.Rows.Add(newRow);
                    }

                    newTable.AssignmentGradeColumns.Add(newCol);
                }
            }
            foreach (var student in table.students)
            {
                newTable.Students.Add(new DataTableStudent
                {
                    Id   = student.id,
                    Name = student.name
                });
            }
            return(newTable);
        }