Пример #1
0
        private void SaveMessage(InboundMessage m)
        {
            string pesan     = string.Empty;
            bool?  isSuccess = null;

            try
            {
                _tMsgRepository.DbContext.BeginTransaction();

                //check sms for mencegah double data
                if (_tMsgRepository.GetMsgLikes(DateTime.Today, m.getText()))
                {
                    throw new Exception("SMS ini sudah pernah diinput.");
                }

                // Received message
                TMsg msg = new TMsg();
                msg.SetAssignedIdTo(Guid.NewGuid().ToString());
                msg.MsgDate     = DateTime.Now;// Convert.ToDateTime(m.getDate().toGMTString());
                msg.MsgFrom     = m.getOriginator();
                msg.MsgText     = m.getText();
                msg.DataStatus  = EnumDataStatus.New.ToString();
                msg.CreatedBy   = Environment.UserName;
                msg.CreatedDate = DateTime.Now;
                // save both stores, this saves everything else via cascading
                _tMsgRepository.Save(msg);
                isSuccess = true;
                pesan     = "\nBerhasil.";
            }
            catch (Exception ex)
            {
                _tMsgRepository.DbContext.RollbackTransaction();
                //throw ex;
                isSuccess = false;
                pesan     = "\nGagal.\n" + ex.GetBaseException().Message;
            }
            finally
            {
                if (isSuccess.HasValue)
                {
                    //delete sms
                    bool deleteSuccess = gateway.deleteMessage(m);
                }
            }
        }
Пример #2
0
        private void SaveMessage(SmsPdu smsPdu)
        {
            string        pesan = string.Empty;
            SmsDeliverPdu data  = (SmsDeliverPdu)smsPdu;

            try
            {
                _tMsgRepository.DbContext.BeginTransaction();

                // Received message
                TMsg msg = new TMsg();
                msg.SetAssignedIdTo(Guid.NewGuid().ToString());
                msg.MsgDate = data.SCTimestamp.ToDateTime();
                msg.MsgFrom = data.OriginatingAddress;
                msg.MsgTo   = "";
                msg.MsgText = data.UserDataText;

                // save both stores, this saves everything else via cascading
                _tMsgRepository.Save(msg);

                //split string
                SaveTransHelper hlp = new SaveTransHelper(_tSalesRepository, _tSalesDetRepository, _mGameRepository, _mAgentRepository, _tMsgRepository);
                hlp.SaveToTrans(data.UserDataText);
                _tMsgRepository.DbContext.CommitTransaction();
                pesan = "\nBerhasil.";
            }
            catch (Exception ex)
            {
                _tMsgRepository.DbContext.RollbackTransaction();
                pesan = "\nGagal.\n" + ex.GetBaseException().Message;
                //throw ex;
            }
            if (data.UserDataText.Length >= 150)
            {
                SendMessage(data.OriginatingAddress, data.UserDataText.Substring(0, 150) + pesan);
            }
            else
            {
                SendMessage(data.OriginatingAddress, data.UserDataText + pesan);
            }

            //make delay to send sms
        }