예제 #1
0
        public User LoginUser([FromBody] User _user)
        {
            GraphClientConnection graphClient = new GraphClientConnection();

            if (graphClient == null)
            {
                StatusCode(500);
                return(null);
            }

            if (_user.name == null || _user.password == null)
            {
                //204
                return(null);
            }

            User user = new User();

            var userQuery = graphClient.client.Cypher
                            .Match("(user:User{name:'" + _user.name + "', password:'******'})")
                            .Return((user) => new {
                User = user.As <User>(),
            })
                            .Results;

            if (userQuery.Count() == 0)
            {
                //204 No Content, user doesnt exist
                return(null);
            }
            StatusCode(200);
            return(Get(userQuery.ToList()[0].User.id));
        }
예제 #2
0
        public List <Band> GetBands()
        {
            GraphClientConnection graphClient = new GraphClientConnection();
            List <Band>           bands       = new List <Band>();

            if (graphClient == null)
            {
                StatusCode(500);
                return(null);
            }

            var bandQuery = graphClient.client.Cypher
                            .Match("(band:Band)")
                            .Return((band) => new {
                Bands = band.CollectAs <Band>(),
            })
                            .Results;


            if (bandQuery.Count() == 0)
            {
                //204 No Content, user doesnt exist
                return(null);
            }
            bands = bandQuery.ToList()[0].Bands.ToList();

            return(bands);
        }
예제 #3
0
        public Band PostBand([FromBody] Band bandInfo)
        {
            GraphClientConnection graphClient = new GraphClientConnection();
            Band newBand = new Band {
                name = bandInfo.name, type = bandInfo.type, phone = bandInfo.phone, imageUrl = bandInfo.imageUrl
            };

            if (graphClient == null)
            {
                StatusCode(500);
                return(null);
            }


            var newBandQueryResult = graphClient.client.Cypher
                                     .Create("(band:Band {newBand})")
                                     .WithParam("newBand", newBand)
                                     .Return((band) => new
            {
                Band = band.As <Band>()
            })
                                     .Results;

            if (newBandQueryResult.Count() == 0)
            {
                StatusCode(500);
                return(null);
            }

            newBand = newBandQueryResult.ToList()[0].Band;
            StatusCode(200);

            return(newBand);
        }
예제 #4
0
        public ActionResult Post([FromBody] User _user)
        {
            GraphClientConnection graphClient = new GraphClientConnection();

            if (graphClient == null)
            {
                StatusCode(500);
                return(null);
            }

            if (_user == null)
            {
                StatusCode(400);
                return(null);
            }

            var newUser = new User {
                id = _user.id, name = _user.name, password = _user.password, age = _user.age, isOwner = _user.isOwner, gender = _user.gender
            };

            graphClient.client.Cypher
            .Create("(user:User {newUser})")
            .WithParam("newUser", newUser)
            .ExecuteWithoutResults();

            return(StatusCode(200));
        }
예제 #5
0
        public void Delete(string name)
        {
            GraphClientConnection graphClient = new GraphClientConnection();

            graphClient.client.Cypher
            .Match("(b:Band {name:'" + name + "'})")
            .DetachDelete("b")
            .ExecuteWithoutResults();
        }
