Example #1
0
        private static TVShow _readShow(NeoTvShow neo)
        {
            TVShow add = new TVShow(neo);

            var query = _instance.Cypher
                        .OptionalMatch("(season:Season)<-[HAS]-(tvshow:TVShow)")
                        .Where((NeoTvShow tvshow) => tvshow.Id == add.Id)
                        .Return(season => season.As <Season>())
                        .Results;

            foreach (Season season in query)
            {
                add.Seasons.Add(season);
            }

            var query2 = _instance.Cypher
                         .OptionalMatch("(creator:TVShowCreator)-[CREATED]->(tvshow:TVShow)")
                         .Where((NeoTvShow tvshow) => tvshow.Id == add.Id)
                         .Return(creator => creator.As <TVShowCreator>())
                         .Results;

            foreach (TVShowCreator creator in query2)
            {
                add.CreatedBy.Add(creator);
            }

            var query3 = _instance.Cypher
                         .OptionalMatch("(network:Network)<-[BELONGS]-(tvshow:TVShow)")
                         .Where((NeoTvShow tvshow) => tvshow.Id == add.Id)
                         .Return(network => network.As <Network>())
                         .Results;

            foreach (Network network in query3)
            {
                add.Networks.Add(network);
            }

            var query4 = _instance.Cypher
                         .OptionalMatch("(tvshow:TVShow)-[IS_GENRE]->(genre:Genre)")
                         .Where((NeoTvShow tvshow) => tvshow.Id == add.Id)
                         .Return(genre => genre.As <Genre>())
                         .Results;

            foreach (Genre genre in query4)
            {
                add.Genres.Add(genre);
            }

            return(add);
        }
Example #2
0
        public static void _addTvShow(TVShow show)
        {
            NeoTvShow newTVShow = new NeoTvShow(show);

            _instance.Cypher
            .Merge("(show:TVShow { Id: {id} })")
            .OnCreate()
            .Set("show = {newTVShow}")
            .WithParams(new
            {
                id = show.Id,
                newTVShow
            })
            .ExecuteWithoutResults();

            foreach (Genre newGenre in show.Genres)
            {
                _instance.Cypher
                .Merge("(genre:Genre { Id: {genreId} })")
                .OnCreate()
                .Set("genre = {newGenre}")
                .WithParams(new
                {
                    genreId = newGenre.Id,
                    newGenre
                })
                .ExecuteWithoutResults();

                _instance.Cypher
                .Match("(foundShow:TVShow)", "(foundGenre:Genre)")
                .Where((NeoTvShow foundShow) => foundShow.Id == show.Id)
                .AndWhere((Genre foundGenre) => foundGenre.Id == newGenre.Id)
                .CreateUnique("(foundShow)-[:IS_GENRE]->(foundGenre)")
                .ExecuteWithoutResults();
            }

            foreach (Network newNetwork in show.Networks)
            {
                _instance.Cypher
                .Merge("(network:Network { Id: {networkId} })")
                .OnCreate()
                .Set("network = {newNetwork}")
                .WithParams(new
                {
                    networkId = newNetwork.Id,
                    newNetwork
                })
                .ExecuteWithoutResults();

                _instance.Cypher
                .Match("(foundShow:TVShow)", "(foundNetwork:Network)")
                .Where((NeoTvShow foundShow) => foundShow.Id == show.Id)
                .AndWhere((Network foundNetwork) => foundNetwork.Id == newNetwork.Id)
                .CreateUnique("(foundShow)-[:BELONGS]->(foundNetwork)")
                .ExecuteWithoutResults();
            }

            foreach (TVShowCreator newCreator in show.CreatedBy)
            {
                _instance.Cypher
                .Merge("(creator:TVShowCreator { Id: {creatorId} })")
                .OnCreate()
                .Set("creator = {newCreator}")
                .WithParams(new
                {
                    creatorId = newCreator.Id,
                    newCreator
                })
                .ExecuteWithoutResults();

                _instance.Cypher
                .Match("(foundShow:TVShow)", "(foundCreator:TVShowCreator)")
                .Where((NeoTvShow foundShow) => foundShow.Id == show.Id)
                .AndWhere((TVShowCreator foundCreator) => foundCreator.Id == newCreator.Id)
                .CreateUnique("(foundShow)<-[:CREATED]-(foundCreator)")
                .ExecuteWithoutResults();
            }

            foreach (Season newSeason in show.Seasons)
            {
                _instance.Cypher
                .Merge("(season:Season { Id: {seasonId} })")
                .OnCreate()
                .Set("season = {newSeason}")
                .WithParams(new
                {
                    seasonId = newSeason.Id,
                    newSeason
                })
                .ExecuteWithoutResults();

                _instance.Cypher
                .Match("(foundShow:TVShow)", "(foundSeason:Season)")
                .Where((NeoTvShow foundShow) => foundShow.Id == show.Id)
                .AndWhere((Season foundSeason) => foundSeason.Id == newSeason.Id)
                .CreateUnique("(foundShow)-[:HAS]->(foundSeason)")
                .ExecuteWithoutResults();
            }
        }