public static AlbumFullModel CreateFullAlbumModelFromEntity(Album entity) { return new AlbumFullModel() { AlbumId = entity.AlbumId, Title = entity.Title, ParentAlbumId = entity.ParentAlbumId, SubAlbums = entity.Albums1.Select(a => new AlbumModel() { AlbumId = a.AlbumId, ParentAlbumId = a.ParentAlbumId, Title = a.Title, }), Images = entity.Images.Select(i => new ImageModel() { AlbumId = i.AlbumId, ImageId = i.ImageId, Title = i.Title, Url = i.Url, }) }; }
public AlbumFullModel GetUserGallery(int userId) { User user = this.repos.UserRepo.Get(userId); Album gallery = this.repos.AlbumRepo.GetAll() .Where(a => a.UserId == user.UserId && a.ParentAlbumId == null) .FirstOrDefault(); if (gallery == null) { gallery = new Album() { Title = "Gallery of " + user.Username, User = user, ParentAlbumId = null, }; this.repos.AlbumRepo.Add(gallery); } AlbumFullModel galleryModel = AlbumFullModel.CreateFullAlbumModelFromEntity(gallery); return galleryModel; }