async public void GetVisibleGifts_Returns_Owned_Gifts() { using (var context = GetContext("test2")) { context.Gifts.Add(new Gift { Id = 1, OwnerId = 1 }); context.Gifts.Add(new Gift { Id = 3, OwnerId = 1 }); context.Gifts.Add(new Gift { Id = 2, OwnerId = 2 }); context.SaveChanges(); var gifts = await _service.GetVisibleGifts(1).ToListAsync(); Assert.Equal(2, gifts.Count); Assert.Equal(1, gifts.First().Id); } }
async public Task <DataContext> Index() { var userId = await UserAccessor.GetCurrentIndividualId(); var individuals = AccessControlService.GetVisibleIndividuals(userId).Select(i => i.ToWeb()); var gifts = AccessControlService.GetVisibleGifts(userId).Select(g => g.ToWeb()); var giftsWithReceivers = AccessControlService.GetVisibleGiftReceiverPairs(userId); return(new DataContext { IndividualMap = await individuals.ToDictionaryAsync(i => i.Id), EventMap = await DbContext.Events.Select(e => e.ToWeb()).ToDictionaryAsync(e => e.Id), GiftMap = await gifts.ToDictionaryAsync(g => g.Id), GiftReceiverPairs = await giftsWithReceivers.ToListAsync(), CurrentUserId = userId }); }
async public Task <List <WebApi.Gift> > Index() { var userId = await UserAccessor.GetCurrentIndividualId(); return(await AccessControlService.GetVisibleGifts(userId).Select(g => g.ToWeb()).ToListAsync()); }
async private Task <Database.Gift> FetchGift(int id) { var userId = await UserAccessor.GetCurrentIndividualId(); return(AccessControlService.GetVisibleGifts(userId).FirstOrDefault(g => g.Id == id)); }