public static void addMerchantKey(MerchantDTO merchant)
 {
     if(checkKey(merchant.MerhchantId))
     {
         MerchantIdCounts.Add(merchant);
     }
 }
        private IList<MessageDTO> checkMoreMerchantId(IList<MessageDTO> messages)
        {
            IList<MessageDTO> finalMessages = new List<MessageDTO>();
               int maxMerchant = tc.getMaxMerchantId();
               int time = tc.getTime();
            var groupedMessages = messages.OrderBy(m => m.requestTime).GroupBy(m => m.MerchantId).Select(m => m).ToList();
            IList<int> uniqueMerchantIds = messages.Select(m => m.MerchantId).Distinct().ToList();
               if(uniqueMerchantIds.Count < messages.Count)
               {
               foreach (int merhcantId in uniqueMerchantIds)
               {
                   int Count = groupedMessages.Where(mg => mg.Key == merhcantId).Count();
                   if (MaintainMerchants.checkKey(merhcantId))
                   {
                       MerchantDTO merchant = new MerchantDTO();
                       merchant.MerhchantId = merhcantId;
                       merchant.date = DateTime.Now;

                       if (Count <= maxMerchant)
                       {
                           merchant.count = Count;
                           MaintainMerchants.MerchantIdCounts.Add(merchant);
                       }
                       else
                       {
                           merchant.count = maxMerchant;
                           foreach (MessageDTO mess in groupedMessages.Where(mg => mg.Key == merhcantId).Take(Count))
                           {
                               finalMessages.Add(mess);
                           }
                           //save remaining messages
                       }
                   }
                   else
                   {
                       MerchantDTO mm = MaintainMerchants.MerchantIdCounts.Where(m => m.MerhchantId == merhcantId).Select(m => m).FirstOrDefault();
                       IList<MessageDTO> sameMerchantMessags = new List<MessageDTO>();
                       foreach (MessageDTO mess in groupedMessages.Where(mg => mg.Key == merhcantId && mg.Where(m => m.requestTime >= mm.date && m.requestTime <= mm.date.AddHours(time)).Any()))
                       {
                           sameMerchantMessags.Add(mess);
                       }
                       if (mm.count + sameMerchantMessags.Count <= maxMerchant)
                       {
                           foreach (MessageDTO mess in sameMerchantMessags)
                           {
                               finalMessages.Add(mess);
                           }
                       }
                       else
                       {
                           // save remai
                       }

                   }
               }
               }
               else
               {
               finalMessages = messages;
               }

               return finalMessages;
        }