public void Delete(QueuedSMS queuedSMS) { const string q = @"UPDATE dbo.QueuedSMS SET Deleted = 1 WHERE Id = @Id"; using (SqlConnection conn = GetConnection()) using (OpenCbsCommand c = new OpenCbsCommand(q, conn)) { c.AddParam("@Id", queuedSMS.Id); c.ExecuteNonQuery(); } }
/// <summary> /// Deletes an SMS account /// </summary> /// <param name="queuedSMS">SMS account</param> public void Delete(QueuedSMS queuedSMS) { if (queuedSMS == null) { throw new ArgumentNullException("queuedSMS"); } if (_manager.SelectAll().Count == 1) { throw new Exception("You cannot delete this SMS account. At least one account is required."); } _manager.Delete(queuedSMS); }
public bool Update(QueuedSMS queuedSMS) { bool updateOk = false; try { const string q = @"UPDATE dbo.QueuedSMS SET [From] = @From, [Recipient] = @Recipient, [RecipientId] = @RecipientId, [ContractId] = @ContractId, [Charged] = @Charged, [Message] = @Message, [CreatedOnUtc] = @CreatedOnUtc, [SentOnUtc] = @SentOnUtc, [SentTries] = @SentTries, [Response] = @Response, [Deleted] = @Deleted WHERE Id = @Id"; using (SqlConnection conn = GetConnection()) using (OpenCbsCommand c = new OpenCbsCommand(q, conn)) { c.AddParam("@Id", queuedSMS.Id); c.AddParam("@From", queuedSMS.From); c.AddParam("@Recipient", queuedSMS.Recipient); c.AddParam("@RecipientId", queuedSMS.RecipientId); c.AddParam("@ContractId", queuedSMS.ContractId); c.AddParam("@Charged", queuedSMS.Charged); c.AddParam("@Message", queuedSMS.Message); c.AddParam("@CreatedOnUtc", queuedSMS.CreatedOnUtc); c.AddParam("@SentOnUtc", queuedSMS.SentOnUtc); c.AddParam("@SentTries", queuedSMS.SentTries); c.AddParam("@Response", queuedSMS.Response); c.AddParam("@Deleted", false); c.ExecuteNonQuery(); updateOk = true; } } catch (System.Exception ex) { throw ex; } return(updateOk); }
public int Add(QueuedSMS queuedSMS) { const string q = @"INSERT INTO dbo.QueuedSMS ([From], [Recipient], [RecipientId], [ContractId], [Charged], [Message], CreatedOnUtc, SentOnUtc, SentTries, Deleted) VALUES (@From, @Recipient, @RecipientId, @ContractId, @Charged, @Message, @CreatedOnUtc, @SentOnUtc, @SentTries, @Deleted) SELECT SCOPE_IDENTITY()"; using (SqlConnection conn = GetConnection()) using (OpenCbsCommand c = new OpenCbsCommand(q, conn)) { c.AddParam("@From", queuedSMS.From); c.AddParam("@Recipient", queuedSMS.Recipient); c.AddParam("@RecipientId", queuedSMS.RecipientId); c.AddParam("@ContractId", queuedSMS.ContractId); c.AddParam("@Charged", queuedSMS.Charged); c.AddParam("@Message", queuedSMS.Message); c.AddParam("@CreatedOnUtc", queuedSMS.CreatedOnUtc); c.AddParam("@SentOnUtc", queuedSMS.SentOnUtc); c.AddParam("@SentTries", queuedSMS.SentTries); c.AddParam("@Deleted", false); return(int.Parse(c.ExecuteScalar().ToString())); } }
public List <QueuedSMS> SelectAll() { List <QueuedSMS> qeuedSMSs = new List <QueuedSMS>(); const string q = @"SELECT * FROM dbo.QueuedSMS where Deleted <> 1"; using (SqlConnection conn = GetConnection()) using (OpenCbsCommand c = new OpenCbsCommand(q, conn)) using (OpenCbsReader r = c.ExecuteReader()) { if (r.Empty) { return(qeuedSMSs); } while (r.Read()) { var queuedSMS = new QueuedSMS { Id = r.GetInt("Id"), From = r.GetString("From"), Recipient = r.GetString("Recipient"), RecipientId = r.GetNullInt("RecipientId"), ContractId = r.GetNullInt("ContractId"), Charged = r.GetNullBool("Charged"), Message = r.GetString("Message"), CreatedOnUtc = r.GetDateTime("CreatedOnUtc"), SentOnUtc = r.GetNullDateTime("SentOnUtc"), SentTries = r.GetInt("SentTries"), Response = r.GetString("Response"), Deleted = r.GetBool("Deleted"), }; qeuedSMSs.Add(queuedSMS); } } return(qeuedSMSs); }
public void Update(QueuedSMS queuedSMS) { _manager.Update(queuedSMS); }
public void Add(QueuedSMS queuedSMS) { _manager.Add(queuedSMS); }
static void Main(string[] args) { QueuedSMSServices _queuedSMSService = ServiceProvider.GetQueuedSMSServices(); UserServices _userService = ServiceProvider.GetUserServices(); ClientServices _clientService = ServiceProvider.GetClientServices(); SavingServices _savingService = ServiceProvider.GetSavingServices(); PaymentMethodServices _paymentMethodService = ServiceProvider.GetPaymentMethodServices(); var generalSettingsService = ServicesProvider.GetInstance().GetApplicationSettingsServices(); generalSettingsService.FillGeneralDatabaseParameter(); Console.WriteLine("Executing sms charges job"); var queuedsms = _queuedSMSService.GetUncharged(); Console.WriteLine(""); Console.WriteLine("-------------------------------------"); Console.WriteLine("Charging SMS"); Console.WriteLine("Uncharged sms count: " + queuedsms.Count); decimal smsCharge = Convert.ToDecimal(ApplicationSettings.GetInstance("").GetSpecificParameter(OGeneralSettings.SMS_CHARGE)); var adminUser = _userService.Find(1); var paymentMethod = _paymentMethodService.GetPaymentMethodByName("Cash"); foreach (QueuedSMS qe in queuedsms) { try { if (qe.ContractId.HasValue && qe.Charged.HasValue && !qe.Charged.Value) { SavingBookContract _saving = _savingService.GetSaving(qe.ContractId.Value); //Get all sms for same saving book contract var smsGroup = _queuedSMSService.FindByContractId(_saving.Id); string description = ""; string formatedAccountNumber = "******" + _saving.Code.Substring(_saving.Code.Length - 4); OCurrency SMSCharges = smsGroup.Count * smsCharge; if (smsGroup.Count > 0) { string desc = "SMS charges of {0:.00} for {1:dd.MM.yyyy} - {2:dd.MM.yyyy} : {3}"; object[] items = new object[] { SMSCharges.GetFormatedValue(true), smsGroup.First().CreatedOnUtc, smsGroup.Last().CreatedOnUtc, formatedAccountNumber }; description = string.Format(desc, items); } if (smsGroup.Count == 0) { string desc = "SMS charges of {0:.00} for {1:dd.MM.yyyy} : {3}"; object[] items = new object[] { SMSCharges.GetFormatedValue(true), smsGroup.First().CreatedOnUtc, formatedAccountNumber }; description = string.Format(desc, items); smsGroup.First().Charged = true; } _savingService.Withdraw(_saving, DateTime.Now, SMSCharges, true, description, "", adminUser, Teller.CurrentTeller, paymentMethod); qe.Charged = true; foreach (var sms in smsGroup) { sms.Charged = true; queuedsms.Where(s => s.Id == sms.Id).First().Charged = true; _queuedSMSService.Update(sms); } //Send sms charge notification Person person = _clientService.FindPersonById(qe.RecipientId.Value); if (person != null) { if (person.SMSDelivery.HasValue && person.SMSDelivery.Value) { string mfbName = Convert.ToString(ServicesProvider.GetInstance().GetGeneralSettings().GetSpecificParameter(OGeneralSettings.MFI_NAME)); //var message = messageTemplate.Body; var messageReplaced = mfbName + " " + description;// Tokenizer.Replace(message, tokens, false); var sms = new QueuedSMS() { From = Convert.ToString(ServicesProvider.GetInstance().GetGeneralSettings().GetSpecificParameter(OGeneralSettings.SMS_FROM_NUMBER)), Recipient = person.PersonalPhone, RecipientId = person.Id, ContractId = _saving != null ? _saving.Id : 0, Charged = true, Message = messageReplaced, SentTries = 0, CreatedOnUtc = DateTime.UtcNow, }; _queuedSMSService.Add(sms); } } } } catch (Exception exc) { Console.WriteLine(string.Format("Error charging sms: {0}", exc.Message), exc); } finally { } } }
protected int SendNotification(MessageTemplate messageTemplate, EmailAccount emailAccount, IEnumerable <Token> tokens, string toEmailAddress, string toName, string replyTo = null, string replyToName = null, ISavingsContract savingsContract = null) { #region Email routine if (person.EmailDelivery.HasValue && person.EmailDelivery.Value && messageTemplate.SendEmail.HasValue && messageTemplate.SendEmail.Value) { var bcc = messageTemplate.BccEmailAddresses; var subject = messageTemplate.Subject; var body = messageTemplate.EmailBody; // Replace subject and body tokens var subjectReplaced = Tokenizer.Replace(subject, tokens, false); var bodyReplaced = Tokenizer.Replace(body, tokens, true); var email = new QueuedEmail() { Priority = 5, From = emailAccount.Email, FromName = emailAccount.DisplayName, To = toEmailAddress, ToName = toName, CC = string.Empty, SentTries = 0, Bcc = bcc, ReplyTo = replyTo, ReplyToName = replyToName, Subject = subjectReplaced, Body = bodyReplaced, CreatedOnUtc = DateTime.UtcNow, EmailAccountId = emailAccount.Id }; _queuedEmailService.Add(email); //return email.Id; } #endregion #region SMS routine if (person.SmsDelivery.HasValue && person.SmsDelivery.Value && messageTemplate.SendSMS.HasValue && messageTemplate.SendSMS.Value) { var message = messageTemplate.Body; var messageReplaced = Tokenizer.Replace(message, tokens, false); var sms = new QueuedSMS() { From = Convert.ToString(ServicesProvider.GetInstance().GetGeneralSettings().GetSpecificParameter(OGeneralSettings.SMS_FROM_NUMBER)), Recipient = person.PersonalPhone, RecipientId = person.Id, ContractId = savingsContract != null ? savingsContract.Id : 0, Charged = false, Message = messageReplaced, SentTries = 0, CreatedOnUtc = DateTime.UtcNow, }; _queuedSMSService.Add(sms); //return sms.Id; } #endregion return(0); }