public static ValidationResult IsValid(Customer customer, ValidationContext context) { if (customer.ID == Guid.Empty.ToString() && customer.CustomerPassword != customer.RetypedPassword) { return new ValidationResult("The password and retyped password were not the same.", new String[] { "CustomerPassword", "RetypedPassword" }); } return ValidationResult.Success; }
public CustomerJSON(Customer customer) { City = customer.City; Country = customer.Country; //CustomerPassword = customer.CustomerPassword; EmailAddress = customer.EmailAddress; EmailAddressConfirmed = customer.EmailAddressConfirmed; Firstname = customer.Firstname; ID = customer.ID; Lastname = customer.Lastname; Username = customer.Name; SecurityAnswer = customer.SecurityAnswer; SecurityQuestion = customer.SecurityQuestion; ServiceLevel = customer.ServiceLevel; ServiceRenewalDate = customer.ServiceRenewalDate; WebSite = customer.WebSite; }
/// <summary> /// Deprecated Method for adding a new object to the Customers EntitySet. Consider using the .Add method of the associated ObjectSet<T> property instead. /// </summary> public void AddToCustomers(Customer customer) { base.AddObject("Customers", customer); }
/// <summary> /// Create a new Customer object. /// </summary> /// <param name="active">Initial value of the Active property.</param> /// <param name="customerPassword">Initial value of the CustomerPassword property.</param> /// <param name="name">Initial value of the Name property.</param> /// <param name="emailAddress">Initial value of the EmailAddress property.</param> /// <param name="emailAddressConfirmed">Initial value of the EmailAddressConfirmed property.</param> /// <param name="executionCount">Initial value of the ExecutionCount property.</param> /// <param name="id">Initial value of the ID property.</param> /// <param name="inserted">Initial value of the Inserted property.</param> /// <param name="maxExecutionCount">Initial value of the MaxExecutionCount property.</param> /// <param name="suspended">Initial value of the Suspended property.</param> /// <param name="serviceLevel">Initial value of the ServiceLevel property.</param> /// <param name="salt">Initial value of the Salt property.</param> public static Customer CreateCustomer(global::System.Boolean active, global::System.String customerPassword, global::System.String name, global::System.String emailAddress, global::System.Boolean emailAddressConfirmed, global::System.Int32 executionCount, global::System.String id, global::System.String inserted, global::System.Int32 maxExecutionCount, global::System.Boolean suspended, global::System.String serviceLevel, global::System.String salt) { Customer customer = new Customer(); customer.Active = active; customer.CustomerPassword = customerPassword; customer.Name = name; customer.EmailAddress = emailAddress; customer.EmailAddressConfirmed = emailAddressConfirmed; customer.ExecutionCount = executionCount; customer.ID = id; customer.Inserted = inserted; customer.MaxExecutionCount = maxExecutionCount; customer.Suspended = suspended; customer.ServiceLevel = serviceLevel; customer.Salt = salt; return customer; }
public Customer ToCustomer() { var entityCustomer = new Customer() { City = this.City, Country = this.Country, CustomerPassword = this.CustomerPassword, EmailAddress = this.EmailAddress, EmailAddressConfirmed = this.EmailAddressConfirmed, Firstname = this.Firstname, ID = ID, Lastname = this.Lastname, Name = this.Username, SecurityAnswer = this.SecurityAnswer, SecurityQuestion = this.SecurityQuestion, ServiceLevel = this.ServiceLevel, ServiceRenewalDate = this.ServiceRenewalDate, WebSite = this.WebSite }; return entityCustomer; }
public void UpdateCustomer(string authUser, Customer customer) { if (authUser.IsNullOrBlank()) { throw new ArgumentException("An authenticated user is required for UpdateCustomer."); } using (var db = new SIPSorceryEntities()) { var existingCustomer = (from cust in db.Customers where cust.Name.ToLower() == authUser.ToLower() select cust).Single(); if (existingCustomer == null) { throw new ApplicationException("The customer record to update could not be found."); } else { existingCustomer.Firstname = customer.Firstname; existingCustomer.Lastname = customer.Lastname; existingCustomer.EmailAddress = customer.EmailAddress; existingCustomer.SecurityQuestion = customer.SecurityQuestion; existingCustomer.SecurityAnswer = customer.SecurityAnswer; existingCustomer.City = customer.City; existingCustomer.Country = customer.Country; existingCustomer.WebSite = customer.WebSite; existingCustomer.Timezone = customer.Timezone; db.SaveChanges(); } } }
public void InsertCustomer(Customer customer) { using (var sipSorceryEntities = new SIPSorceryEntities()) { if (sipSorceryEntities.Customers.Any(x => x.Name == customer.Name.ToLower())) { throw new ApplicationException("The username is already taken. Please choose a different one."); } else if (sipSorceryEntities.Customers.Any(x => x.EmailAddress.ToLower() == customer.EmailAddress.ToLower())) { throw new ApplicationException("The email address is already associated with an account."); } else { customer.ID = Guid.NewGuid().ToString(); customer.Inserted = DateTime.UtcNow.ToString("o"); customer.Name = customer.Name.Trim().ToLower(); customer.MaxExecutionCount = Customer.FREE_MAXIMUM_EXECUTION_COUNT; customer.APIKey = Crypto.GetRandomByteString(Customer.API_KEY_LENGTH / 2); customer.ServiceLevel = (customer.ServiceLevel == null) ? CustomerServiceLevels.Free.ToString() : customer.ServiceLevel; customer.EmailAddressConfirmed = true; customer.CreatedFromIPAddress = System.Web.HttpContext.Current.Request.UserHostAddress; string plainTextassword = customer.CustomerPassword; // Hash the password. string salt = PasswordHash.GenerateSalt(); customer.CustomerPassword = PasswordHash.Hash(customer.CustomerPassword, salt); customer.Salt = salt; if (customer.ServiceRenewalDate != null) { DateTime renewalDate = DateTime.MinValue; if (DateTime.TryParse(customer.ServiceRenewalDate, out renewalDate)) { customer.ServiceRenewalDate = DateTime.SpecifyKind(renewalDate, DateTimeKind.Utc).ToUniversalTime().ToString("o"); } else { throw new ApplicationException("The service renewal date could not be parsed as a valid date."); } } if ((customer.EntityState != EntityState.Detached)) { sipSorceryEntities.ObjectStateManager.ChangeObjectState(customer, EntityState.Added); } else { sipSorceryEntities.Customers.AddObject(customer); } sipSorceryEntities.SaveChanges(); logger.Debug("New customer record added for " + customer.Name + "."); // Create a default dialplan. SIPDialPlan defaultDialPlan = new SIPDialPlan() { ID = Guid.NewGuid().ToString(), Owner = customer.Name, DialPlanName = "default", DialPlanScript = "sys.Log(\"Log message from default dialplan.\")\nsys.Dial(\"[email protected]\")\n", ScriptTypeDescription = SIPDialPlanScriptTypesEnum.Ruby.ToString(), Inserted = DateTimeOffset.UtcNow.ToString("o"), LastUpdate = DateTimeOffset.UtcNow.ToString("o"), MaxExecutionCount = SIPDialPlan.DEFAULT_MAXIMUM_EXECUTION_COUNT }; sipSorceryEntities.SIPDialPlans.AddObject(defaultDialPlan); sipSorceryEntities.SaveChanges(); logger.Debug("Default dialplan added for " + customer.Name + "."); // Get default domain name. string defaultDomain = sipSorceryEntities.SIPDomains.Where(x => x.AliasList.Contains("local")).Select(y => y.Domain).First(); // Create SIP account. if (!sipSorceryEntities.SIPAccounts.Any(s => s.SIPUsername == customer.Name && s.SIPDomain == defaultDomain)) { SIPAccount sipAccount = SIPAccount.Create(customer.Name, defaultDomain, customer.Name, plainTextassword, "default"); sipSorceryEntities.SIPAccounts.AddObject(sipAccount); sipSorceryEntities.SaveChanges(); logger.Debug("SIP account " + sipAccount.SIPUsername + "@" + sipAccount.SIPDomain + " added for " + sipAccount.Owner + "."); } else { int attempts = 0; while (attempts < 10) { string testUsername = customer.Name + Crypto.GetRandomString(4); if (!sipSorceryEntities.SIPAccounts.Any(s => s.SIPUsername == testUsername && s.SIPDomain == defaultDomain)) { SIPAccount sipAccount = SIPAccount.Create(customer.Name, defaultDomain, testUsername, plainTextassword, "default"); sipSorceryEntities.SIPAccounts.AddObject(sipAccount); sipSorceryEntities.SaveChanges(); logger.Debug("SIP account " + sipAccount.SIPUsername + "@" + sipAccount.SIPDomain + " added for " + sipAccount.Owner + "."); break; } else { attempts++; } } } if (!m_customerConfirmLink.IsNullOrBlank()) { logger.Debug("Sending new account confirmation email to " + customer.EmailAddress + "."); SIPSorcerySMTP.SendEmail(customer.EmailAddress, NEW_ACCOUNT_EMAIL_FROM_ADDRESS, NEW_ACCOUNT_EMAIL_SUBJECT, String.Format(NEW_ACCOUNT_EMAIL_BODY, customer.Firstname, m_customerConfirmLink, customer.ID)); } else { logger.Debug("Customer confirmation email was not sent as no confirmation link has been set."); } } } }
private void GetCustomerCompleted(LoadOperation<Customer> lo) { if (lo.HasError) { UIHelper.SetText(m_statusTextBlock, lo.Error.Message); lo.MarkErrorAsHandled(); } else { m_customer = m_riaContext.Customers.FirstOrDefault(); if (m_customer == null) { UIHelper.SetText(m_statusTextBlock, "There was an error retrieving your details. Please re-login and try again."); } else { this.DataContext = m_customer; UIHelper.SetText(m_statusTextBlock, "Details successfully loaded."); SetUpdateButtonsEnabled(true); } } }