Пример #1
0
        public async Task <IActionResult> GetDetail(long?id)
        {
            if (id == null)
            {
                return(JsonBadRequest("DataSet ID is required."));
            }
            var dataSet = await dataSetRepository.GetDataSetIncludeDataSetEntryAsync(id.Value);

            if (dataSet == null)
            {
                return(JsonNotFound($"DataSet Id {id.Value} is not found."));
            }
            var model = new DetailsOutputModel(dataSet);

            if (dataSet.DataSetEntries != null)
            {
                //エントリの作成開始
                var entities    = new Dictionary <string, List <ApiModels.DataApiModels.IndexOutputModel> >();
                var flatEntries = new List <ApiModels.DataApiModels.IndexOutputModel>();

                //空のデータ種別も表示したい&順番を統一したいので、先に初期化しておく
                foreach (var dataType in dataTypeRepository.GetAllWithOrderby(d => d.SortOrder, true))
                {
                    entities.Add(dataType.Name, new List <ApiModels.DataApiModels.IndexOutputModel>());
                }

                //エントリを一つずつ突っ込んでいく。件数次第では遅いかも。
                foreach (var entry in dataSet.DataSetEntries)
                {
                    var dataFile = new ApiModels.DataApiModels.IndexOutputModel(entry.Data);
                    if (dataSet.IsFlat)
                    {
                        flatEntries.Add(dataFile);
                    }
                    else
                    {
                        string key = entry.DataType.Name;
                        entities[key].Add(dataFile);
                    }
                }

                //各種別内のデータについて、データIDの降順に並び替える
                foreach (var dataType in dataTypeRepository.GetAllWithOrderby(d => d.SortOrder, true))
                {
                    entities[dataType.Name].Sort((x, y) => y.Id.CompareTo(x.Id));
                }
                flatEntries.Sort((x, y) => y.Id.CompareTo(x.Id));

                model.Entries     = entities;
                model.FlatEntries = flatEntries;
            }

            model.IsLocked = dataSet.IsLocked;

            return(JsonOK(model));
        }