예제 #6
0
        public Band GetBand(string name)
        {
            GraphClientConnection graphClient = new GraphClientConnection();
            Band band = new Band();

            if (graphClient == null)
            {
                StatusCode(500);
                return(null);
            }

            if (name == null)
            {
                StatusCode(400);
                return(null);
            }


            var bandQuery = graphClient.client.Cypher
                            .Match("(band:Band{ name:'" + name + "'})")
                            .Return((band) => new {
                Band = band.As <Band>(),
            })
                            .Results;

            var avgRatingQuery = graphClient.client.Cypher
                                 .OptionalMatch("(b:Band {name:'" + name + "'})-[:HAS_REVIEW]->(r:Review)<-[:LEAVE]-(u:User)")
                                 .With("avg(r.rating) as bandAvgRating")
                                 .Return((bandAvgRating) => new {
                BandAvgRating = bandAvgRating.As <Double>()
            })
                                 .Results;

            var bandsReviewQuery = graphClient.client.Cypher
                                   .OptionalMatch("(u:User)-[:LEAVE]->(bandsReviews:Review)<-[:HAS_REVIEW]-(band:Band { name:'" + name + "'})")
                                   .With("bandsReviews {nameOfBandOrPlace:band.name, comment:bandsReviews.comment, rating:bandsReviews.rating, userId: u.id, userName: u.name }")
                                   .Return((bandsReviews) => new {
                BandsReviews = bandsReviews.CollectAs <UserReview>()
            })
                                   .Results;

            if (bandQuery.Count() == 0)
            {
                //204 No Content, user doesnt exist
                return(null);
            }

            band.name          = bandQuery.ToList()[0].Band == null ? null : bandQuery.ToList()[0].Band.name;
            band.type          = bandQuery.ToList()[0].Band == null ? null : bandQuery.ToList()[0].Band.type;
            band.imageUrl      = bandQuery.ToList()[0].Band == null ? null : bandQuery.ToList()[0].Band.imageUrl;
            band.phone         = bandQuery.ToList()[0].Band == null ? null : bandQuery.ToList()[0].Band.phone;
            band.bandAvgRating = avgRatingQuery.ToList()[0].BandAvgRating;
            band.bandReviews   = bandsReviewQuery.ToList()[0].BandsReviews == null ? null : bandsReviewQuery.ToList()[0].BandsReviews.ToList();

            return(band);
        }
예제 #7
0
        public Place Post([FromBody] Place _place)
        {
            GraphClientConnection graphClient = new GraphClientConnection();

            if (graphClient == null)
            {
                StatusCode(500);
                return(null);
            }

            User owner = new User();

            var ownerQuery = graphClient.client.Cypher
                             .Match("(user:User{id:'" + _place.ownerId + "'})")
                             .Return((user) => new
            {
                Owner = user.As <User>()
            })
                             .Results;

            owner = ownerQuery.ToList()[0].Owner;
            if (owner == null || owner.isOwner == false)
            {
                StatusCode(204);
                return(null);
            }
            Place newPlace = new Place {
                address = _place.address, imageUrl = _place.imageUrl, name = _place.name, phone = _place.phone
            };
            var newPlaceQueryResult = graphClient.client.Cypher
                                      .Match("(owner:User{id:'" + _place.ownerId + "'})")
                                      .Create("(owner)-[c:CREATE]->(p:Place{address:'" + newPlace.address + "', imageUrl:'" + newPlace.imageUrl +
                                              "', name:'" + newPlace.name + "', phone:'" + newPlace.phone + "'})")
                                      .Return((p) => new
            {
                Place = p.As <Place>()
            })
                                      .Results;

            if (newPlaceQueryResult.Count() == 0)
            {
                StatusCode(500);
                return(null);
            }
            newPlace = newPlaceQueryResult.ToList()[0].Place;
            StatusCode(200);
            return(newPlace);
        }
예제 #8
0
        public List <Place> Get()
        {
            GraphClientConnection graphClient = new GraphClientConnection();

            if (graphClient == null)
            {
                StatusCode(500);
                return(null);
            }
            List <Place> allPlaces      = new List <Place>();
            var          allPlacesQuery = graphClient.client.Cypher
                                          .Match("(allPlaces:Place)")
                                          .ReturnDistinct((allPlaces) => new
            {
                AllPlaces = allPlaces.CollectAs <Place>()
            })
                                          .Results;

            allPlaces = allPlacesQuery.ToList()[0].AllPlaces == null ? null : allPlacesQuery.ToList()[0].AllPlaces.ToList();
            if (allPlaces == null)
            {
                return(null);
            }
            List <Place> sortedRatedPlaces = new List <Place>();
            Place        tmp;

            foreach (var place in allPlaces)
            {
                tmp = new Place();
                var ratedPlaceQuery = graphClient.client.Cypher
                                      .OptionalMatch("(p:Place{name:'" + place.name + "'})-[:HAS_REVIEW]->(r:Review)<-[:LEAVE]-()")
                                      .With("avg(r.rating) as averageRate")
                                      .Return((averageRate) => new
                {
                    AverageRate = averageRate.As <Double>()
                })
                                      .Results;
                tmp             = place;
                tmp.averageRate = ratedPlaceQuery.ToList()[0].AverageRate;
                if (tmp != null)
                {
                    sortedRatedPlaces.Add(tmp);
                }
            }
            sortedRatedPlaces = sortedRatedPlaces.OrderByDescending(x => x.averageRate).ToList();
            return(sortedRatedPlaces);
        }
