Ejemplo n.º 1
0
        public IActionResult GetThesaurus(
            [FromRoute] string database,
            [FromRoute] string id,
            [FromQuery] bool emptyIfNotFound)
        {
            ICadmusRepository repository =
                _repositoryProvider.CreateRepository(database);
            Thesaurus thesaurus = repository.GetThesaurus(id);

            if (thesaurus == null)
            {
                return(emptyIfNotFound
                    ? Ok(new ThesaurusModel
                {
                    Id = id,
                    Language = "en",
                    Entries = Array.Empty <ThesaurusEntry>()
                })
                    : (IActionResult)NotFound());
            }

            ThesaurusModel model = new ThesaurusModel
            {
                Id       = thesaurus.Id,
                Language = thesaurus.GetLanguage(),
                Entries  = thesaurus.GetEntries().ToArray()
            };

            return(Ok(model));
        }
Ejemplo n.º 2
0
        public ActionResult <Dictionary <string, ThesaurusModel> > GetThesauri(
            [FromRoute] string database,
            [FromRoute] string ids,
            [FromQuery] bool purgeIds)
        {
            ICadmusRepository repository =
                _repositoryProvider.CreateRepository(database);
            Dictionary <string, ThesaurusModel> dct =
                new Dictionary <string, ThesaurusModel>();

            foreach (string id in (ids ?? "")
                     .Split(',', StringSplitOptions.RemoveEmptyEntries)
                     .Distinct())
            {
                Thesaurus thesaurus = repository.GetThesaurus(id);
                if (thesaurus == null)
                {
                    continue;
                }
                dct[purgeIds ? PurgeThesaurusId(id) : id] = new ThesaurusModel
                {
                    Id       = thesaurus.Id,
                    Language = thesaurus.GetLanguage(),
                    Entries  = thesaurus.GetEntries().ToArray()
                };
            }
            return(Ok(dct));
        }