コード例 #1
0
        private static void UpdateUserImageCollection(Dictionary <FeedItemKey, UploadedImageFeedViewModel> userImagesViewModelConsolidated, UploadedImageFeedViewModel uploadedImageFeed)
        {
            // the key to identify if a transaction is unique or not depends on the user id and the time since the transaction occurred
            FeedItemKey feedKey = new FeedItemKey()
            {
                UserId  = uploadedImageFeed.UploaderUserId,
                TimeAgo = uploadedImageFeed.TimeAgo
            };

            UploadedImageFeedViewModel existingUploadedImageFeed = new UploadedImageFeedViewModel();

            // check if the transaction for this user and time is already accounted for
            bool uploadedImageAlreadyInCollection = userImagesViewModelConsolidated.TryGetValue(feedKey, out existingUploadedImageFeed);

            // if it isn't, then add it to our consolidated collection to begin consolidating
            if (!uploadedImageAlreadyInCollection)
            {
                userImagesViewModelConsolidated.Add(feedKey, uploadedImageFeed);
            }
            // if it is, then add the image path to the consolidated collection
            else
            {
                if (uploadedImageFeed.UploadedImagesPaths.Count > 0)
                {
                    existingUploadedImageFeed.UploadedImagesPaths.Add(uploadedImageFeed.UploadedImagesPaths[0]);
                }
            }
        }
コード例 #2
0
        /// <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());
        }
コード例 #3
0
        private static FeedItemKey GetFeedItemKey(GiftReceivedFeedViewModel giftTransaction)
        {
            FeedItemKey key = new FeedItemKey()
            {
                UserId  = giftTransaction.SenderUserId,
                TimeAgo = giftTransaction.TimeAgo
            };

            return(key);
        }