예제 #9
0
        public FollowedUser FollowUser([FromBody] UserIds userIds)
        {
            string userId                      = userIds.userId;
            string followedUserId              = userIds.followedUserId;
            GraphClientConnection graphClient  = new GraphClientConnection();
            FollowedUser          followedUser = new FollowedUser();

            if (graphClient == null)
            {
                StatusCode(500);
                return(null);
            }

            string matchQuery        = "(user:User{id:'" + userId + "'})-[follow:FOLLOW]->(followedUser:User{id:'" + followedUserId + "'})";
            var    followedUserQuery = graphClient.client.Cypher
                                       .Match(matchQuery)
                                       .Return((followedUser) => new {
                FollowedUser = followedUser.As <FollowedUser>(),
            })
                                       .Results;

            if (followedUserQuery.Count() == 1) // relation between nodes exist already, so, you need to delete that relation
            {
                graphClient.client.Cypher
                .Match(matchQuery)
                .Delete("follow")
                .ExecuteWithoutResults();
                //204
                return(null);
            }

            var newFollowerQuery = graphClient.client.Cypher
                                   .Match("(user:User{id:'" + userId + "'}),(followedUser:User{id:'" + followedUserId + "'})")
                                   .Create("(user)-[:FOLLOW]->(followedUser)")
                                   .Return((followedUser) => new {
                FollowedUser = followedUser.As <FollowedUser>(),
            })
                                   .Results;

            followedUser.id     = newFollowerQuery.ToList()[0].FollowedUser.id;
            followedUser.name   = newFollowerQuery.ToList()[0].FollowedUser.name;
            followedUser.age    = newFollowerQuery.ToList()[0].FollowedUser.age;
            followedUser.gender = newFollowerQuery.ToList()[0].FollowedUser.gender;
            return(followedUser);
        }
예제 #10
0
        public FavoritePlace AddFavoritePlace([FromBody] UserIdName userIdName)
        {
            string userId    = userIdName.userId;
            string placeName = userIdName.name;
            GraphClientConnection graphClient   = new GraphClientConnection();
            FavoritePlace         favoritePlace = new FavoritePlace();

            if (graphClient == null)
            {
                StatusCode(500);
                return(null);
            }

            string matchQuery         = "(user:User{id:'" + userId + "'})-[like:LIKE]->(favoritePlace:Place{name:'" + placeName + "'})";
            var    favoritePlaceQuery = graphClient.client.Cypher
                                        .Match(matchQuery)
                                        .Return((favoritePlace) => new {
                FavoritePlace = favoritePlace.As <FavoritePlace>()
            })
                                        .Results;

            if (favoritePlaceQuery.Count() == 1) // relation between nodes exist already, so, you need to delete that relation
            {
                graphClient.client.Cypher
                .Match(matchQuery)
                .Delete("like")
                .ExecuteWithoutResults();
                //204
                return(null);
            }

            var newFavoritePlaceQuery = graphClient.client.Cypher
                                        .Match("(user:User{id:'" + userId + "'}),(favoritePlace:Place{name:'" + placeName + "'})")
                                        .Create("(user)-[:LIKE]->(favoritePlace)")
                                        .Return((favoritePlace) => new {
                FavoritePlace = favoritePlace.As <FavoritePlace>()
            })
                                        .Results;

            favoritePlace.name     = newFavoritePlaceQuery.ToList()[0].FavoritePlace.name;
            favoritePlace.address  = newFavoritePlaceQuery.ToList()[0].FavoritePlace.address;
            favoritePlace.imageUrl = newFavoritePlaceQuery.ToList()[0].FavoritePlace.imageUrl;
            return(favoritePlace);
        }
