예제 #1
0
        public RelationshipView Render(RelationshipModel source, int dictionaryId)
        {
            var result = source.Map <RelationshipModel, RelationshipView>();

            result.RelationType = _enumRenderer.Render(source.RelationType);

            var links = new List <LinkView>
            {
                LinkRenderer.Render("GetRelationById", RelTypes.Self, new { id = dictionaryId, relationshipId = source.Id }),
                LinkRenderer.Render("GetWordById", RelTypes.SourceWord, new { id = dictionaryId, wordId = source.SourceWordId }),
                LinkRenderer.Render("GetWordById", RelTypes.RelatedWord, new { id = dictionaryId, wordId = source.RelatedWordId })
            };

            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);
            }

            result.Links = links;
            return(result);
        }
예제 #2
0
        public PageView <WordView> Render(PageRendererArgs <WordModel> source)
        {
            var page = new PageView <WordView>(source.Page.PageCount, source.RouteArguments.PageSize, source.RouteArguments.PageNumber)
            {
                Data = source.Page.Data.Select(x => _wordIndexRenderer.Render(x))
            };

            var links = new List <LinkView>
            {
                LinkRenderer.Render(source.RouteName, RelTypes.Self, CreateRouteParameters(source, page.CurrentPageIndex, page.PageSize))
            };

            if (page.CurrentPageIndex < page.PageCount)
            {
                links.Add(LinkRenderer.Render(source.RouteName, RelTypes.Next, CreateRouteParameters(source, page.CurrentPageIndex + 1, page.PageSize)));
            }

            if (page.CurrentPageIndex > 1)
            {
                links.Add(LinkRenderer.Render(source.RouteName, RelTypes.Previous, CreateRouteParameters(source, page.CurrentPageIndex - 1, page.PageSize)));
            }

            page.Links = links;

            return(page);
        }
예제 #3
0
        public TranslationView Render(TranslationModel source, int dictionaryId)
        {
            if (source == null)
            {
                return(null);
            }

            var result = source.Map <TranslationModel, TranslationView>();

            result.Language = _enumRenderer.Render((LanguageType)source.LanguageId);

            var links = new List <LinkView>
            {
                LinkRenderer.Render("GetTranslationById", RelTypes.Self, new { id = dictionaryId, translationId = source.Id }),
                LinkRenderer.Render("GetWordById", RelTypes.Word, new { id = dictionaryId, wordId = source.WordId })
            };

            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);
            }

            result.Links = links;
            return(result);
        }
예제 #4
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" })
                }
            });
        }
예제 #5
0
        public MeaningView Render(MeaningModel source, int dictionaryId)
        {
            var result = source.Map <MeaningModel, MeaningView>();

            var links = new List <LinkView>
            {
                LinkRenderer.Render("GetMeaningById", RelTypes.Self, new { id = dictionaryId, meaningId = source.Id }),
                LinkRenderer.Render("GetWordById", RelTypes.Word, new { id = dictionaryId, wordId = source.WordId })
            };

            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);
            }

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