public object Get(POIs request)
        {
            // Try to get the page limit parameter
            int pageLimit = 10;
            if (!request.Limit.IsNullOrEmpty())
            {
              pageLimit = int.Parse(request.Limit);
            }

            // Try to get the offset
            int skipResults = 0;
            if (!request.Offset.IsNullOrEmpty())
            {
              // If pagelimit is -1, skip parameters skips unitary elements
              skipResults = int.Parse(request.Offset) * ((pageLimit != -1) ? pageLimit : 1);
            }

            if (!request.Id.IsNullOrEmpty())
            {
                var objectID = ObjectId.Parse(request.Id);

                var poi = MongoDb.POIs.FindOneById(objectID);

                if (poi == null)
                {
                  base.Response.StatusCode = (int)HttpStatusCode.NotFound;
                  return "POI " + request.Id + " not found";
                }

                // Simple request by id
                if (request.Relation.IsNullOrEmpty())
                {
                  return BuildPOI(MongoDb.POICategories, poi, false);
                }

                if (request.Relation == "parent")
                {
                  MongoCursor<poi> parentPois = MongoDb.POIs.Find(Query.And(Query.EQ("link.term", "child"), Query.EQ("link.id",objectID)));
                  POISResponse parentResponse = new POISResponse();

                  foreach (poi p in parentPois.DistinctBy(d => d._id))
                  {
                    poi tmpPoi = BuildPOI(MongoDb.POICategories, p, false);

                    if(tmpPoi != null)
                      parentResponse.poi.Add(tmpPoi);
                  }

                  if (pageLimit != -1)
                    parentResponse.poi = parentResponse.poi.Skip(skipResults).Take(pageLimit).ToList();
                  else
                    parentResponse.poi = parentResponse.poi.Skip(skipResults).ToList();

                  return parentResponse;
                }

                if (request.Relation == "child")
                {

                  POISResponse childResponse = new POISResponse();

                  if(poi.link.IsNullOrEmpty())
                    return childResponse;

                  foreach (var link in poi.link)
                  {
                    if (link.term != "child")
                      continue;

                    if (ObjectId.TryParse(link.id, out objectID))
                    {
                      poi = MongoDb.POIs.FindOneById(objectID);

                      if (poi != null)
                        childResponse.poi.Add(BuildPOI(MongoDb.POICategories, poi, false));
                    }
                  }

                  if (pageLimit != -1)
                    childResponse.poi = childResponse.poi.Skip(skipResults).Take(pageLimit).ToList();
                  else
                    childResponse.poi = childResponse.poi.Skip(skipResults).ToList();

                  return childResponse;
                }

                if (request.Relation == "events")
                {
                  MongoCursor<@event> events = MongoDb.Events.Find(Query.EQ("location.relationship.targetPOI", objectID));
                  EventsResponse eventResponse = new EventsResponse();

                  if(events != null)
                    foreach (@event ev in events)
                    {
                      @event completeEvent = EventService.BuildEvent(MongoDb.EventCategories, MongoDb.POIs, ev);

                      if(completeEvent != null)
                        [email protected](completeEvent);
                    }

                  if (pageLimit != -1)
                    eventResponse.@event = [email protected](skipResults).Take(pageLimit).ToList();
                  else
                    eventResponse.@event = [email protected](skipResults).ToList();

                  return eventResponse;
                }

                if (request.Relation == "routes")
                {
                  MongoCursor<route> routes = MongoDb.Routes.Find(Query.EQ("pois.location.relationship.targetPOI", objectID));
                  RoutesResponse routeResponse = new RoutesResponse();

                  if(routes != null)
                    foreach(route rt in routes)
                    {
                      route completeRoute = RouteService.BuildRoute(MongoDb.RouteCategories, MongoDb.POIs, rt, false);

                      if(completeRoute != null)
                        routeResponse.routes.Add(completeRoute);
                    }

                  if (pageLimit != -1)
                    routeResponse.routes = routeResponse.routes.Skip(skipResults).Take(pageLimit).ToList();
                  else
                    routeResponse.routes = routeResponse.routes.Skip(skipResults).ToList();

                  return routeResponse;
                }

                base.Response.StatusCode = (int)HttpStatusCode.BadRequest;
                return "Invalid relation: " + request.Relation;
            }

            List<IMongoQuery> queries = new List<IMongoQuery>();

            //Category
            if (!request.Category.IsNullOrEmpty())
            {
                List<IMongoQuery> categoriesList = new List<IMongoQuery>();

                foreach (string category in request.Category.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    var catsTofind = MongoDb.POICategories.Find(
                      Query.And(
                        Query.EQ("term", "category"),
                        Query.Matches("label.value", new BsonRegularExpression(".*" + category + ".*", "-i")),
                        Query.Or(Query.NotExists("deleted"), Query.GT("deleted", BsonValue.Create(DateTime.UtcNow)))
                      )
                    );
                    categoriesList.AddRange(catsTofind.Select(category1 => Query.Or(new[] { Query.EQ("categoryIDs", category1._id) })));
                }

                if (categoriesList.Count > 0)
                    queries.Add(Query.Or(categoriesList));
                else
                {
                    // If no category was found, we can already reply a empty response...
                    return new POISResponse();
                }
            }

            QueryDocument qDoc = new QueryDocument();

            if (request.Deleted.IsNullOrEmpty())
            {
              queries.Add(Query.Or(Query.NotExists("deleted"), Query.GT("deleted", BsonValue.Create(DateTime.UtcNow))));
            }

            //Tag
            if (!request.Tag.IsNullOrEmpty())
            {
                queries.Add(Query.And(request.Tag.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(tag => Query.Or(new[] { Query.EQ("tags", tag) }))));
            }

            //Relation
            if (!request.Relation.IsNullOrEmpty())
            {
                queries.Add(Query.And(request.Relation.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(rel => Query.Or(new[] { Query.EQ("location.relationship.targetPOI", rel) }))));
            }

            //Minimal
            if (!request.Minimal.IsNullOrEmpty())
            {
                queries.AddRange(request.Minimal.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(word => Query.And(Query.Matches("label.value", "/.*" + word + ".*/i"))));
            }
            else if (!request.Complete.IsNullOrEmpty())
            {
                queries.AddRange(request.Complete.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(word => Query.And(Query.Matches("label.value", "/.*" + word + ".*/i"))));
            }

            if (!string.IsNullOrEmpty(request.Coords))
            {
                qDoc.AddRange(Utilities.GetGeoIntersect(request.Coords).ToBsonDocument());
            }

            if (queries.Count > 0)
                qDoc.AddRange(Query.And(queries).ToBsonDocument());

            MongoCursor<poi> pois = MongoDb.POIs.Find(qDoc);
            POISResponse response = new POISResponse();

            bool minimal = !request.Minimal.IsNullOrEmpty();
            foreach (var p in pois.DistinctBy(d => d._id))
            {
              poi tmpPoi = BuildPOI(MongoDb.POICategories, p, minimal);

              if(tmpPoi != null)
                response.poi.Add(tmpPoi);
            }

            if (pageLimit != -1)
              response.poi = response.poi.Skip(skipResults).Take(pageLimit).ToList();
            else
              response.poi = response.poi.Skip(skipResults).ToList();

            return response;
        }
        public object Get(Routes request)
        {
            if (!request.Id.IsNullOrEmpty())
            {
                var objectID = ObjectId.Parse(request.Id);

                var ev = MongoDb.Routes.FindOneById(objectID);

                return BuildRoute(MongoDb.RouteCategories, MongoDb.POIs, ev, true);
            }

            List<IMongoQuery> queries = new List<IMongoQuery>();

            //Category
            if (!request.Category.IsNullOrEmpty())
            {
                List<IMongoQuery> categoriesList = new List<IMongoQuery>();

                foreach (string category in request.Category.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
                {
                    var catsTofind = MongoDb.RouteCategories.Find(
                      Query.And(
                        Query.EQ("term", "category"),
                        Query.Matches("label.value", BsonRegularExpression.Create(".*" + category + ".*", "-i")),
                        Query.Or(Query.NotExists("deleted"), Query.GT("deleted", BsonValue.Create(DateTime.UtcNow)))
                      )
                    );
                    categoriesList.AddRange(catsTofind.Select(category1 => Query.Or(new[] { Query.EQ("categoryIDs", category1._id) })));
                }

                if (categoriesList.Count > 0)
                    queries.Add(Query.Or(categoriesList));
                else
                {
                    return new RoutesResponse();
                }
            }

            //Tag
            if (!request.Tag.IsNullOrEmpty())
            {
                queries.Add(Query.And(request.Tag.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(tag => Query.Or(new[] { Query.EQ("tags", tag) }))));
            }

            //Search
            if (!request.Name.IsNullOrEmpty())
            {
                queries.Add(Query.And(Query.Matches("label.value", "/.*" + request.Name + ".*/i")));
            }

            QueryDocument qDoc = new QueryDocument();

            queries.Add(Query.Or(Query.NotExists("deleted"), Query.GT("deleted", BsonValue.Create(DateTime.UtcNow))));
            qDoc.Add(Query.And(queries).ToBsonDocument());

            MongoCursor<route> routes = MongoDb.Routes.Find(qDoc);

            List<route> FinalRoutes = routes.ToList();

            if (!string.IsNullOrEmpty(request.Coords))
            {
                FinalRoutes = new List<route>();

                foreach (var route in routes)
                {

                    List<IMongoQuery> qs = new List<IMongoQuery>();
                    foreach (var p in route.pois)
                    {
                        if (p.location != null && p.location.relationship != null && p.location.relationship.Count > 0)
                        {
                            var rel = p.location.relationship.AsQueryable().FirstOrDefault(w => w.term == "equals");
                            if (rel != null)
                            {
                                qs.Add(Query.EQ("_id", rel.targetPOI));
                            }
                        }
                    }

                    QueryDocument q1 = new QueryDocument();
                    q1.AddRange(Utilities.GetGeoIntersect(request.Coords).ToBsonDocument());
                    q1.AddRange(Query.Or(qs).ToBsonDocument());

                    if (MongoDb.POIs.Find(q1).Any())
                    {
                        FinalRoutes.Add(route);
                    }
                }
            }

            /*
            if (!request.Show.IsNullOrEmpty())
            {
                int start = int.Parse(request.Show.SplitOnFirst(',')[0]);
                int end = int.Parse(request.Show.SplitOnFirst(',')[1]);

                FinalRoutes = FinalRoutes.Skip(start).Take(end - start).ToList();
            }
            */

            int pageLimit = 10;
            if (!request.Limit.IsNullOrEmpty())
            {
                pageLimit = int.Parse(request.Limit);
            }

            int skipResults = 0;
            if (!request.Offset.IsNullOrEmpty())
            {
              skipResults = int.Parse(request.Offset) * ((pageLimit != -1) ? pageLimit : 1);
            }

            if (pageLimit != -1)
              FinalRoutes = FinalRoutes.Skip(skipResults).Take(pageLimit).ToList();
            else
              FinalRoutes = FinalRoutes.Skip(skipResults).ToList();

            RoutesResponse response = new RoutesResponse();
            foreach (var p in FinalRoutes)
            {
                //response.routes.Add(new RouteResponse { route = BuildRoute(p) });
              response.routes.Add(BuildRoute(MongoDb.RouteCategories, MongoDb.POIs, p, false));
            }

            return response;
        }