예제 #11
0
        public UserReview PostReview([FromBody] UserReview reviewInfo)
        {
            GraphClientConnection graphClient = new GraphClientConnection();

            if (graphClient == null)
            {
                StatusCode(500);
                return(null);
            }

            Review newReview = new Review {
                comment = reviewInfo.comment, rating = reviewInfo.rating, nameOfBandOrPlace = reviewInfo.nameOfBandOrPlace
            };

            var rev = graphClient.client.Cypher
                      .Match("(n {name:'" + reviewInfo.nameOfBandOrPlace + "'}), (u: User {name:'" + reviewInfo.userName + "'})")
                      .Create("(r:Review {newReview}), (u)-[:LEAVE]->(r)<-[:HAS_REVIEW]-(n)")
                      .WithParam("newReview", newReview)
                      .Return((r, u) => new {
                Review = r.As <Review>(),
                User   = u.As <User>()
            })
                      .Results;

            UserReview ur = new UserReview();

            ur.userId   = rev.ToList()[0].User == null ? null : rev.ToList()[0].User.id;
            ur.userName = rev.ToList()[0].User == null ? null : rev.ToList()[0].User.name;

            ur.comment           = rev.ToList()[0].Review == null ? null : rev.ToList()[0].Review.comment;
            ur.rating            = rev.ToList()[0].Review.rating;
            ur.nameOfBandOrPlace = rev.ToList()[0].Review == null ? null : rev.ToList()[0].Review.nameOfBandOrPlace;

            StatusCode(200);
            return(ur);
        }
예제 #12
0
        public List <Review> GetReviews(string name)
        {
            GraphClientConnection graphClient = new GraphClientConnection();
            List <Review>         reviews     = new List <Review>();

            if (graphClient == null)
            {
                StatusCode(500);
                return(null);
            }

            if (name == null)
            {
                StatusCode(400);
                return(null);
            }


            var reviewQuery = graphClient.client.Cypher
                              .Match("(:User)-[:LEAVE]->(review:Review)<-[:HAS_REVIEW]-(n { name:'" + name + "'})")
                              .With("review {nameOfBandOrPlace:n.name,comment:review.comment,rating:review.rating}")
                              .Return((review) => new {
                Reviews = review.CollectAs <Review>(),
            })
                              .Results;


            if (reviewQuery.Count() == 0)
            {
                //204 No Content, user doesnt exist
                return(null);
            }
            reviews = reviewQuery.ToList()[0].Reviews.ToList();

            return(reviews);
        }
예제 #13
0
        public EventIdName UserGoingTo([FromBody] UserEvent _newUserEvent)
        {
            GraphClientConnection graphClient = new GraphClientConnection();

            if (graphClient == null)
            {
                StatusCode(500);
                return(null);
            }

            EventIdName eventInfo = new EventIdName();

            //////////
            ///
            string matchQuery = "(user:User{id:'" + _newUserEvent.userId + "'})-[going_to:GOING_TO]->(event:Event{id:" + _newUserEvent.eventId + "})";
            var    userAlreadyGoingToEvent = graphClient.client.Cypher
                                             .Match(matchQuery)
                                             .Return((user) => new {
                UserGingToEvent = user.As <User>()
            })
                                             .Results;

            if (userAlreadyGoingToEvent.Count() == 1) // relation between nodes exist already, so, you need to delete that relation
            {
                graphClient.client.Cypher
                .Match(matchQuery)
                .Delete("going_to")
                .ExecuteWithoutResults();
                //204
                return(null);
            }

            ///////////


            var eventIdAndName = graphClient.client.Cypher
                                 .Match("(event:Event{id:" + _newUserEvent.eventId + "})")
                                 .With("event.id as eventId, event.name as eventName")
                                 .Return((eventId, eventName) => new
            {
                EventId   = eventId.As <int>(),
                EventName = eventName.As <string>()
            })
                                 .Results;


            if (eventIdAndName.Count() == 0)
            {
                StatusCode(500);
                return(null);
            }

            eventInfo.eventId   = eventIdAndName.ToList()[0].EventId;
            eventInfo.eventName = eventIdAndName.ToList()[0].EventName;

            var userId = graphClient.client.Cypher
                         .Match("(user:User{id:'" + _newUserEvent.userId + "'})")
                         .With("user.id as userId")
                         .Return((userId) => new
            {
                UserId = userId.As <string>()
            })
                         .Results;

            if (userId.Count() == 0)
            {
                StatusCode(500);
                return(null);
            }

            graphClient.client.Cypher
            .Match("(event:Event{id:" + _newUserEvent.eventId + "}), (user:User{id:'" + _newUserEvent.userId + "'})")
            .Create("(user)-[:GOING_TO]->(event)")
            .ExecuteWithoutResults();

            StatusCode(200);
            return(eventInfo);
        }
