Last active
August 29, 2015 14:07
-
-
Save wayne-o/97de92256a306b26c77e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public object Get(LineupRequest request) | |
{ | |
var response = new LineupResponse (); | |
var sw = new Stopwatch (); | |
sw.Start (); | |
using(var db = con.Open ()){ | |
var eventInstance = db.LoadSelect <Model.EventInstance>(q => q.Slug == request.Slug).FirstOrDefault (); | |
var locationIds = eventInstance.Locations.Select (x => x.Id); | |
if (!string.IsNullOrEmpty (request.Query)) { | |
var listingEvents = db.SelectFmt<ListingEventDto> ( | |
"select *, location.name as LocationName from listing_event, location where listing_event.location_id = location.id AND listing_event.event_instance_slug = {3} AND (LOWER(location.name) like LOWER({0}) or LOWER(listing_event.name) like LOWER({0})) LIMIT {1} OFFSET {2};", | |
"%" + request.Query + "%", request.Take, request.Skip, eventInstance.Slug); | |
response.ListingEvents.AddRange(listingEvents); | |
} else { | |
var listingEvents = db.Select <Model.ListingEvent> (q => q.Where (le => locationIds.Contains (le.LocationId)).Limit (skip: request.Skip, rows: request.Take)); | |
listingEvents.ForEach (x => response.ListingEvents.Add (x.ConvertTo <ListingEventDto> ())); | |
} | |
} | |
sw.Stop (); | |
response.ExecutionTime = sw.ElapsedMilliseconds; | |
return response; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment