public IEnumerable <CollectionDetails> GetCollectionByCardId(string cardId) { using (var ctx = new ApplicationDbContext()) { var cardService = new CardService(); var collectedCards = ctx.Cards.Single(c => c.CardId == cardId) .Collections .Select(c => new CollectionDetails { CollectionId = c.CollectionId, Name = c.Name, Cards = (ICollection <CardDetails>)cardService.GetCardById(cardId), CardsUntilComplete = c.CardsUntilComplete, Public = c.Public }); return(collectedCards.ToArray()); } }
public CollectionDetails GetCollectionById(int id) { using (var ctx = new ApplicationDbContext()) { var foundCollection = ctx.Collections.Where(c => c.CollectionId == id) .FirstOrDefault(); var cardService = new CardService(); return((foundCollection != null) ? new CollectionDetails() { CollectionId = foundCollection.CollectionId, Name = foundCollection.Name, Public = foundCollection.Public, //CardsInCollection = (int)foundCollection.CardsInCollection, CardsUntilComplete = foundCollection.CardsUntilComplete, Cards = (ICollection <CardDetails>)cardService.GetCardsByCollectionId(id) //ModifiedAt = foundCollection.ModifiedAt } : null); } }