예제 #14
0
        public Event Post([FromBody] Event _newEvent)
        {
            GraphClientConnection graphClient = new GraphClientConnection();

            if (graphClient == null)
            {
                StatusCode(500);
                return(null);
            }

            var newEventQuery = graphClient.client.Cypher
                                .Match("(place:Place{name:'" + _newEvent.placeName + "'})")
                                .Create("(place)<-[:HAPPENS]-(newEvent:Event{name:'" + _newEvent.name + "', topic:'" + _newEvent.topic + "', time:'"
                                        + _newEvent.time + "', description:'" + _newEvent.description + "', imageUrl:'" + _newEvent.imageUrl + "'})")
                                .Set("newEvent.id = id(newEvent)")
                                .Return((newEvent) => new
            {
                NewEvent = newEvent.As <Event>()
            })
                                .Results;

            if (newEventQuery.Count() == 0)
            {
                return(null);
            }
            Event newEvent = new Event();

            newEvent                = newEventQuery.ToList()[0].NewEvent;
            newEvent.placeName      = _newEvent.placeName;
            newEvent.listOfSponsors = new List <Sponsor>();
            foreach (var sponsor in _newEvent.listOfSponsors)
            {
                var getSponsor = graphClient.client.Cypher
                                 .Match("(s:Sponsor{name:'" + sponsor.name + "'})")
                                 .Return((s) => new
                {
                    Sponsor = s.As <Sponsor>()
                })
                                 .Results;
                if (getSponsor.Count() == 0)
                {
                    var addSponsor = graphClient.client.Cypher
                                     .Match("(event:Event{id:" + newEventQuery.ToList()[0].NewEvent.id + "})")
                                     .Create("(event)-[:SPONSORED_BY]->(newSponsor:Sponsor{name:'" + sponsor.name + "', description:'"
                                             + sponsor.description + "'})")
                                     .Return((newSponsor) => new
                    {
                        NewSponsor = newSponsor.As <Sponsor>()
                    })
                                     .Results;
                    newEvent.listOfSponsors.Add(addSponsor.ToList()[0].NewSponsor);
                }
                else
                {
                    var addSponsor = graphClient.client.Cypher
                                     .Match("(event:Event{id:" + newEventQuery.ToList()[0].NewEvent.id + "}), " +
                                            "(sponsor:Sponsor{name:'" + sponsor.name + "'})")
                                     .Create("(event)-[:SPONSORED_BY]->(sponsor)")
                                     .Return((sponsor) => new
                    {
                        Sponsor = sponsor.As <Sponsor>()
                    })
                                     .Results;
                    newEvent.listOfSponsors.Add(addSponsor.ToList()[0].Sponsor);
                }
            }

            return(newEvent);
        }
