public BalanceController(DbContext context, ILogService logService) : base(context, logService) { this.sendMessageRuleService = new SendMessageRuleService(new UnitOfWork(context), logService); }
public SendMessageRuleController(DbContext context, ILogService logService, ISystemParameters systemParameters) : base(context, logService) { this.sendMessageRuleService = new SendMessageRuleService(new UnitOfWork(context), logService); this.systemParameters = systemParameters; }
private void CheckCredit(ApplicationUser user) { DateTime utcNow = DateTime.UtcNow; // 低於下限時自動撥點 LimitAllotPoint(user); // 點數預警設定 var creditWarning = user.CreditWarning; if (creditWarning == null) { return; } if (creditWarning.Enabled == false) { return; } if (creditWarning.LastNotifiedTime.HasValue && creditWarning.NotifiedInterval > (utcNow - creditWarning.LastNotifiedTime.Value).TotalSeconds) { return; } string Email = user.Email; string Mobile = user.PhoneNumber; if (creditWarning.ByEmail) { string subject = "點數預警"; string body = string.Format("目前點數 {0},低於點數預警 {1}", user.SmsBalance, creditWarning.SmsBalance); string[] destinations = { Email }; bool notifyMe = creditWarning.SmsBalance >= (user.SmsBalance); if (notifyMe) { // 在發送通知之前,先更新預警通知時間,可以避免遞迴問題 creditWarning.LastNotifiedTime = utcNow; this.unitOfWork.Repository <CreditWarning>().Update(creditWarning); // 發送通知 BackgroundJob.Enqueue <CommonMailService>(x => x.Send(subject, body, destinations)); } } if (creditWarning.BySmsMessage) { string subject = "點數預警"; string body = string.Format("目前點數 {0},低於點數預警 {1}", user.SmsBalance, creditWarning.SmsBalance); string[] destinations = { Mobile }; var messageCostInfo = new MessageCostInfo(body, Mobile); // 以簡訊提供預警通知,花費點數為使用者自己的點數(messageCostInfo.MessageCost) bool notifyMe = creditWarning.SmsBalance >= (user.SmsBalance + messageCostInfo.MessageCost); if (notifyMe) { // 在發送通知之前,先更新預警通知時間,可以避免遞迴問題 creditWarning.LastNotifiedTime = utcNow; this.unitOfWork.Repository <CreditWarning>().Update(creditWarning); // 發送通知 var sendMessageRuleService = new SendMessageRuleService(this.unitOfWork, this.logService); sendMessageRuleService.CreateCreditWarningSendMessageRule(user, subject, body, destinations); } } }
public SendParamSMSController(DbContext context, ILogService logService) : base(context, logService) { this.sendMessageRuleService = new SendMessageRuleService(new UnitOfWork(context), logService); this.validationService = new ValidationService(new UnitOfWork(context), logService); }