Example #1
0
        public ActionResult GetRoutesWithPiecesInArea(string minLatLng, string maxLatLng)
        {
            Response.AppendHeader("Access-Control-Allow-Origin", "*");
            try
            {
                SearchPosition min = SearchPosition.CreateSearchPosition(minLatLng, null);
                SearchPosition max = SearchPosition.CreateSearchPosition(maxLatLng, null);

                if (min != null && max != null)
                {
                    var routePieces = DataHandler.GetRoutePiecesTouchingArea(min.Lat, min.Lng, max.Lat, max.Lng);

                    var byRoute = routePieces.Where(x => x.Route.Email != "*****@*****.**").GroupBy(x => x.RouteID);

                    var jsonRoutes = byRoute.Select(r => new { ID = r.First().Route.ID, TypeID = r.First().Route.TypeID, Name = r.First().Route.Name, FromName = r.First().Route.FromName, ToName = r.First().Route.ToName, Path = r.OrderBy(x => x.ID).Select(x => new { Lat = x.Lat, Lng = x.Lng, Name = x.Name }) });

                    return(Json(jsonRoutes, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(new { error = "Wrong parameters" }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                DataHandler.WriteException(ex, Request.UserHostAddress);
                return(Json(new { error = "Internal server error" }, JsonRequestBehavior.AllowGet));
            }
        }
Example #2
0
        private void SetControls(int index)
        {
            EnableAllControls();
            switch (index)
            {
            case 0:
                SetBookView();
                addPosition    = AddBook;
                editPosition   = EditBook;
                searchPosition = SearchBook;
                break;

            case 1:
                SetGameView();
                addPosition    = AddGame;
                editPosition   = EditGame;
                searchPosition = SearchGame;
                break;

            case 2:
                SetMagazineView();
                addPosition    = AddMagazineNumber;
                editPosition   = EditMagazineNumber;
                searchPosition = SearchMagazineNumber;
                break;
            }
        }
Example #3
0
        public ActionResult GetRoutesInArea(string minLatLng, string maxLatLng)
        {
            Response.AppendHeader("Access-Control-Allow-Origin", "*");
            try
            {
                SearchPosition min = SearchPosition.CreateSearchPosition(minLatLng, null);
                SearchPosition max = SearchPosition.CreateSearchPosition(maxLatLng, null);

                if (min != null && max != null)
                {
                    var routes     = DataHandler.GetRoutesInArea(min.Lat, min.Lng, max.Lat, max.Lng);
                    var jsonRoutes = routes.Select(r => new { ID = r.ID, TypeName = r.Type.Name, FromName = r.FromName, ToName = r.ToName, Name = r.Name });

                    return(Json(jsonRoutes, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(new { error = "Wrong parameters" }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                DataHandler.WriteException(ex, Request.UserHostAddress);
                return(Json(new { error = "Internal server error" }, JsonRequestBehavior.AllowGet));
            }
        }
Example #4
0
        public void ApplyFilter()
        {
            ICollectionView view = GetMoviesCollectionView();

            if (view != null)
            {
                view.Filter = delegate(object item)
                {
                    Movie          movie    = (Movie)item;
                    SearchPosition position = SearchHelper.FindSearchPosition(cbxFilterPosition.SelectedIndex);

                    if (!SearchHelper.ContainsText(Database.Filter.Name, movie.Name, position) ||
                        !SearchHelper.ContainsText(Database.Filter.Storage, movie.Storage, position) ||
                        !SearchHelper.ContainsItems(Database.Filter.Category, movie.Category, ',') ||
                        !SearchHelper.ContainsText(Database.Filter.Year, movie.Year.ToString(), position) ||
                        !SearchHelper.ContainsText(Database.Filter.Country, movie.Country, position) ||
                        !SearchHelper.ContainsItems(Database.Filter.Actors, movie.Actors, ',') ||
                        !SearchHelper.IsNewerThen(Database.Filter.Added, movie.Added) ||
                        !SearchHelper.TestThreeStatesTrue(Database.Filter.Starred, movie.Starred)
                        )
                    {
                        return(false);
                    }

                    return(true);
                };
            }
        }
Example #5
0
 public async Task <IActionResult> Result([Bind("TypeId,Title,Author")] SearchPosition item)
 {
     if (ModelState.IsValid)
     {
         var itemList = repository.Search(item.TypeId, item.Title, item.Author);
         return(View(itemList.ToList()));
     }
     return(View());
 }
Example #6
0
        public HttpResponseMessage Get([FromUri] SearchPosition pos)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateResponseForInvalidModelState());
            }

            if (pos.R > _MAX_LOCATIONS_SEARCH_R)
            {
                pos.R = _MAX_LOCATIONS_SEARCH_R;
            }
            else if (pos.R <= _MIN_LOCATIONS_SEARCH_R)
            {
                pos.R = _MIN_LOCATIONS_SEARCH_R;
            }
            else
            {
                pos.R = (int)pos.R;
            }

            var locations = new List <LocationDTO>();
            IEnumerable <LocationDTO> dbLocations;

            using (var repos = DataRepos.Instance)
            {
                dbLocations = repos.Locations.GetAllAround(pos.P.Lat, pos.P.Lng, pos.R);
            }

            var myCoord = new GeoCoordinate(double.Parse(pos.P.Lat, CultureInfo.InvariantCulture),
                                            double.Parse(pos.P.Lng, CultureInfo.InvariantCulture));
            double distance = pos.R * 1000;

            foreach (var location in dbLocations)
            {
                var locCoord = new GeoCoordinate(double.Parse(location.Lat, CultureInfo.InvariantCulture),
                                                 double.Parse(location.Lng, CultureInfo.InvariantCulture));

                if (myCoord.GetDistanceTo(locCoord) <= distance)
                {
                    locations.Add(location);
                }
            }

            return(Request.CreateResponse(HttpStatusCode.OK, locations));
        }
Example #7
0
        public static bool ContainsText(string filter, string text, SearchPosition position = SearchPosition.StartsWith)
        {
            if (String.IsNullOrEmpty(filter))
            {
                return(true);
            }

            if (String.IsNullOrEmpty(text))
            {
                return(String.IsNullOrEmpty(filter));
            }

            if ((position == SearchPosition.StartsWith && text.ToLowerInvariant().StartsWith(filter.ToLowerInvariant())) ||
                (position == SearchPosition.EndsWith && text.ToLowerInvariant().EndsWith(filter.ToLowerInvariant())) ||
                (position == SearchPosition.Contains && text.ToLowerInvariant().Contains(filter.ToLowerInvariant())) ||
                (position == SearchPosition.Equals && text.ToLowerInvariant().Equals(filter.ToLowerInvariant()))
                )
            {
                return(true);
            }

            return(false);
        }
Example #8
0
        public ActionResult Search(string de, string a, int?count, string key)
        {
            Response.AppendHeader("Access-Control-Allow-Origin", "*");
            try
            {
                var error = DataHandler.ChargeServiceCall("/Service/Search", key, Request.UserHostAddress, de + "|" + a + "|" + count);

                if (error == null)
                {
                    int c = count ?? 1;
                    if (c > 5)
                    {
                        c = 5;
                    }
                    if (c < 1)
                    {
                        c = 1;
                    }

                    SearchResultModel model = new SearchResultModel();

                    Searcher searcher = new Searcher(ViaDFGraph.Instance);

                    SearchPosition spFrom = SearchPosition.CreateSearchPosition(de, null);
                    SearchPosition spTo   = SearchPosition.CreateSearchPosition(a, null);

                    if (spFrom != null && spTo != null)
                    {
                        SearchParams sp = new SearchParams();
                        sp.StartSearch = spFrom;
                        sp.StartSearch.LoadNameFromDB();
                        sp.EndSearch = spTo;
                        sp.EndSearch.LoadNameFromDB();
                        sp.NrOfResults = c;

                        DataHandler.LogSearch(sp, Request.UserHostAddress);

                        List <SearchResult> results = searcher.DoSearch(sp);
                        model.Results = results;
                    }
                    else
                    {
                        model.Results = new List <SearchResult>();
                    }

                    using (var stream = new MemoryStream())
                    {
                        new DataContractJsonSerializer(typeof(SearchResultModel)).WriteObject(stream, model);
                        return(Content(Encoding.UTF8.GetString(stream.ToArray()), "application/json", Encoding.UTF8));
                    }
                }
                else
                {
                    return(Json(new { error = error }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                DataHandler.WriteException(ex, Request.UserHostAddress);
                return(Json(new { error = "Internal server error" }, JsonRequestBehavior.AllowGet));
            }
        }
Example #9
0
        public ActionResult Search(string de, string a, string origen, string destino)
        {
            Response.Cache.SetCacheability(HttpCacheability.Private);
            Response.Cache.SetLastModified(DateTime.Now);

            // check if available on client cache
            if (!string.IsNullOrEmpty(Request.Headers["If-Modified-Since"]))
            {
                Response.StatusCode        = 304;
                Response.StatusDescription = "Not Modified";
                return(null);
            }

            // try to get coordinates from strings
            if ((string.IsNullOrWhiteSpace(de) || string.IsNullOrWhiteSpace(a)) && !string.IsNullOrWhiteSpace(origen) && !string.IsNullOrWhiteSpace(destino))
            {
                SearchPosition from = Utils.GeoCodeSearchPosition(origen.Trim());
                SearchPosition to   = Utils.GeoCodeSearchPosition(destino.Trim());

                if (from != null && to != null)
                {
                    de = from.Lat.ToString(CultureInfo.InvariantCulture) + "," + from.Lng.ToString(CultureInfo.InvariantCulture);
                    a  = to.Lat.ToString(CultureInfo.InvariantCulture) + "," + to.Lng.ToString(CultureInfo.InvariantCulture);
                }
            }

            if (!string.IsNullOrWhiteSpace(de) && !string.IsNullOrWhiteSpace(a))
            {
                SearchPosition spFrom = SearchPosition.CreateSearchPosition(de, origen);
                SearchPosition spTo   = SearchPosition.CreateSearchPosition(a, destino);

                if (spFrom != null && spTo != null)
                {
                    Searcher     searcher = new Searcher(ViaDFGraph.Instance);
                    SearchParams sp       = new SearchParams();
                    sp.StartSearch = spFrom;
                    sp.StartSearch.LoadNameFromDB();
                    sp.EndSearch = spTo;
                    sp.EndSearch.LoadNameFromDB();
                    sp.NrOfResults = 3;

                    // log search
                    DataHandler.LogSearch(sp, Request.UserHostAddress);

                    if (string.IsNullOrWhiteSpace(sp.StartSearch.Name))
                    {
                        sp.StartSearch.Name = "Origen";
                    }
                    if (string.IsNullOrWhiteSpace(sp.EndSearch.Name))
                    {
                        sp.EndSearch.Name = "Destino";
                    }

                    List <SearchResult> results = searcher.DoSearch(sp);

                    if (results.Count > 0)
                    {
                        SearchResultModel model = new SearchResultModel();
                        model.Results         = results;
                        model.CloseBusinesses = DataHandler.GetCloseBusinesses(spTo.Lat, spTo.Lng, 0.25, 30);

                        SetSEO(results[0].Start.Name + " a " + results[0].End.Name + " - ¿Cómo llegar en transporte público?", "", "");

                        return(View("Search", model));
                    }
                }
            }

            return(View("NotFound"));
        }