Example #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> >();

                //空のデータ種別も表示したい&順番を統一したいので、先に初期化しておく
                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)
                {
                    string key      = entry.DataType.Name;
                    var    dataFile = new ApiModels.DataApiModels.IndexOutputModel(entry.Data);
                    entities[key].Add(dataFile);
                }

                model.Entries = entities;
            }

            model.IsLocked = dataSet.IsLocked;

            return(JsonOK(model));
        }
Example #2
0
        public async Task <IActionResult> GetDataSetVersion(long id, long versionId)
        {
            var dataSetVersion = await aquariumDataSetVersionRepository
                                 .GetAll()
                                 .Include(x => x.DataSet)
                                 .ThenInclude(d => d.DataSetEntries)
                                 .ThenInclude(d => d.Data)
                                 .SingleOrDefaultAsync(x => x.Id == versionId && x.AquariumDataSetId == id);

            if (dataSetVersion == null)
            {
                return(JsonNotFound($"DataSetVersion (AquariumDataSetId {id} and VersionId {versionId}) is not found."));
            }

            var result  = new VersionDetailsOutputModel(dataSetVersion);
            var dataSet = dataSetVersion.DataSet;

            if (dataSet.DataSetEntries != null)
            {
                result.Entries     = new Dictionary <string, List <ApiModels.DataApiModels.IndexOutputModel> >();
                result.FlatEntries = new List <ApiModels.DataApiModels.IndexOutputModel>();

                foreach (var dataType in dataTypeRepository.GetAllWithOrderby(d => d.SortOrder, true))
                {
                    result.Entries.Add(dataType.Name, new List <ApiModels.DataApiModels.IndexOutputModel>());
                }

                if (dataSet.IsFlat)
                {
                    result.FlatEntries = dataSet.DataSetEntries
                                         .OrderByDescending(x => x.Data.Id)
                                         .Select(x => new ApiModels.DataApiModels.IndexOutputModel(x.Data));
                }
                else
                {
                    foreach (var x in dataSet.DataSetEntries.OrderByDescending(x => x.Data.Id))
                    {
                        result.Entries[x.DataType.Name].Add(new ApiModels.DataApiModels.IndexOutputModel(x.Data));
                    }
                }
            }
            result.Memo = dataSet.Memo;
            return(JsonOK(result));
        }