private static List <Models.Accommodation.Likibu.Destination> ParseJSON4Destinations(string js) { var jo = JObject.Parse(js); List <Models.Accommodation.Likibu.Destination> dest = new List <Models.Accommodation.Likibu.Destination>(); int num = jo["results"].Count(); for (int i = 0; i < num; i++) { string id = jo["results"][i]["id"].ToString(); string name = jo["results"][i]["name"].ToString(); string pname = jo["results"][i]["parent_name"].ToString(); int numRes = Int32.Parse(jo["results"][i]["results"].ToString()); string ccode = jo["results"][i]["country_code"].ToString(); Models.Accommodation.Likibu.Destination d = new Models.Accommodation.Likibu.Destination(id, name, pname, numRes, ccode); dest.Add(d); } return(dest); }
private async Task <Models.Find.RequestResults> GetRequestSearchResults(Models.Find.SearchVM searchVM) { string destination = searchVM.Search.Location; Models.Accommodation.Likibu.Destination dest = (await GetGeolocationString(destination, searchVM.Language, "1")).FirstOrDefault(); string destID = dest.ID; using (var db = new ApplicationDbContext()) { IQueryable <Models.Request.Request> retQ = db.Requests.Where(p => p.Accommodation.AccomProfile.DestinationIDs.Contains(destID)).Include(p => p.Accommodation).Include(p => p.Accommodation.AccomProfile); /// Destination Ids have to be updated //retQ = FilterCheckTimeRequests(searchVM, retQ, 3.0f); retQ = retQ.Where(p => p.objState == BaseDataObject.ObjectState.Valid); int totalres = retQ.Count(); int page = int.Parse(searchVM.Search.FilterProps.Page); int perpage = int.Parse(searchVM.Search.FilterProps.PerPage); IEnumerable <Models.Request.Request> retList = await retQ.ToListAsync(); if (page > 1) { retList = retList.Skip(perpage * (page - 1)); } retList = retList.Take(perpage); List <Models.Request.RequestVMListing> retListFiltered = new List <Models.Request.RequestVMListing>(); foreach (var rq in retList) //Filter invalid requests { if (rq.IsValid()) { Models.VM.ProfilePreviewVM host = await ProfilesController.ProfilePreviewVM(rq.RequestOwner_ID); retListFiltered.Add(new Models.Request.RequestVMListing(rq, "", host)); //stats } } searchVM.RequestResults = new Models.Find.RequestResults(retListFiltered, page, perpage, totalres); //int.Parse(searchVM.Search.FilterProps.Page), int.Parse(searchVM.Search.FilterProps.PerPage) return(searchVM.RequestResults); } }