public async Task <IReadOnlyCollection <GiftReceivedFeedViewModel> > GetGiftTransactionsForUserFeedAsync(string userId) { var giftTransactions = from gifts in db.GiftTransactions where (gifts.FromUserId == userId || gifts.ToUserId == userId) where gifts.FromUser.IsActive where gifts.ToUser.IsActive select new GiftReceivedFeedViewModel() { DateSent = gifts.DateTransactionOccurred, ReceiverUserName = gifts.ToUser.UserName, ReceiverProfileImagePath = gifts.ToUser.Profile.UserImage.FileName, ReceiverProfileId = gifts.ToUser.Profile.Id, SenderProfileId = gifts.FromUser.Profile.Id, SenderProfileImagePath = gifts.FromUser.Profile.UserImage.FileName, SenderUserId = gifts.FromUser.Id, SenderUserName = gifts.FromUser.UserName, StoreItemId = gifts.StoreItemId, ItemCount = gifts.ItemCount, StoreItemIconPath = gifts.StoreItem.IconFileName }; var results = await giftTransactions.ToListAsync(); foreach (var result in results) { result.ReceiverProfileImagePath = ProfileExtensions.GetThumbnailImagePath(result.ReceiverProfileImagePath); result.SenderProfileImagePath = ProfileExtensions.GetThumbnailImagePath(result.SenderProfileImagePath); result.StoreItemIconPath = StoreItemExtensions.GetImagePath(result.StoreItemIconPath); result.Gifts = new Dictionary <int, GiftReceivedFeedItemViewModel>(); } return(results.AsReadOnly()); }
/// <summary> /// Returns all store items in descending order by the date at which they were added. /// </summary> /// <returns></returns> public async Task <IReadOnlyList <StoreItemViewModel> > GetNewStoreItemsAsync() { DateTime now = DateTime.Now; var query = from storeItems in db.StoreItems join sales in db.StoreSales on storeItems.Id equals sales.StoreItemId into lj from sales in lj.DefaultIfEmpty() where (now >= sales.DateStart && now <= sales.DateEnd) || sales.Discount == null // sales for today or items without sales orderby storeItems.DateAdded descending select new StoreItemViewModel() { ItemId = storeItems.Id, Discount = sales.Discount, ItemDescription = storeItems.Description, ItemName = storeItems.Name, ItemTypeId = storeItems.ItemTypeId, PointsCost = storeItems.PointPrice, ItemImagePath = storeItems.IconFileName, DateSaleEnds = sales.DateEnd }; var results = await query.ToListAsync(); // we couldn't execute these custom formatting functions in the LINQ query, so we loop and do it here foreach (var item in results) { item.ItemImagePath = StoreItemExtensions.GetImagePath(item.ItemImagePath); } return(results); }
public async Task <IReadOnlyCollection <GiftReceivedFeedViewModel> > GetFollowerGiftTransactionsAsync(string userId, FeedItemQueryType queryType) { List <GiftReceivedFeedViewModel> results = new List <GiftReceivedFeedViewModel>(); if (queryType == FeedItemQueryType.All) { var giftsSent = (from gifts in db.GiftTransactions from favoritedProfiles in db.FavoriteProfiles where gifts.FromUser.Profile.Id == favoritedProfiles.ProfileId || gifts.ToUser.Profile.Id == favoritedProfiles.ProfileId where favoritedProfiles.UserId == userId where gifts.FromUser.IsActive where gifts.ToUser.IsActive select new GiftReceivedFeedViewModel() { DateSent = gifts.DateTransactionOccurred, ReceiverUserName = gifts.ToUser.UserName, ReceiverProfileImagePath = gifts.ToUser.Profile.UserImage.FileName, ReceiverProfileId = gifts.ToUser.Profile.Id, SenderProfileId = gifts.FromUser.Profile.Id, SenderProfileImagePath = gifts.FromUser.Profile.UserImage.FileName, SenderUserId = gifts.FromUser.Id, SenderUserName = gifts.FromUser.UserName, StoreItemId = gifts.StoreItemId, ItemCount = gifts.ItemCount, StoreItemIconPath = gifts.StoreItem.IconFileName }) .Distinct(); results = await giftsSent.ToListAsync(); } else { var giftsToSelf = from gifts in db.GiftTransactions .Include(g => g.StoreItem) .Include(g => g.FromUser) where gifts.ToUserId == userId where gifts.FromUser.IsActive where gifts.ToUser.IsActive select new GiftReceivedFeedViewModel() { DateSent = gifts.DateTransactionOccurred, ReceiverUserName = gifts.ToUser.UserName, ReceiverProfileImagePath = gifts.ToUser.Profile.UserImage.FileName, ReceiverProfileId = gifts.ToUser.Profile.Id, SenderProfileId = gifts.FromUser.Profile.Id, SenderProfileImagePath = gifts.FromUser.Profile.UserImage.FileName, SenderUserId = gifts.FromUser.Id, SenderUserName = gifts.FromUser.UserName, StoreItemId = gifts.StoreItemId, ItemCount = gifts.ItemCount, StoreItemIconPath = gifts.StoreItem.IconFileName }; results = await giftsToSelf.ToListAsync(); } foreach (var result in results) { result.ReceiverProfileImagePath = ProfileExtensions.GetThumbnailImagePath(result.ReceiverProfileImagePath); result.SenderProfileImagePath = ProfileExtensions.GetThumbnailImagePath(result.SenderProfileImagePath); result.StoreItemIconPath = StoreItemExtensions.GetImagePath(result.StoreItemIconPath); result.Gifts = new Dictionary <int, GiftReceivedFeedItemViewModel>(); } return(results.AsReadOnly()); }