public Album_t GetAlbumById(int id, bool checkAllFiles = true) { var queryAlbum = _ar.GetById(id); var listFiles = (from f in _entities.File_t where f.Album_Id == id select new { Album_Id = f.Album_Id, CreatedDate = f.CreatedDate, IsOnTopAlbum = f.IsOnTopAlbum, Id = f.Id, Sort = f.Sort, FileName = f.FileName, Title = f.Title, Description = f.Description }).ToList(); //Where cust.Orders.Count > 0 And // cust.CompanyName.StartsWith("H") //Select cust.CustomerID, cust.CompanyName, // OrderCount = cust.Orders.Count, // cust.Country var album = new Album_t() { Id = id }; var list = listFiles.Select(f => new File_t() { Album_Id = f.Album_Id, CreatedDate = f.CreatedDate, IsOnTopAlbum = f.IsOnTopAlbum, Id = f.Id, Sort = f.Sort, FileName = f.FileName, Title = f.Title, Description = f.Description }).ToList(); if (queryAlbum != null) { var o = _nr.GetAll().Where(n => n.AlbumId == queryAlbum.Id); album.Id = queryAlbum.Id; album.CreatedDate = queryAlbum.CreatedDate; album.File_t = list; album.Name = o.Any() ? o.First().Title : ""; album.AlbumTypeId = queryAlbum.AlbumTypeId; } List <File_t> tmplist = null; if (checkAllFiles) { tmplist = album.File_t.OrderBy(f => f.Sort).ToList(); } else { tmplist = album.File_t.Where(f => f.IsOnTopAlbum).ToList(); } foreach (var item in tmplist) { item.InitialisePaths(_serverPath); if (!PictureHelper.CheckFiles(item)) { PictureHelper.SaveImageToDirectory(_fr.GetById(item.Id).Image, item); } } return(album); }
public ICollection <Album_t> GetAlbums(int?userId = null) { var listAlbumIdsInfNews = _nr.GetAll().Select(n => n.AlbumId).ToList(); var result = new Collection <Album_t>(); var albums = _ar.GetAll().Where(a => a.AlbumTypeId == 2).OrderByDescending(a => a.CreatedDate).ToList(); foreach (var album in albums) { // skip album which is not of event if (userId == null && !listAlbumIdsInfNews.Contains(album.Id)) { continue; } else { var queryNew = _nr.GetAll().Where(n => n.AlbumId == album.Id); if (queryNew.Any()) { var o = queryNew.First(); album.Name = o.Title; } } var itemResult = new Album_t() { Id = album.Id, CreatedDate = album.CreatedDate, Name = album.Name }; var query = (from f in _entities.File_t where f.Album_Id.Value == album.Id && f.IsOnTopAlbum select new { Album_Id = f.Album_Id, CreatedDate = f.CreatedDate, IsOnTopAlbum = f.IsOnTopAlbum, Id = f.Id, Sort = f.Sort, FileName = f.FileName, Title = f.Title, Description = f.Description }) .ToList() .Select(f => new File_t() { Album_Id = f.Album_Id, CreatedDate = f.CreatedDate, IsOnTopAlbum = f.IsOnTopAlbum, Id = f.Id, Sort = f.Sort, FileName = f.FileName, Title = f.Title, Description = f.Description }).ToList(); if (query.Any()) { itemResult.File_t = new Collection <File_t>() { query.First() }; } else { itemResult.File_t = new Collection <File_t>(); } result.Add(itemResult); } // save to disk foreach (var item in result) { if (item.File_t.Any()) { var file = item.File_t.FirstOrDefault(); file.InitialisePaths(_serverPath); if (!PictureHelper.CheckFiles(file)) { PictureHelper.SaveImageToDirectory(_fr.GetById(file.Id).Image, file); } } } return(result); }