public static List <Friend> FindAllFriendsWithLending() { using (var db = new DBContext()) { try { List <Lending> lendingList = Lending.FindLendingOpened(); List <Friend> friendList = db.Friend.ToList(); List <Friend> returnList = new List <Friend>(); foreach (var item in friendList) { if (lendingList.Any(p => p.FriendId == item.ID)) { returnList.Add(item); } } return(returnList); } catch (Exception ex) { //LogError.insertLog(new LogError(ex.Message, ex.StackTrace)); throw; } } }
public static List <Games> FindNoLendedGames() { using (var db = new DBContext()) { try { //List<Games> gamesList = db.Games.ToList(); //List<Games> gamesOut = new List<Games>(); //List<Games> returnList = new List<Games>(); //foreach (var item in gamesList) //{ // var a = lendingList.Where(p => p.GameId == item.ID).ToList(); // if (lendingList.Contains(item)) // { // } // returnList.Add(); //} //foreach (var item in lendingList) //{ // gamesOut.Add(item.Games); //} //returnList = gamesList.Except(gamesOut).ToList(); //foreach (var item in lendingList) //{ // gamesOut.Add(item.Games); //} //foreach (var item in gamesList) //{ // if (!gamesOut.Contains(item)) // { // returnList.Add(item); // } //} //return returnList; var lendingList = Lending.FindLendingOpened().AsQueryable(); //var listGames = db.Games.Where(g => !lendingList.Any(l => l.GameId == g.ID)).ToList(); var listGames = db.Games .Where(g => !db.Lending.Any(l => l.GameId == g.ID && string.IsNullOrEmpty(l.DateReturned.Value.ToString()))) .ToList(); return(listGames); } catch (Exception ex) { //LogError.insertLog(new LogError(ex.Message, ex.StackTrace)); throw; } } }