Skip to content

Instantly share code, notes, and snippets.

@wayne-o
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wayne-o/97de92256a306b26c77e to your computer and use it in GitHub Desktop.
Save wayne-o/97de92256a306b26c77e to your computer and use it in GitHub Desktop.
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