/// <summary>
        /// On the user's feed, we want to consolidate multiple "Sent gift" notices into a single line item. For example, the following transactions should be consolidated:
        /// "jskiles sent a 'Red Rose' gift to justin on Aug 10"
        /// "jskiles sent a 'Red Rose' gift to justin on Aug 10"
        /// "jskiles sent a 'Red Rose' gift to justin on Aug 10"
        /// "jskiles sent a 'White Rose' gift to justin on Aug 10"
        ///
        /// Further, all gifts of the same ID should be summed into a single count. The above would condense to a single line of:
        /// "jskiles sent 3x 'Red Rose' gifts and 1x 'White Rose' gift to justin on Aug 10"
        /// </summary>
        /// <param name="giftTransactions"></param>
        /// <returns></returns>
        public static IReadOnlyCollection <GiftReceivedFeedViewModel> GetConsolidatedGiftTransactions(this IReadOnlyCollection <GiftReceivedFeedViewModel> giftTransactions)
        {
            Dictionary <FeedItemKey, GiftReceivedFeedViewModel> consolidatedGiftTransactionViewModels = new Dictionary <FeedItemKey, GiftReceivedFeedViewModel>();

            foreach (var giftTransaction in giftTransactions)
            {
                // the key to identify if a transaction is unique or not depends on the user id and the time since the transaction occurred
                FeedItemKey key = GetFeedItemKey(giftTransaction);

                GiftReceivedFeedViewModel existingGiftReceivedFeedViewModel = new GiftReceivedFeedViewModel();
                bool alreadyExists = consolidatedGiftTransactionViewModels.TryGetValue(key, out existingGiftReceivedFeedViewModel);
                if (!alreadyExists)
                {
                    //var newGiftReceivedFeedViewModel = Mapper.Map<GiftTransactionLog, GiftReceivedFeedViewModel>(giftTransaction);
                    AddGiftReceivedFeedItem(giftTransaction);
                    consolidatedGiftTransactionViewModels.Add(key, giftTransaction);
                }
                else
                {
                    GiftReceivedFeedItemViewModel existingGiftReceivedFeedItemViewModel = new GiftReceivedFeedItemViewModel();
                    alreadyExists = existingGiftReceivedFeedViewModel.Gifts.TryGetValue(giftTransaction.StoreItemId, out existingGiftReceivedFeedItemViewModel);
                    if (!alreadyExists)
                    {
                        AddGiftReceivedFeedItem(giftTransaction);
                    }
                    else
                    {
                        existingGiftReceivedFeedItemViewModel.GiftSentCount++;
                    }
                }
            }

            return(consolidatedGiftTransactionViewModels.Values.ToList().AsReadOnly());
        }
 private static void AddGiftReceivedFeedItem(GiftReceivedFeedViewModel giftReceivedFeedViewModel)
 {
     giftReceivedFeedViewModel.Gifts.Add(giftReceivedFeedViewModel.StoreItemId, new GiftReceivedFeedItemViewModel()
     {
         GiftImagePath = giftReceivedFeedViewModel.StoreItemIconPath,
         GiftSentCount = giftReceivedFeedViewModel.ItemCount
     });
 }
        private static FeedItemKey GetFeedItemKey(GiftReceivedFeedViewModel giftTransaction)
        {
            FeedItemKey key = new FeedItemKey()
            {
                UserId  = giftTransaction.SenderUserId,
                TimeAgo = giftTransaction.TimeAgo
            };

            return(key);
        }