Пример #1
0
        public AlbumItem GetAlbumItem(Album album, int index)
        {
            if (album == null)
            {
                return(null);
            }

            var images = DbManager
                         .ExecuteList(
                Query("photo_image")
                .Select(Mappers.ImageColumns)
                .Where("Album", album.Id)
                .OrderBy("Name", true)
                .OrderBy("Id", true)
                .SetMaxResults(1).SetFirstResult(index))
                         .ConvertAll(r => Mappers.ToImage(r));

            if (images.Count == 0)
            {
                return(null);
            }

            var image = images[0];

            image.Album = album;
            if (album != null && album.FaceImageId == image.Id)
            {
                album.FaceItem = image;
            }

            return(image);
        }
Пример #2
0
        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);
        }
Пример #3
0
        public AlbumItem GetAlbumItem(long id)
        {
            var images = DbManager
                         .ExecuteList(Query("photo_image").Select(Mappers.ImageColumns).Where("Id", id))
                         .ConvertAll(r => Mappers.ToImage(r));

            if (images.Count == 0)
            {
                return(null);
            }

            var image = images[0];

            image.Album = GetAlbum(image.AlbumId);
            if (image.Album != null && image.Album.FaceImageId == image.Id)
            {
                image.Album.FaceItem = image;
            }

            return(image);
        }
Пример #4
0
        public List <AlbumItem> GetAlbumItems(Album album)
        {
            if (album == null)
            {
                return(new List <AlbumItem>());
            }

            var images = DbManager
                         .ExecuteList(Query("photo_image").Select(Mappers.ImageColumns).Where("Album", album.Id).OrderBy("Name", true).OrderBy("Id", true))
                         .ConvertAll(r => Mappers.ToImage(r));

            images.ForEach(i =>
            {
                i.Album = album;
                if (i.Id == album.FaceImageId)
                {
                    album.FaceItem = i;
                }
            });

            return(images);
        }