public List <Wishlist> GetOpenParticipatingWishlistsByUserId(int userId) { try { using (WishlistDbContext context = new WishlistDbContext()) { context.Database.EnsureCreated(); List <Wishlist> ws = new List <Wishlist>(); foreach (User c in User.Contacts) { foreach (int wi in context.OwnedWishlists.Where(ow => ow.OwnerId == c.UserId && !ow.IsFavorite).Select(wo => wo.WishlistId).ToList()) { if (context.Wishlists.FirstOrDefault(w => w.WishlistId == wi).IsOpen) { Wishlist wl = context.Wishlists.FirstOrDefault(w => w.WishlistId == wi); wl.SetDeadlineText(); wl.Owner = context.Users.FirstOrDefault(o => o.UserId == context.OwnedWishlists.FirstOrDefault(ow => ow.WishlistId == wi).OwnerId); ws.Add(wl); } } } return(ws); } } catch (Exception eContext) { Debug.WriteLine("Exception: " + eContext.Message); return(null); } }
public List <Wishlist> GetClosedParticipatingWishlistsByUserId(int userId) { try { using (WishlistDbContext context = new WishlistDbContext()) { context.Database.EnsureCreated(); List <Wishlist> ws = new List <Wishlist>(); foreach (int id in context.Participants.Where(p => p.ParticipantId == User.UserId).Select(p => p.WishlistId).ToList()) { Wishlist wl = context.Wishlists.FirstOrDefault(w => w.WishlistId == id); wl.SetDeadlineText(); wl.Owner = context.Users.FirstOrDefault(o => o.UserId == context.OwnedWishlists.FirstOrDefault(ow => ow.WishlistId == id).OwnerId); ws.Add(wl); } return(ws); } } catch (Exception eContext) { Debug.WriteLine("Exception: " + eContext.Message); return(null); } }