public override void CommitOrThrow_Send(MobileNoHandler storedNumbers, string[] telList, bool isWelcomeMessage, int MessageLength, ref Data_AppUserFile.eUserStatus accountStatus, out bool sendFooter) { sendFooter = false; //1) Data_AppUserFile_Checker_Free.VerifyAllMobileNumbers(storedNumbers, telList); if (isWelcomeMessage) { throw new ArgumentException("Wrong account"); } else { //2) checkTimeDelay() DateTime NotBefore = new DateTime(payAsSent.payAsSent_LastMsgQueued, DateTimeKind.Utc).AddSeconds(payAsSent.payAsSent_MinDelayInSeconds); if (DateTime.UtcNow < NotBefore) { throw new ArgumentException("wait"); } //3) check fonds Data_AppUserFile.niceMoney totalCost = payAsSent.payAsSent_CostPerMessage.MultiplyBy(telList.Length); if (payAsSent.payAsSent_CurrentCredit.ValueInUsCent < totalCost.ValueInUsCent) { throw new ArgumentException("Not enouth fonds on account"); } payAsSent.payAsSent_CurrentCredit.ValueInUsCent -= totalCost.ValueInUsCent; //4) update counters payAsSent.payAsSent_MsgSent += telList.Length; payAsSent.payAsSent_LastMsgQueued = DateTime.UtcNow.Ticks; } }
private void UpdateIfChanged_mon(CheckBox cbChanged, TextBox val, ref Data_AppUserFile.niceMoney res) { if (cbChanged.Checked) { res = Data_AppUserFile.niceMoney.Parse(val.Text); } }
public override void CommitOrThrow_TelNumberAdd(MobileHandleConfUnconfList existing, MobileNoHandler noToAdd) { Data_AppUserFile.niceMoney totalCost = monthlyDifPrice.monthlyDifPrice_CostPerNumber.MultiplyBy(noToAdd.MobileNumbersCount); if (!monthlyDifPrice.monthlyDifPrice_CurrentCredit.DeductIfEnoughFund(totalCost)) { throw new ArgumentException("Not enouth fonds on account"); } }
public static bool DeductIfEnoughFund(this Data_AppUserFile.niceMoney wallet, Data_AppUserFile.niceMoney deduct) { if (wallet.ValueInUsCent >= deduct.ValueInUsCent) { wallet.ValueInUsCent -= deduct.ValueInUsCent; return(true); } return(false); }
public override void CommitOrThrow_TelNumberAdd(MobileHandleConfUnconfList existing, MobileNoHandler noToAdd) { Data_AppUserFile.niceMoney totalCost = monthly.monthly_CostPerNumber.MultiplyBy(noToAdd.MobileNumbersCount); if (monthly.monthly_CurrentCredit.ValueInUsCent < totalCost.ValueInUsCent) { throw new ArgumentException("Not enouth fonds on account"); } monthly.monthly_CurrentCredit.ValueInUsCent -= totalCost.ValueInUsCent; }
public override bool FundManagement_CommitAddOneNumber(string telNumber) { Data_AppUserFile.niceMoney totalCost = payAsSent.payAsSent_CostPerNumber.MultiplyBy(1); if (payAsSent.payAsSent_CurrentCredit.ValueInUsCent < totalCost.ValueInUsCent) { // "Not enouth fonds on account" return(false); } payAsSent.payAsSent_CurrentCredit.ValueInUsCent -= totalCost.ValueInUsCent; return(true); }
public override bool FundManagement_CommitAddOneNumber(string telNumber) { Data_AppUserFile.niceMoney totalCost = monthly.monthly_CostPerNumber.MultiplyBy(1); if (monthly.monthly_CurrentCredit.ValueInUsCent < totalCost.ValueInUsCent) { // "Not enouth fonds on account" return(false); } monthly.monthly_CurrentCredit.ValueInUsCent -= totalCost.ValueInUsCent; this.commentLog("Adding " + telNumber, true); return(true); }
public override void CommitOrThrow_Send(MobileNoHandler storedNumbers, string[] telList, bool isWelcomeMessage, int MessageLength, ref Data_AppUserFile.eUserStatus accountStatus, out bool sendFooter) { sendFooter = false; //1) Data_AppUserFile_Checker_Free.VerifyAllMobileNumbers(storedNumbers, telList); if (isWelcomeMessage) { throw new ArgumentException("Wrong account"); } else { // 0) checkTimeDelay() DateTime NotBefore = new DateTime(monthlyDifPrice.monthlyDifPrice_LastMsgQueued, DateTimeKind.Utc) .AddSeconds(monthlyDifPrice.monthlyDifPrice_MinDelayInSeconds); if (DateTime.UtcNow < NotBefore) { throw new ArgumentException("wait"); } PriceLevelHandler levelHandler = new PriceLevelHandler(monthlyDifPrice.monthlyDifPrice_LevelDefinitions); if (!levelHandler.Ok) { throw new ArgumentException("Please check configuration. (NO)"); } // 0) first initialisation if (monthlyDifPrice.monthlyDifPrice_Level == 0) { Data_AppUserFile.niceMoney cost1 = levelHandler.Config.FirstOrDefault(_ => _.Level == 1).Cost; if (!monthlyDifPrice.monthlyDifPrice_CurrentCredit.DeductIfEnoughFund(cost1)) { throw new ArgumentException("Please arrange a top up. (L0)"); } else { monthlyDifPrice.monthlDifPricey_PeriodeStart = DateTime.UtcNow.Ticks; monthlyDifPrice.monthlyDifPrice_ThisMonthMsgSent = 0; monthlyDifPrice.monthlyDifPrice_TotalMsgSent++; monthlyDifPrice.monthlyDifPrice_Level = 1; monthlyDifPrice.monthlyDifPrice_LastMsgQueued = DateTime.UtcNow.Ticks; commentLog($"Deducted {cost1} for initialisation", true); } } // 1) Check aktive, sonst eine Periode mehr und auf Level 1 if (monthlyDifPrice.HasExpired()) { if (!monthlyDifPrice.monthlyDifPrice_AutoRenewMonthPayment) { throw new ArgumentException("Please arrange a top up. (AR)"); } Data_AppUserFile.niceMoney cost1 = levelHandler.Config.FirstOrDefault(_ => _.Level == 1).Cost; if (!monthlyDifPrice.monthlyDifPrice_CurrentCredit.DeductIfEnoughFund(cost1)) { throw new ArgumentException("Please arrange a top up. (L1)"); } else { monthlyDifPrice.monthlDifPricey_PeriodeStart = DateTime.UtcNow.Ticks; monthlyDifPrice.monthlyDifPrice_ThisMonthMsgSent = 0; monthlyDifPrice.monthlyDifPrice_TotalMsgSent++; monthlyDifPrice.monthlyDifPrice_Level = 1; monthlyDifPrice.monthlyDifPrice_LastMsgQueued = DateTime.UtcNow.Ticks; commentLog($"Deducted {cost1} to renew Month", true); } } // 2) Check messageCount and go a level up if needed var curLev = levelHandler.Config.FirstOrDefault(_ => _.Level == monthlyDifPrice.monthlyDifPrice_Level); if (curLev == null) { // bad config throw new ArgumentException($"Please check configuration. (BL) - {levelHandler}"); } if (curLev.MaxMessages == monthlyDifPrice.monthlyDifPrice_ThisMonthMsgSent) { // no more messages left if (!monthlyDifPrice.monthlyDifPrice_AutoInceremntLevel) { throw new ArgumentException("Please arrange a top up. (AI)"); } var nextLev = levelHandler.Config.FirstOrDefault(_ => _.Level == (monthlyDifPrice.monthlyDifPrice_Level + 1)); if (nextLev == null) { // no more levels throw new ArgumentException("Please arrange a top up. (NL)"); } Data_AppUserFile.niceMoney costDif = new Data_AppUserFile.niceMoney(nextLev.Cost.ValueInUsCent - curLev.Cost.ValueInUsCent); if (!monthlyDifPrice.monthlyDifPrice_CurrentCredit.DeductIfEnoughFund(costDif)) { throw new ArgumentException("Please arrange a top up. (LN)"); } else { monthlyDifPrice.monthlyDifPrice_Level = nextLev.Level; monthlyDifPrice.monthlyDifPrice_ThisMonthMsgSent++; monthlyDifPrice.monthlyDifPrice_TotalMsgSent++; monthlyDifPrice.monthlyDifPrice_LastMsgQueued = DateTime.UtcNow.Ticks; commentLog($"Deducted {costDif} to enter level {nextLev.Level}", true); } } else { //ok to send one more message monthlyDifPrice.monthlyDifPrice_LastMsgQueued = DateTime.UtcNow.Ticks; monthlyDifPrice.monthlyDifPrice_ThisMonthMsgSent++; monthlyDifPrice.monthlyDifPrice_TotalMsgSent++; } } }