Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class LocationDataAccess : ILocationDataAccess
- {
- private IDBConnectionFactory Conn { get; }
- public LocationDataAccess(IDBConnectionFactory connection)
- {
- Conn = connection;
- }
- public async Task<IEnumerable<Location>> GetAllLocations()
- {
- var sql = @"Select * FROM Location";
- using (var connection = await Conn.GetOpenConnectionAsync())
- {
- var locations = await connection.QueryAsync<Location>(sql);
- return locations.ToList();
- }
- }
- public async Task<Location> Randomize()
- {
- var locations = await GetAllLocations();
- Random rand = new Random();
- int toSkip = rand.Next(0, locations.Count());
- var loc = locations.OrderBy(x => x.ID)
- .Skip(toSkip)
- .Take(1).First();
- return loc;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement