Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Action
- public async Task<IActionResult> Explore(
- string sortOrder)
- {
- var locationdata = from v in _context.Venues select new VenueModel{
- Category = v.Category,
- Price = v.Price,
- Name = v.Name,
- Id = v.Id,
- Rating = v.Rating,
- Description = v.Description,
- Image = v.Image,
- Address = v.Address,
- City = v.City,
- // Latitude = v.Latitude,
- // Longitude = v.Longitude,
- GetDistance = GetDistanceM(v.Latitude, v.Longitude, 27.692373, 85.318175)
- };
- var venues = locationdata.Where(x => (string.IsNullOrEmpty(searchString) || x.Name.Contains(searchString) ||
- x.Description.Contains(searchString) ||
- x.Category.Contains(searchString))
- && (string.IsNullOrEmpty(address) || x.City.Contains(address) || x.Address.Contains(address)));
- switch (sortOrder)
- {
- case "Location":
- venues = venues.OrderBy(s => s.GetDistance);
- break;
- default:
- venues = venues.OrderByDescending(s => s.GetDistance);
- break;
- }
- }
- //Method
- public static double GetDistanceM(double lat1, double long1, double lat2, double long2)
- {
- var sCoord = new GeoCoordinate(lat1, long1);
- var eCoord = new GeoCoordinate(lat2, long2);
- var distance = sCoord.GetDistanceTo(eCoord) / 1000;
- return (Math.Round(distance,2));
- }
- //View Model
- public class VenueModel
- {
- public int Id { get; set; }
- [MaxLength(200)]
- public string Name { get; set; }
- [MaxLength(100)]
- public string UserN {get;set;}
- public string Category { get; set; }
- public string Description {get;set;}
- [MaxLength(100)]
- public string Address {get;set;}
- public float Rating { get; set; }
- public int Price { get; set; }
- public string Image { get; set; }
- [MaxLength(100)]
- public string City { get; set; }
- public double Latitude { get; set; }
- public double Longitude { get; set; }
- public double GetDistance { get;set; }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement