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