コード例 #1
0
        private string GetReportOutputConfiguration(int reportId, int userId, IEnumerable<ReportColumn> columnsSwapHistory, IEnumerable<ReportColumn> columnsWidthHistory)
        {
            var userReport = GetUserReport(reportId, userId);

            var columnsConfig = new JavaScriptSerializer().Deserialize<List<ReportColumn>>(userReport.OutputConfiguration);

            columnsConfig.ForEach(reportConfig =>
            {
                var lastIndex = columnsSwapHistory.LastOrDefault(columnSwap => columnSwap.Name == reportConfig.Name);

                //There was an index change so an offset has to be performed
                if (!lastIndex.IsNull())
                {
                    //Right offset
                    if (lastIndex.Index > reportConfig.Index)
                    {
                        foreach (var column in columnsConfig.Where(colum => colum.Index <= lastIndex.Index && colum.Index > reportConfig.Index))
                            column.Index--;
                    }
                    else
                    {
                        //Left offset
                        foreach (var column in columnsConfig.Where(colum => colum.Index >= lastIndex.Index && colum.Index < reportConfig.Index))
                            column.Index++;
                    }

                    reportConfig.Index = lastIndex.Index;
                }

                var lastWidth = columnsWidthHistory.LastOrDefault(columnWidth => columnWidth.Name == reportConfig.Name);

                if (!lastWidth.IsNull())
                    reportConfig.Width = lastWidth.Width;
            });

            var jsonResult = new JsonSerializer().Serialize(columnsConfig);

            return jsonResult;
        }