private void SaveOnDemandData(string numbers, string address)
        {
            //// Should save for ussd and sms both
            if (numbers.ToUpper().Contains(_configurationHelper.SubscriptionKeyword) || numbers.ToUpper().Contains(_configurationHelper.UnSubscriptionKeyword))
                return;
            string msisdnNumber = address.Split(':').LastOrDefault();
            string pbNumbers = numbers.Substring(4).ToUpper().Trim();
            BDAppsRepository bdapps = new BDAppsRepository(Configuration, PBDrawResultRepository, PBOnDemandRepository, _cache);
            SaveAllPBNumbers(numbers, address, msisdnNumber, pbNumbers, bdapps);

        }
        private async Task<string> SendOndemandSMSNotificationByMSISDN(string MSISDN)
        {
            if (_cache.TryGetValue(MSISDN, out string value))
                return null;

            _configurationHelper.AddCache(MSISDN, MSISDN);
           
            await Task.Delay(5*60*1000);
            BDAppsRepository bdapps = new BDAppsRepository(Configuration, PBDrawResultRepository, PBOnDemandRepository, _cache);
            return bdapps.SendIndivualSMSNotificationByMSISDN(MSISDN); 
        }
        public string Post([FromBody]Object id)
        {
            MoUssdReceiver receiver = JsonConvert.DeserializeObject<MoUssdReceiver>(id.ToString());
            string content = receiver.getMessage();
            string address = receiver.getAddress(); // get the sender's address

            BDAppsRepository bdapps = new BDAppsRepository(Configuration, PBDrawResultRepository, PBOnDemandRepository, _cache);
            string json = bdapps.SendMessage(receiver);

            if (content.ToUpper().Contains(_configurationHelper.SmsKeyword))
            {
                SaveOnDemandData(content, address);

                if (!string.IsNullOrEmpty(receiver.SessionId))
                {
                    var result = this.SendOndemandSMSNotificationByMSISDN(address.Split(':').LastOrDefault()).Result;
                }
            }
            return json;
        }
 private string SendSubscriberNotification()
 {
     BDAppsRepository bdapps = new BDAppsRepository(Configuration, PBDrawResultRepository, PBOnDemandRepository, _cache);
     return bdapps.SendSubscriberNotification();
 }
        private void SaveAllPBNumbers(string numbers, string address, string msisdnNumber, string pbNumbers, BDAppsRepository bdapps)
        {
            PBOnDemand pbOnDemandToUpdate = PBOnDemandRepository.GetAll().FirstOrDefault(oItem => oItem.MSISDN == msisdnNumber && oItem.Keyword == _configurationHelper.SmsKeyword);
            if (pbOnDemandToUpdate != null)
            {
                string concatePBNumbers = pbOnDemandToUpdate.PBNo + "," + pbNumbers;
                pbOnDemandToUpdate.PBNo = concatePBNumbers.Split(',').Distinct().Aggregate((a, b) => a.Trim() + "," + b.Trim()).ToString();

                pbOnDemandToUpdate.LastUpdatedDate = DateTime.Now;
                PBOnDemandRepository.Update(pbOnDemandToUpdate);
                PBOnDemandRepository.Save();
            }
            else
            {
                PBOnDemand pbOnDemand = new PBOnDemand();
                pbOnDemand.MSISDN = msisdnNumber;
                pbOnDemand.Keyword = numbers.Substring(0, 3).ToUpper().Trim();
                pbOnDemand.PBNo = pbNumbers;
                pbOnDemand.CreatedBy = pbOnDemand.MSISDN;
                pbOnDemand.LastUpdatedBy = pbOnDemand.MSISDN;
                pbOnDemand.PrizeDate = DateTime.Now;
                pbOnDemand.CreatedDate = DateTime.Now;
                pbOnDemand.LastUpdatedDate = DateTime.Now;
                pbOnDemand.IsActive = true;
                pbOnDemand.IsActiveSubscription = bdapps.IsActiveSubscriber(address);
                PBOnDemandRepository.Add(pbOnDemand);
                PBOnDemandRepository.Save();
            }
        }