本文整理汇总了C#中SIPSorcery.Entities.SIPSorceryEntities.SaveChanges方法的典型用法代码示例。如果您正苦于以下问题:C# SIPSorceryEntities.SaveChanges方法的具体用法?C# SIPSorceryEntities.SaveChanges怎么用?C# SIPSorceryEntities.SaveChanges使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SIPSorcery.Entities.SIPSorceryEntities
的用法示例。
在下文中一共展示了SIPSorceryEntities.SaveChanges方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SIPProviderDeleted
public static void SIPProviderDeleted(SIPProvider sipProvider)
{
try
{
logger.Debug("SIPProviderBindingSynchroniser SIPProviderDeleted for " + sipProvider.Owner + " and " + sipProvider.ProviderName + ".");
using (SIPSorceryEntities sipSorceryEntities = new SIPSorceryEntities())
{
SIPProviderBinding existingBinding = (from binding in sipSorceryEntities.SIPProviderBindings
where binding.ProviderID == sipProvider.ID
select binding).FirstOrDefault();
if (existingBinding != null)
{
if (existingBinding.IsRegistered)
{
// Let the registration agent know the existing binding should be expired.
existingBinding.BindingExpiry = 0;
existingBinding.NextRegistrationTime = DateTime.UtcNow.ToString("o");
sipSorceryEntities.SaveChanges();
}
else
{
sipSorceryEntities.SIPProviderBindings.DeleteObject(existingBinding);
sipSorceryEntities.SaveChanges();
}
}
}
}
catch (Exception excp)
{
logger.Error("Exception SIPProviderBindingSynchroniser SIPProviderDeleted. " + excp.Message);
}
}
示例2: Add
/// <summary>
/// Adds a new customer account.
/// </summary>
/// <param name="customerAccount">The customer account to add.</param>
public void Add(CustomerAccount customerAccount)
{
using (var sipSorceryEntities = new SIPSorceryEntities())
{
customerAccount.AccountCode = Crypto.GetRandomString(ACCOUNT_CODE_RANDOM_STRING_PREFIX_LENGTH) + Crypto.GetRandomInt(ACCOUNT_CODE_RANDOM_NUMBER_SUFFIX_LENGTH).ToString();
CheckUniqueFields(customerAccount);
customerAccount.ID = Guid.NewGuid().ToString();
customerAccount.Inserted = DateTimeOffset.UtcNow.ToString("o");
sipSorceryEntities.CustomerAccounts.AddObject(customerAccount);
sipSorceryEntities.SaveChanges();
}
}
示例3: Add
/// <summary>
/// Adds a new rate.
/// </summary>
/// <param name="rate">The rate record to add.</param>
public void Add(Rate rate)
{
using (var sipSorceryEntities = new SIPSorceryEntities())
{
if ((from rt in sipSorceryEntities.Rates where rt.Prefix == rate.Prefix select rt).Any())
{
throw new ApplicationException("The rate prefix is already in use.");
}
else
{
rate.ID = Guid.NewGuid().ToString();
rate.Inserted = DateTimeOffset.UtcNow.ToString("o");
sipSorceryEntities.Rates.AddObject(rate);
sipSorceryEntities.SaveChanges();
}
}
}
示例4: ReturnUnusedCredit
/// <summary>
/// This method should be called once a billable call has been completed. It will calculate the final cost of the call and return
/// any usused credit back to the customer account.
/// </summary>
/// <param name="cdrID">The ID of the CDR the credit is being returned for.</param>
/// <returns>The total cost of the completed call.</returns>
public decimal ReturnUnusedCredit(string rtccID)
{
logger.Debug("ReturnUnusedCredit for RTCC ID " + rtccID + ".");
decimal actualCallCost = Decimal.Zero;
using (var db = new SIPSorceryEntities())
{
using (var trans = new TransactionScope())
{
var rtcc = (from rtc in db.RTCCs1.Include("cdr") where rtc.ID == rtccID select rtc).First();
if (rtcc.ReconciliationResult != null)
{
logger.Error("This CDR has already been reconciled, no further action will be taken.");
}
else
{
var callCDR = (from cdr in db.CDRs where cdr.ID == rtcc.CDRID select cdr).SingleOrDefault();
string reconciliationError = null;
if (callCDR.Duration == null)
{
reconciliationError = "Error, the call duration was null.";
logger.Warn("The unused credit could not be returned for " + rtcc.ID + " the CDR has not been hungup.");
}
else if (rtcc.Cost == null)
{
reconciliationError = "Error, the call cost was null.";
logger.Warn("The unused credit could not be returned for " + rtcc.ID + " the call cost was empty.");
}
else if (rtcc.AccountCode.IsNullOrBlank())
{
reconciliationError = "Error, the accountcode was null.";
logger.Warn("The unused credit could not be returned for " + rtcc.ID + " due to the CDR having a blank accountcode.");
}
else if (rtcc.Rate <= 0)
{
reconciliationError = "Error, the rate was not set.";
logger.Warn("The unused credit could not be returned for " + rtcc.ID + " due to the CDR having no rate.");
}
if (reconciliationError != null)
{
rtcc.ReconciliationResult = reconciliationError;
db.SaveChanges();
}
else
{
string accountCode = rtcc.AccountCode;
var customerAccount = db.CustomerAccounts.Where(x => x.AccountCode == accountCode).SingleOrDefault();
logger.Debug("The pre-reconciliation balance for account " + accountCode + " was " + customerAccount.Credit + " when processing RTCC ID " + rtcc.ID + ".");
if (customerAccount == null)
{
logger.Debug("The unused credit could not be returned for RTCC ID " + rtcc.ID + " due to the no matching accountcode.");
rtcc.ReconciliationResult = "Error, no matching customer for " + accountCode + ".";
db.SaveChanges();
}
else
{
// Get the owning customer's RTCC billing increment.
//int rtccIncrement = (from cust in db.Customers where cust.Name.ToLower() == callCDR.Owner.ToLower() select cust.RTCCBillingIncrement).Single();
int rtccIncrement = (rtcc.IncrementSeconds <= 0) ? DEFAULT_INCREMENT_SECONDS : rtcc.IncrementSeconds;
int billableDuration = (callCDR.Duration.Value % rtccIncrement == 0) ? callCDR.Duration.Value : (callCDR.Duration.Value / rtccIncrement + 1) * rtccIncrement;
if (billableDuration > 0)
{
actualCallCost = ((Convert.ToDecimal(billableDuration) / SECONDS_FOR_RATE) * rtcc.Rate.Value) + rtcc.SetupCost;
}
logger.Debug("RTCC billable duration " + billableDuration + " (increment " + rtccIncrement + "), actual call cost calculated at " + actualCallCost.ToString("0.#####") + " for call with cost of " + rtcc.Cost + ".");
if (Math.Round(actualCallCost, 5) < Math.Round(rtcc.Cost.Value, 5))
{
decimal returnCredit = Math.Round(rtcc.Cost.Value, 5) - Math.Round(actualCallCost, 5);
if (returnCredit > 0)
{
// There is some credit to return to the customer account.
rtcc.Cost = rtcc.Cost.Value - returnCredit;
rtcc.ReconciliationResult = "ok";
customerAccount.Credit = customerAccount.Credit + returnCredit;
rtcc.PostReconciliationBalance = customerAccount.Credit;
logger.Debug("The billed call cost was " + actualCallCost.ToString("0.#####") + ", return credit amount " + returnCredit.ToString("0.#####") + ", post reconciliation balance " + customerAccount.Credit.ToString("0.#####") + ".");
}
else
{
// An error has occurred and the credit reserved was less than the cost of the call.
rtcc.ReconciliationResult = "Error: Actual call cost calculated as " + actualCallCost.ToString("0.#####");
//.........这里部分代码省略.........
示例5: SetCDRIsHangingUp
public void SetCDRIsHangingUp(string rtccID)
{
using (var db = new SIPSorceryEntities())
{
//var callCDR = (from cdr in db.CDRs where cdr.ID == cdrID select cdr).SingleOrDefault();
var callRTCC = (from rtcc in db.RTCCs1 where rtcc.ID == rtccID select rtcc).SingleOrDefault();
if (callRTCC == null)
{
logger.Debug("RTCC record could not be found for " + rtccID + " when attemping to set the IsHangingUp flag.");
}
else
{
callRTCC.IsHangingUp = true;
db.SaveChanges();
}
}
}
示例6: Update
/// <summary>
/// Updates an existing customer account.
/// </summary>
/// <param name="customerAccount">The customer account to update.</param>
public void Update(CustomerAccount customerAccount)
{
using (var db = new SIPSorceryEntities())
{
var existingAccount = (from ca in db.CustomerAccounts where ca.ID == customerAccount.ID select ca).SingleOrDefault();
if (existingAccount == null)
{
throw new ApplicationException("The customer account to update could not be found");
}
else if (existingAccount.Owner.ToLower() != customerAccount.Owner.ToLower())
{
throw new ApplicationException("You are not authorised to update this customer account.");
}
else
{
CheckUniqueFields(customerAccount);
logger.Debug("Updating customer account " + existingAccount.AccountName + " for " + existingAccount.Owner + ".");
existingAccount.AccountName = customerAccount.AccountName;
existingAccount.AccountNumber = customerAccount.AccountNumber;
existingAccount.Credit = customerAccount.Credit;
existingAccount.PIN = customerAccount.PIN;
db.SaveChanges();
}
}
}
示例7: CustomerResetAPIKey
public void CustomerResetAPIKey(string authUser, string customerUsername)
{
if (authUser.IsNullOrBlank())
{
throw new ArgumentException("An authenticated user is required for CustomerResetAPIKey.");
}
else if (authUser.ToLower() != customerUsername.ToLower())
{
throw new ArgumentException("You are not authorised to reset the API key for " + customerUsername + ".");
}
using (var db = new SIPSorceryEntities())
{
var existingCustomer = (from cust in db.Customers where cust.Name.ToLower() == customerUsername.ToLower() select cust).Single();
if (existingCustomer == null)
{
throw new ApplicationException("The customer record to reset the API key for could not be found.");
}
else
{
existingCustomer.APIKey = Crypto.GetRandomByteString(Customer.API_KEY_LENGTH / 2);
db.SaveChanges();
}
}
}
示例8: ReserveCredit
/// <summary>
/// This method attempts to reserve a chunk of credit for to allow a call to continue.
/// </summary>
/// <param name="seconds">The number of seconds the reservation is being requested for.</param>
/// <param name="cdrID">The CDR that the credit reservation will be applied to.</param>
/// <returns>True if there was enough credit for the reservation otherwise false.</returns>
public bool ReserveCredit(int seconds, string cdrID)
{
if (seconds <= 0 || cdrID.IsNullOrBlank())
{
return false;
}
using (var db = new SIPSorceryEntities())
{
using (var trans = new TransactionScope())
{
var callCDR = (from cdr in db.CDRs where cdr.ID == cdrID select cdr).SingleOrDefault();
if (callCDR == null)
{
logger.Debug("The reservation for " + cdrID + " and " + seconds + "s failed due to the no matching CDR.");
return false;
}
else
{
if (callCDR.HungupTime != null)
{
logger.Debug("The reservation for " + cdrID + " and " + seconds + "s failed due to the CDR already being hungup.");
callCDR.ReservationError = "Error, call already hungup.";
}
else if (callCDR.AccountCode.IsNullOrBlank())
{
logger.Debug("The reservation for " + cdrID + " and " + seconds + "s failed due to the CDR having a blank accountcode.");
callCDR.ReservationError = "Error, empty accountcode.";
}
else if (callCDR.Rate <= 0)
{
logger.Debug("The reservation for " + cdrID + " and " + seconds + "s failed due to the CDR having no rate.");
callCDR.ReservationError = "Error, empty rate.";
}
if (callCDR.ReservationError == null)
{
string accountCode = callCDR.AccountCode;
var customerAccount = db.CustomerAccounts.Where(x => x.AccountCode == accountCode).SingleOrDefault();
if (customerAccount == null)
{
logger.Debug("The reservation for " + accountCode + " and " + seconds + "s failed due to the no matching accountcode.");
callCDR.ReservationError = "Error, no customer for accountcode.";
}
else
{
decimal amount = (Convert.ToDecimal(seconds) / SECONDS_FOR_RATE) * callCDR.Rate.Value;
if (customerAccount.Credit < amount)
{
logger.Debug("The reservation for " + accountCode + " and " + seconds + "s failed due to lack of credit.");
callCDR.ReservationError = "Error, insufficient credit.";
}
else
{
// The credit is available deduct it from the customer account balance and place it on the CDR.
customerAccount.Credit = customerAccount.Credit - amount;
// Set the fields on the CDR.
callCDR.SecondsReserved = callCDR.SecondsReserved + seconds;
callCDR.Cost = callCDR.Cost + amount;
}
}
}
db.SaveChanges();
trans.Complete();
return callCDR.ReservationError == null;
}
}
}
}
示例9: ReturnUnusedCredit
/// <summary>
/// This method should be called once a billable call has been completed. It will calcualte the final cost of the call and return
/// any usused credit back to the customer account.
/// </summary>
/// <param name="cdrID">The ID of the CDR the credit is being returned for.</param>
public void ReturnUnusedCredit(string cdrID)
{
logger.Debug("ReturnUnusedCredit for CDR ID " + cdrID + ".");
if (cdrID.NotNullOrBlank())
{
using (var db = new SIPSorceryEntities())
{
using (var trans = new TransactionScope())
{
var callCDR = (from cdr in db.CDRs where cdr.ID == cdrID select cdr).SingleOrDefault();
if (callCDR == null)
{
logger.Error("The unused credit could not be returned for " + cdrID + " due to the no matching CDR.");
}
else
{
string reconciliationError = null;
if (callCDR.Duration == null)
{
reconciliationError = "Error, the call duration was null.";
logger.Warn("The unused credit could not be returned for " + cdrID + " the CDR has not been hungup.");
}
else if (callCDR.Cost == null)
{
reconciliationError = "Error, the call cost was null.";
logger.Warn("The unused credit could not be returned for " + cdrID + " the call cost was empty.");
}
else if (callCDR.AccountCode.IsNullOrBlank())
{
reconciliationError = "Error, the accountcode was null.";
logger.Warn("The unused credit could not be returned for " + cdrID + " due to the CDR having a blank accountcode.");
}
else if (callCDR.Rate <= 0)
{
reconciliationError = "Error, the rate was not set.";
logger.Warn("The unused credit could not be returned for " + cdrID + " due to the CDR having no rate.");
}
if (reconciliationError != null)
{
callCDR.ReconciliationResult = reconciliationError;
db.SaveChanges();
}
else
{
string accountCode = callCDR.AccountCode;
var customerAccount = db.CustomerAccounts.Where(x => x.AccountCode == accountCode).SingleOrDefault();
if (customerAccount == null)
{
logger.Debug("The unused credit could not be returned for " + cdrID + " due to the no matching accountcode.");
callCDR.ReconciliationResult = "Error, no matching customer for " + accountCode + ".";
db.SaveChanges();
}
else
{
// Get the owning customer's RTCC billing increment.
int rtccIncrement = (from cust in db.Customers where cust.Name.ToLower() == callCDR.Owner.ToLower() select cust.RTCCBillingIncrement).Single();
int billableDuration = (callCDR.Duration.Value % rtccIncrement == 0) ? callCDR.Duration.Value : (callCDR.Duration.Value / rtccIncrement + 1) * rtccIncrement;
decimal actualCallCost = (Convert.ToDecimal(billableDuration) / SECONDS_FOR_RATE) * callCDR.Rate.Value;
logger.Debug("RTCC billable duration " + billableDuration + " (increment " + rtccIncrement + "), actual call cost calculated at " + actualCallCost.ToString("0.#####") + " for call with cost of " + callCDR.Cost + ".");
if (Math.Round(actualCallCost, 5) < Math.Round(callCDR.Cost.Value, 5))
{
decimal returnCredit = Math.Round(callCDR.Cost.Value, 5) - Math.Round(actualCallCost, 5);
if (returnCredit > 0)
{
// There is some credit to return to the customer account.
callCDR.Cost = callCDR.Cost.Value - returnCredit;
callCDR.ReconciliationResult = "ok";
callCDR.PostReconciliationBalance = customerAccount.Credit + returnCredit;
customerAccount.Credit = customerAccount.Credit + returnCredit;
}
else
{
// An error has occurred and the credit reserved was less than the cost of the call.
callCDR.ReconciliationResult = "Error: Actual call cost calculated as " + actualCallCost.ToString("0.#####");
callCDR.PostReconciliationBalance = customerAccount.Credit + returnCredit;
customerAccount.Credit = customerAccount.Credit + returnCredit;
}
db.SaveChanges();
}
else if (Math.Round(actualCallCost, 5) > Math.Round(callCDR.Cost.Value, 5) && Math.Abs(callCDR.Duration.Value - callCDR.SecondsReserved.Value) <= SECONDS_LENIENCY_FOR_RECONCILIATION)
{
logger.Debug("The billed call duration was in +/- " + SECONDS_LENIENCY_FOR_RECONCILIATION + " of actual call duration so a a bille call cost of " + callCDR.Cost.Value.ToString("0.#####") + " was accepted for an actual call cost of " + actualCallCost.ToString("0.#####") + ".");
callCDR.ReconciliationResult = "ok";
callCDR.PostReconciliationBalance = customerAccount.Credit;
//.........这里部分代码省略.........
示例10: DeleteSIPAccount
public void DeleteSIPAccount(string authUser, SIPAccount sipAccount)
{
using (var sipSorceryEntities = new SIPSorceryEntities())
{
SIPAccount existingAccount = (from sa in sipSorceryEntities.SIPAccounts where sa.ID == sipAccount.ID && sa.Owner.ToLower() == authUser.ToLower() select sa).FirstOrDefault();
if (existingAccount == null)
{
throw new ApplicationException("The SIP account to delete could not be found.");
}
else if (existingAccount.Owner.ToLower() != authUser.ToLower())
{
throw new ApplicationException("Not authorised to delete the SIP Account.");
}
sipSorceryEntities.SIPAccounts.DeleteObject(existingAccount);
sipSorceryEntities.SaveChanges();
}
}
示例11: AddNewBindingForProvider
private static void AddNewBindingForProvider(SIPSorceryEntities sipSorceryEntities, SIPProvider sipProvider)
{
try
{
logger.Debug("AddNewBindingForProvider provider ID=" + sipProvider.ID + ".");
SIPProviderBinding newBinding = sipSorceryEntities.SIPProviderBindings.CreateObject();
newBinding.SetProviderFields(sipProvider);
newBinding.ID = Guid.NewGuid().ToString();
newBinding.NextRegistrationTime = DateTimeOffset.UtcNow.ToString("o");
newBinding.ProviderID = sipProvider.ID;
newBinding.Owner = sipProvider.Owner;
sipSorceryEntities.SIPProviderBindings.AddObject(newBinding);
sipSorceryEntities.SaveChanges();
}
catch (Exception excp)
{
logger.Error("Exception AddNewBindingForProvider. " + excp.Message);
logger.Error(excp);
}
}
示例12: DeleteRate
public void DeleteRate(string authUser, string rateID)
{
using (var sipSorceryEntities = new SIPSorceryEntities())
{
var existingRate = (from ra in sipSorceryEntities.Rates where ra.ID == rateID && ra.Owner.ToLower() == authUser.ToLower() select ra).FirstOrDefault();
if (existingRate == null)
{
throw new ApplicationException("The rate to delete could not be found.");
}
else if (existingRate.Owner != authUser.ToLower())
{
throw new ApplicationException("Not authorised to delete the rate.");
}
sipSorceryEntities.Rates.DeleteObject(existingRate);
sipSorceryEntities.SaveChanges();
}
}
示例13: DeleteSimpleWizardRule
public void DeleteSimpleWizardRule(string authUser, SimpleWizardRule rule)
{
using (var sipSorceryEntities = new SIPSorceryEntities())
{
SimpleWizardRule existingRule = (from ru in sipSorceryEntities.SimpleWizardRules where ru.ID == rule.ID && ru.Owner == authUser.ToLower() select ru).FirstOrDefault();
if (existingRule == null)
{
throw new ApplicationException("The Simple Wizard Rule to delete could not be found.");
}
else if (existingRule.Owner != authUser.ToLower())
{
throw new ApplicationException("Not authorised to delete the Simple Wizard Rule.");
}
sipSorceryEntities.SimpleWizardRules.DeleteObject(existingRule);
sipSorceryEntities.SaveChanges();
}
}
示例14: DeleteCustomerAccount
public void DeleteCustomerAccount(string authUser, string customerAccountID)
{
using (var sipSorceryEntities = new SIPSorceryEntities())
{
var existingAccount = (from ca in sipSorceryEntities.CustomerAccounts where ca.ID == customerAccountID && ca.Owner.ToLower() == authUser.ToLower() select ca).FirstOrDefault();
if (existingAccount == null)
{
throw new ApplicationException("The customer account to delete could not be found.");
}
else if (existingAccount.Owner != authUser.ToLower())
{
throw new ApplicationException("Not authorised to delete the customer account.");
}
sipSorceryEntities.CustomerAccounts.DeleteObject(existingAccount);
sipSorceryEntities.SaveChanges();
}
}
示例15: DBWrite
public void DBWrite(string authUsername, string key, string value)
{
using (var entities = new SIPSorceryEntities())
{
var existingEntry = entities.DialPlanData.Where(x => x.DataOwner == authUsername && x.DataKey == key).SingleOrDefault();
if (existingEntry != null)
{
existingEntry.DataValue = value;
}
else
{
var newEntry = new DialPlanDataEntry() { DataOwner = authUsername, DataKey = key, DataValue = value };
entities.AddToDialPlanData(newEntry);
}
entities.SaveChanges();
}
}