예제 #15
0
        public ObjectResult addBand([FromBody] TimeAndBand _bandTimeAndPlace)
        {
            GraphClientConnection graphClient = new GraphClientConnection();

            if (graphClient == null)
            {
                return(StatusCode(500, "{message:\"Something went wrong with db\"}"));
            }

            var bandPlaceQuery = graphClient.client.Cypher
                                 .Match("(band:Band{name: '" + _bandTimeAndPlace.bandName + "'})-[p:PLAY{time:'" + _bandTimeAndPlace.time + "'}]->(place:Place{name:'" + _bandTimeAndPlace.placeName + "'})")
                                 .Return((band) => new
            {
                Band = band.As <Band>()
            })
                                 .Results;

            if (bandPlaceQuery.Count() == 1)
            {
                return(StatusCode(403, "{message:\"Band doesn't exist\"}"));
            }

            var bandQuery = graphClient.client.Cypher
                            .Match("(band:Band{name: '" + _bandTimeAndPlace.bandName + "'})")
                            .Return((band) => new
            {
                Band = band.As <Band>()
            })
                            .Results;

            if (bandQuery.Count() == 0)
            {
                return(StatusCode(404, "{message:\"Band doesn't exist\"}"));
            }

            var placeQuery = graphClient.client.Cypher
                             .Match("(place:Place{name: '" + _bandTimeAndPlace.placeName + "'})")
                             .Return((place) => new
            {
                Place = place.As <Place>()
            })
                             .Results;

            if (placeQuery.Count() == 0)
            {
                return(StatusCode(404, "{message:\"Place doesn't exist\"}"));
            }

            var timePlaceBand = graphClient.client.Cypher
                                .Match("(band:Band{name: '" + _bandTimeAndPlace.bandName + "'}), (place:Place{name: '" + _bandTimeAndPlace.placeName + "'})")
                                .Create("(band)-[play:PLAY{time:'" + _bandTimeAndPlace.time + "', day:'" + _bandTimeAndPlace.day + "',type:'" +
                                        _bandTimeAndPlace.type + "'}]->(place)")
                                .With("{placeName: place.name, bandName: band.name, day: play.day, time: play.time, type: play.type} as timePlaceAndBand ")
                                .Return((timePlaceAndBand) => new
            {
                TimePlaceAndBand = timePlaceAndBand.As <TimeAndBand>()
            })
                                .Results;

            if (timePlaceBand.Count() == 0)
            {
                return(StatusCode(500, "{message:\"Something went wrong\"}"));
            }
            TimeAndBand tmp = timePlaceBand.ToList()[0].TimePlaceAndBand;

            return(StatusCode(201, tmp));
        }
