Inheritance: System.Data.Objects.DataClasses.EntityObject
Beispiel #1
0
        public CustomerAccount ToCustomerAccount()
        {
            CustomerAccount account = new CustomerAccount()
            {
                Owner         = String.Empty,
                ID            = ID,
                AccountName   = AccountName,
                AccountNumber = AccountNumber,
                Credit        = Credit,
                PIN           = PIN
            };

            return(account);
        }
Beispiel #2
0
 private void CheckUniqueFields(CustomerAccount customerAccount)
 {
     if (IsAccountNameInUse(customerAccount.Owner, customerAccount.AccountName, customerAccount.ID))
     {
         throw new ApplicationException("The account name is already in use.");
     }
     else if (customerAccount.AccountNumber != null && IsAccountNumberInUse(customerAccount.Owner, customerAccount.AccountNumber, customerAccount.ID))
     {
         throw new ApplicationException("The account number is already in use.");
     }
     else if (IsAccountCodeInUse(customerAccount.AccountCode, customerAccount.ID))
     {
         throw new ApplicationException("The account code is already in use.");
     }
 }
Beispiel #3
0
        /// <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();
            }
        }
        /// <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();
            }
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the CustomerAccounts EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToCustomerAccounts(CustomerAccount customerAccount)
 {
     base.AddObject("CustomerAccounts", customerAccount);
 }
 /// <summary>
 /// Create a new CustomerAccount object.
 /// </summary>
 /// <param name="id">Initial value of the ID property.</param>
 /// <param name="owner">Initial value of the Owner property.</param>
 /// <param name="accountCode">Initial value of the AccountCode property.</param>
 /// <param name="credit">Initial value of the Credit property.</param>
 /// <param name="inserted">Initial value of the Inserted property.</param>
 /// <param name="accountName">Initial value of the AccountName property.</param>
 /// <param name="ratePlan">Initial value of the RatePlan property.</param>
 public static CustomerAccount CreateCustomerAccount(global::System.String id, global::System.String owner, global::System.String accountCode, global::System.Decimal credit, global::System.String inserted, global::System.String accountName, global::System.Int32 ratePlan)
 {
     CustomerAccount customerAccount = new CustomerAccount();
     customerAccount.ID = id;
     customerAccount.Owner = owner;
     customerAccount.AccountCode = accountCode;
     customerAccount.Credit = credit;
     customerAccount.Inserted = inserted;
     customerAccount.AccountName = accountName;
     customerAccount.RatePlan = ratePlan;
     return customerAccount;
 }
 private void CheckUniqueFields(CustomerAccount customerAccount)
 {
     if (IsAccountNameInUse(customerAccount.Owner, customerAccount.AccountName, customerAccount.ID))
     {
         throw new ApplicationException("The account name is already in use.");
     }
     else if (customerAccount.AccountNumber != null && IsAccountNumberInUse(customerAccount.Owner, customerAccount.AccountNumber, customerAccount.ID))
     {
         throw new ApplicationException("The account number is already in use.");
     }
     else if (IsAccountCodeInUse(customerAccount.AccountCode, customerAccount.ID))
     {
         throw new ApplicationException("The account code is already in use.");
     }
 }
        /// <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();
                }
            }
        }
        public void DeleteCustomerAccount(string authUser, CustomerAccount customerAccount)
        {
            using (var sipSorceryEntities = new SIPSorceryEntities())
            {
                var existingAccount = (from ca in sipSorceryEntities.CustomerAccounts where ca.ID == customerAccount.ID && 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();
            }
        }
        public void UpdateCustomerAccount(string authUser, CustomerAccount customerAccount)
        {
            if (authUser.IsNullOrBlank())
            {
                throw new ArgumentException("An authenticated user is required for UpdateCustomerAccount.");
            }

            customerAccount.Owner = authUser;
            _customerAccountDataLayer.Update(customerAccount);
        }