public static ActorInfo ActorInfo(int actorId) { ActorInfo fullInfo = new ActorInfo(); List <Photo> allPhotos; using (ActorsDb db = new ActorsDb()) { allPhotos = db.Photos.Where(p => p.ActorId.Equals(actorId)).ToList(); } fullInfo.Photos = allPhotos.Select(r => new PhotoModel { PhotoId = r.Id, PhotoPath = r.Path }).ToList(); return(fullInfo); }
public static List <MainPageViewModel> GetAllActors() { List <Actor> actors; List <Photo> mainPhotos; using (ActorsDb db = new ActorsDb()) { actors = db.Actors.ToList(); mainPhotos = db.Photos.Where(p => p.IsMain).ToList(); } var res = actors.Select(a => new MainPageViewModel { ActorId = a.Id, ActorName = a.FullName, Gender = a.Gender, PhotoPath = mainPhotos.SingleOrDefault(p => p.ActorId.Equals(a.Id))?.Path }) .ToList(); return(res); }