/// <summary> /// Add it to Sorted list if rooms greater than 5 /// </summary> /// <param name="houseData"></param> /// <param name="curHouse"></param> private void PopulateSortedHouseByRooms(HouseData houseData, HouseInfo curHouse) { if (curHouse.Rooms > 5) { houseData.SortedHouseByRooms.Add(curHouse); } }
/// <summary> /// Populate nearest house by distance /// </summary> /// <param name="houseData"></param> /// <param name="curHouse"></param> private void PopulateNearestHouse(HouseData houseData, HouseInfo curHouse) { //Filter with number of rooms and value. if (curHouse.Rooms >= 10 && curHouse.Value <= 5000000) { houseData.NearestHouse = houseData.NearestHouse == null ? curHouse : (houseData.NearestHouse.Distance <= curHouse.Distance) ? houseData.NearestHouse : curHouse; } }
/// <summary> /// This function will return /// Sorted Houses by Distance /// Sorted Houses by Rooms with min 5 rooms /// Sorted Houses by Street if room info misses /// Get Nearest house from sister house and with more rooms with 10 rooms and 5000000 value /// </summary> /// <param name="baseHouseList"></param> /// <returns></returns> public HouseData GetSortedHouseInfo(List <House> baseHouseList = null) { if (baseHouseList == null) { baseHouseList = GetListofHouses(); } HouseData houseData = new HouseData(); var baseCord = PopulateHouseCoordsBasedOnAddress(); foreach (var curHouse in baseHouseList) { var eCoord = new GeoCoordinate(curHouse.coords.lat, curHouse.coords.lon); curHouse.distance = baseCord.GetDistanceTo(eCoord); HouseInfo houseInfo = curHouse.GetHouseInfo(); houseData.SourceData.Add(houseInfo); PopulateSortedHouseByDistance(houseData, houseInfo); //Indicates we don't have full information so sort them by Street if (curHouse.@params == null || [email protected] <= 0 || [email protected] <= 0) { PopulateSortedHouseByStreet(houseData, houseInfo); } else //Indicates we have full information so sort them by rooms { PopulateSortedHouseByRooms(houseData, houseInfo); PopulateNearestHouse(houseData, houseInfo); } } houseData.SortedHouseByDistance.Sort((curr, comp) => curr.Distance.CompareTo(comp.Distance)); houseData.SortedHouseByRooms.Sort((curr, comp) => curr.Rooms.CompareTo(comp.Rooms)); houseData.SortedHouseByStreet.Sort((curr, comp) => curr.Street.CompareTo(comp.Street)); return(houseData); }
/// <summary> /// Add it to Sorted list /// </summary> /// <param name="houseData"></param> /// <param name="curHouse"></param> private void PopulateSortedHouseByStreet(HouseData houseData, HouseInfo curHouse) { houseData.SortedHouseByStreet.Add(curHouse); }
/// <summary> /// Add it to Sorted list /// </summary> /// <param name="houseData"></param> /// <param name="curHouse"></param> private void PopulateSortedHouseByDistance(HouseData houseData, HouseInfo curHouse) { houseData.SortedHouseByDistance.Add(curHouse); }