public Event GetEvent(long id) { var events = DbManager .ExecuteList(Query("photo_event").Select(Mappers.EventColumns).Where("Id", id)) .ConvertAll(r => Mappers.ToEvent(r)); return(0 < events.Count ? events[0] : null); }
private List <Album> ToAlbums(List <object[]> rawAlbums) { var eventIds = new List <long>(); var faceIds = new List <long>(); var albums = new List <Album>(rawAlbums.Count); foreach (var row in rawAlbums) { albums.Add(Mappers.ToAlbum(row)); var eventId = Convert.ToInt64(row[3]); if (!eventIds.Contains(eventId)) { eventIds.Add(eventId); } var faceId = Convert.ToInt64(row[4]); if (!faceIds.Contains(faceId)) { faceIds.Add(faceId); } } var events = DbManager .ExecuteList(Query("photo_event").Select(Mappers.EventColumns).Where(Exp.In("Id", eventIds.OrderBy(id => id).ToArray()))) .ConvertAll(r => Mappers.ToEvent(r)); var faces = DbManager .ExecuteList(Query("photo_image").Select(Mappers.ImageColumns).Where(Exp.In("Id", faceIds.OrderBy(id => id).ToArray()))) .ConvertAll(r => Mappers.ToImage(r)); albums.ForEach(a => { a.Event = events.Find(e => e.Id == a.EventId); a.FaceItem = faces.Find(f => f.Id == a.FaceImageId); if (a.FaceItem != null) { a.FaceItem.Album = a; } }); return(albums); }
public List <Event> GetEvents(int offset, int count) { return(DbManager .ExecuteList(GetEventsQuery().Select(Mappers.EventColumns).SetFirstResult(offset).SetMaxResults(count)) .ConvertAll(r => Mappers.ToEvent(r))); }