예제 #16
0
        public Place Get(string name)
        {
            GraphClientConnection graphClient = new GraphClientConnection();

            if (graphClient == null)
            {
                StatusCode(500);
                return(null);
            }
            Place placeInfo = new Place();

            var placeQuery = graphClient.client.Cypher
                             //.Match("(place:Place{name:'" + name + "'})-[:HAS_REVIEW]->(review:Review)<-[:LEAVE]-(u:User)")
                             //.With("{name:place.name, address:place.address, imageUrl:place.imageUrl, phone:place.phone, averageRate:avg(review.rating)} as place")
                             .Match("(place:Place{name:'" + name + "'})")
                             .Return((place) => new {
                Place = place.As <Place>()
            })
                             .Results;

            if (placeQuery.Count() == 0)
            {
                return(null); //code 204
            }
            var placeAvgRate = graphClient.client.Cypher
                               .OptionalMatch("(place:Place{name:'" + name + "'})-[:HAS_REVIEW]->(review:Review)<-[:LEAVE]-(u:User)")
                               .With("avg(review.rating) as averageRate")
                               .Return((averageRate) => new {
                AverageRate = averageRate.As <Double>()
            })
                               .Results;
            var placeReviewsQuery = graphClient.client.Cypher
                                    .OptionalMatch("(place:Place{name:'" + name + "'})-[:HAS_REVIEW]->(reviews:Review)<-[]-(u:User)")
                                    .With("{nameOfBandOrPlace:place.name, comment: reviews.comment, rating:reviews.rating, userId: u.id, userName: u.name} as placeReviews ")
                                    .Return((placeReviews) => new {
                Reviews = placeReviews.CollectAs <UserReview>()
            })
                                    .Results;

            var placeBandsQuery = graphClient.client.Cypher
                                  .OptionalMatch("(bands:Band)-[play:PLAY]->(p:Place{name:'" + name + "'})")
                                  .With("{bandName: bands.name, day: play.day, time: play.time, type: play.type} as timeAndBand ")
                                  .Return((timeAndBand) => new
            {
                placeBandsTime = timeAndBand.CollectAs <TimeAndBand>()
            })
                                  .Results;

            var placeEvents = graphClient.client.Cypher
                              .OptionalMatch("(events:Event)-[:HAPPENS]->(place:Place{name:'" + name + "'})")
                              .Return((events) => new
            {
                Events = events.CollectAs <Event>()
            })
                              .Results;

            placeInfo.name         = placeQuery.ToList()[0].Place == null? null : placeQuery.ToList()[0].Place.name;
            placeInfo.address      = placeQuery.ToList()[0].Place == null ? null : placeQuery.ToList()[0].Place.address;
            placeInfo.averageRate  = placeAvgRate.ToList()[0].AverageRate;
            placeInfo.imageUrl     = placeQuery.ToList()[0].Place == null ? null : placeQuery.ToList()[0].Place.imageUrl;
            placeInfo.phone        = placeQuery.ToList()[0].Place == null ? null : placeQuery.ToList()[0].Place.phone;
            placeInfo.placeBands   = placeBandsQuery.ToList()[0].placeBandsTime == null ? null : placeBandsQuery.ToList()[0].placeBandsTime.ToList();
            placeInfo.placeReviews = placeReviewsQuery.ToList()[0].Reviews == null ? null : placeReviewsQuery.ToList()[0].Reviews.ToList();
            //placeInfo.listOfEvents = placeEvents.ToList()[0].Events == null ? null : placeEvents.ToList()[0].Events.ToList();
            placeInfo.listOfEvents = placeEvents.ToList()[0].Events.ToList();
            return(placeInfo);
        }
예제 #17
0
        public User Get(string userId)
        {
            GraphClientConnection graphClient = new GraphClientConnection();
            User user = new User();

            var userQuery = graphClient.client.Cypher
                            .Match("(user:User{id:'" + userId + "'})")
                            .Return((user) => new {
                User = user.As <User>(),
            })
                            .Results;

            if (userQuery.Count() == 0)
            {
                //204 No Content, user doesnt exist
                return(null);
            }

            var myPlacesQuery = graphClient.client.Cypher
                                .OptionalMatch("(:User{ id:'" + userId + "'})-[:CREATE]->(place:Place)")
                                .With("place.name as placeName")
                                .Return((placeName) => new {
                MyPlaces = placeName.CollectAs <string>()
            })
                                .Results;

            var favBandsQuery = graphClient.client.Cypher
                                .OptionalMatch("(:User{ id:'" + userId + "'})-[:LIKE]->(bands:Band)")
                                .Return((bands) => new {
                FavBands = bands.CollectAs <FavoriteBand>()
            })
                                .Results;

            var favPlacesQuery = graphClient.client.Cypher
                                 .OptionalMatch("(:User{ id:'" + userId + "'})-[:LIKE]->(places:Place)")
                                 .Return((places) => new {
                FavPlaces = places.CollectAs <FavoritePlace>()
            })
                                 .Results;

            var bandsReviewQuery = graphClient.client.Cypher
                                   .OptionalMatch("(:User{ id:'" + userId + "'})-[:LEAVE]->(bandsReviews:Review)<-[:HAS_REVIEW]-(band:Band)")
                                   .With("bandsReviews {nameOfBandOrPlace:band.name,comment:bandsReviews.comment,rating:bandsReviews.rating}")
                                   .Return((bandsReviews) => new {
                BandsReviews = bandsReviews.CollectAs <Review>()
            })
                                   .Results;

            var placesReviewQuery = graphClient.client.Cypher
                                    .OptionalMatch("(:User{ id:'" + userId + "'})-[:LEAVE]->(placesReviews:Review)<-[:HAS_REVIEW]-(place:Place)")
                                    .With("placesReviews {nameOfBandOrPlace:place.name,comment:placesReviews.comment,rating:placesReviews.rating}")
                                    .Return((placesReviews) => new
            {
                PlacesReviews = placesReviews.CollectAs <Review>()
            })
                                    .Results;

            var followedUsersQuery = graphClient.client.Cypher
                                     .OptionalMatch("(:User{ id:'" + userId + "'})-[:FOLLOW]->(followedUsers:User)")
                                     .Return((followedUsers) => new {
                FollowedUsers = followedUsers.CollectAs <FollowedUser>()
            })
                                     .Results;

            var goingToEventsUsersQuery = graphClient.client.Cypher
                                          .OptionalMatch("(:User{ id:'" + userId + "'})-[:GOING_TO]->(ev:Event)")
                                          .With("ev {eventId:ev.id,eventName:ev.name}")
                                          .Return((ev) => new {
                EventIdEventName = ev.CollectAs <EventIdName>()
            })
                                          .Results;

            user.id             = userQuery.ToList()[0].User.id;
            user.name           = userQuery.ToList()[0].User.name;
            user.age            = userQuery.ToList()[0].User.age;
            user.isOwner        = userQuery.ToList()[0].User.isOwner;
            user.gender         = userQuery.ToList()[0].User.gender;
            user.myPlaces       = myPlacesQuery.ToList()[0].MyPlaces.ToList();
            user.favoriteBands  = favBandsQuery.ToList()[0].FavBands.ToList();
            user.favoritePlaces = favPlacesQuery.ToList()[0].FavPlaces.ToList();
            user.reviewBand     = bandsReviewQuery.ToList()[0].BandsReviews.ToList();
            user.reviewPlaces   = placesReviewQuery.ToList()[0].PlacesReviews.ToList();
            user.followedUsers  = followedUsersQuery.ToList()[0].FollowedUsers.ToList();
            user.userEvents     = goingToEventsUsersQuery.ToList()[0].EventIdEventName.ToList();
            StatusCode(200);
            return(user);
        }
