Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2020
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. //Action
  2. public async Task<IActionResult> Explore(
  3. string sortOrder)
  4. {
  5. var locationdata = from v in _context.Venues select new VenueModel{
  6. Category = v.Category,
  7. Price = v.Price,
  8. Name = v.Name,
  9. Id = v.Id,
  10. Rating = v.Rating,
  11. Description = v.Description,
  12. Image = v.Image,
  13. Address = v.Address,
  14. City = v.City,
  15. // Latitude = v.Latitude,
  16. // Longitude = v.Longitude,
  17. GetDistance = GetDistanceM(v.Latitude, v.Longitude, 27.692373, 85.318175)
  18.  
  19. };
  20.  
  21. var venues = locationdata.Where(x => (string.IsNullOrEmpty(searchString) || x.Name.Contains(searchString) ||
  22. x.Description.Contains(searchString) ||
  23. x.Category.Contains(searchString))
  24. && (string.IsNullOrEmpty(address) || x.City.Contains(address) || x.Address.Contains(address)));
  25.  
  26. switch (sortOrder)
  27. {
  28. case "Location":
  29. venues = venues.OrderBy(s => s.GetDistance);
  30. break;
  31. default:
  32. venues = venues.OrderByDescending(s => s.GetDistance);
  33. break;
  34. }
  35.  
  36. }
  37. //Method
  38. public static double GetDistanceM(double lat1, double long1, double lat2, double long2)
  39. {
  40. var sCoord = new GeoCoordinate(lat1, long1);
  41. var eCoord = new GeoCoordinate(lat2, long2);
  42. var distance = sCoord.GetDistanceTo(eCoord) / 1000;
  43. return (Math.Round(distance,2));
  44. }
  45. //View Model
  46. public class VenueModel
  47. {
  48. public int Id { get; set; }
  49. [MaxLength(200)]
  50. public string Name { get; set; }
  51. [MaxLength(100)]
  52. public string UserN {get;set;}
  53.  
  54.  
  55. public string Category { get; set; }
  56. public string Description {get;set;}
  57. [MaxLength(100)]
  58. public string Address {get;set;}
  59. public float Rating { get; set; }
  60.  
  61. public int Price { get; set; }
  62. public string Image { get; set; }
  63. [MaxLength(100)]
  64.  
  65.  
  66. public string City { get; set; }
  67. public double Latitude { get; set; }
  68. public double Longitude { get; set; }
  69.  
  70. public double GetDistance { get;set; }
  71.  
  72.  
  73.  
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement