Ejemplo n.º 1
0
        public EntryView Render(EntryModel model)
        {
            if (model == null)
            {
                var links = new List <LinkView>
                {
                    LinkRenderer.Render("Entry", RelTypes.Self),
                    LinkRenderer.Render("GetDictionaries", RelTypes.Dictionaries),
                    LinkRenderer.Render("GetLanguages", RelTypes.Languages),
                    LinkRenderer.Render("GetAttributes", RelTypes.Attributes),
                    LinkRenderer.Render("GetRelationTypes", RelTypes.RelationshipTypes),
                    LinkRenderer.Render("GetWordAlternatives", RelTypes.Thesaurus, new { word = "word" })
                };
                return(new EntryView {
                    Links = links
                });
            }

            return(new EntryView
            {
                Links = new List <LinkView>
                {
                    LinkRenderer.RenderOrReRoute(model.Links, "Entry", RelTypes.Self),
                    LinkRenderer.RenderOrReRoute(model.Links, "GetDictionaries", RelTypes.Dictionaries),
                    LinkRenderer.RenderOrReRoute(model.Links, "GetLanguages", RelTypes.Languages),
                    LinkRenderer.RenderOrReRoute(model.Links, "GetAttributes", RelTypes.Attributes),
                    LinkRenderer.RenderOrReRoute(model.Links, "GetRelationTypes", RelTypes.RelationshipTypes),
                    LinkRenderer.RenderOrReRoute(model.Links, "GetWordAlternatives", RelTypes.Thesaurus, new { word = "word" })
                }
            });
        }
Ejemplo n.º 2
0
        public DictionaryView Render(DictionaryModel source)
        {
            var links = new List <LinkView>
            {
                LinkRenderer.RenderOrReRoute(source.Links, "GetDictionaryById", RelTypes.Self, new { id = source.Id }),
                LinkRenderer.RenderOrReRoute(source.Links, "GetWords", RelTypes.Index, new { id = source.Id }),
                LinkRenderer.RenderOrReRoute(source.Links, "SearchDictionary", RelTypes.Search, new { id = source.Id }),
            };

            if (source.Links != null)
            {
                links.AddRange(source.Links
                               .Where(l => l.Rel == RelTypes.Download)
                               .Select(downloadLink => LinkRenderer.RenderOrReRoute(source.Links, "DownloadDictionary", RelTypes.Download, new { id = source.Id, format = downloadLink.Type })));
            }

            var indexes = new List <LinkView>(_indexes.Select(i => LinkRenderer.RenderOrReRoute(source.Indexes, "GetWordsListStartWith", i,
                                                                                                new { id = source.Id, startingWith = i })));

            var result = source.Map <DictionaryModel, DictionaryView>();

            result.Links   = links;
            result.Indexes = indexes;
            return(result);
        }
        public DictionariesView Render(DictionariesModel source)
        {
            var links = new List <LinkView>
            {
                LinkRenderer.RenderOrReRoute(source.Links, "GetDictionaries", RelTypes.Self)
            };


            var view = source.Map <DictionariesModel, DictionariesView>();

            view.Links = links;
            view.Items = source.Items.Select(d => _dictionaryRenderer.Render(d));
            return(view);
        }
Ejemplo n.º 4
0
        public WordView Render(WordModel source)
        {
            var result = source.Map <WordModel, WordView>();

            var links = new List <LinkView>
            {
                LinkRenderer.RenderOrReRoute(source.Links, "GetWordById", RelTypes.Self, new { id = source.DictionaryId, wordId = result.Id }),
                LinkRenderer.RenderOrReRoute(source.Links, "GetWordMeaningByWordId", RelTypes.Meanings, new { id = source.DictionaryId, wordId = result.Id }),
                LinkRenderer.RenderOrReRoute(source.Links, "GetWordTranslationsById", RelTypes.Translations, new { id = source.DictionaryId, wordId = result.Id }),
                LinkRenderer.RenderOrReRoute(source.Links, "GetWordRelationsById", RelTypes.Relationships, new { id = source.DictionaryId, wordId = result.Id }),
                LinkRenderer.RenderOrReRoute(source.Links, "GetDictionaryById", RelTypes.Dictionary, new { id = source.DictionaryId })
            };

            var link = LinkRenderer.ReRoute(source.Links.WithRel(RelTypes.Update));

            if (link != null)
            {
                links.Add(link);
            }
            link = LinkRenderer.ReRoute(source.Links.WithRel(RelTypes.Delete));
            if (link != null)
            {
                links.Add(link);
            }

            link = LinkRenderer.ReRoute(source.Links.WithRel(RelTypes.AddMeaning));
            if (link != null)
            {
                links.Add(link);
            }

            link = LinkRenderer.ReRoute(source.Links.WithRel(RelTypes.AddTranslation));
            if (link != null)
            {
                links.Add(link);
            }

            link = LinkRenderer.ReRoute(source.Links.WithRel(RelTypes.AddRelation));
            if (link != null)
            {
                links.Add(link);
            }

            result.Links = links;
            return(result);
        }