예제 #18
0
        public Event Get(int id)
        {
            GraphClientConnection graphClient = new GraphClientConnection();

            if (graphClient == null)
            {
                StatusCode(500);
                return(null);
            }

            Event getEvent      = new Event();
            var   getEventQuery = graphClient.client.Cypher
                                  .Match("(e:Event{id:" + id + "})")
                                  .Return((e) => new {
                Event = e.As <Event>()
            })
                                  .Results;

            if (getEventQuery.Count() == 0)
            {
                return(null);
            }

            var getPlace = graphClient.client.Cypher
                           .Match("(e:Event{id:" + id + "})-[:HAPPENS]->(place)")
                           .With("place.name as placeName")
                           .Return((placeName) => new
            {
                PlaceName = placeName.As <string>()
            })
                           .Results;

            if (getPlace.Count() == 0)
            {
                return(null);
            }
            var getSponsores = graphClient.client.Cypher
                               .Match("(sponsor)<-[:SPONSORED_BY]-(e:Event{id:" + id + "})")
                               .Return((sponsor) => new
            {
                Sponsor = sponsor.CollectAs <Sponsor>()
            })
                               .Results;

            if (getSponsores.Count() == 0)
            {
                return(null);
            }
            var getUsersGoingTo = graphClient.client.Cypher
                                  .Match("(users:User)-[:GOING_TO]->(e:Event{id:" + id + "})")
                                  .Return((users) => new
            {
                Users = users.CollectAs <User>()
            })
                                  .Results;

            //getEvent.usersGoingTo = new List<User>();
            getEvent = getEventQuery.ToList()[0].Event;
            if (getUsersGoingTo.Count() != 0)
            {
                getEvent.usersGoingTo = getUsersGoingTo.ToList()[0].Users.ToList();
            }
            getEvent.placeName      = getPlace.ToList()[0].PlaceName;
            getEvent.listOfSponsors = getSponsores.ToList()[0].Sponsor.ToList();
            return(getEvent);
        }