Пример #1
0
        public static void AddCustomer(Customer customer)
        {
            var connectionString = ConfigurationManager.ConnectionStrings["appDatabase"].ConnectionString;

            using (var connection = new SqlConnection(connectionString))
            {
                var command = new SqlCommand
                {
                    Connection = connection,
                    CommandType = CommandType.StoredProcedure,
                    CommandText = "uspAddCustomer"
                };

                var firstNameParameter = new SqlParameter("@Firstname", SqlDbType.VarChar, 50) { Value = customer.FirstName };
                command.Parameters.Add(firstNameParameter);
                var surnameParameter = new SqlParameter("@Surname", SqlDbType.VarChar, 50) { Value = customer.LastName };
                command.Parameters.Add(surnameParameter);
                var dateOfBirthParameter = new SqlParameter("@DateOfBirth", SqlDbType.DateTime) { Value = customer.DateOfBirth };
                command.Parameters.Add(dateOfBirthParameter);
                var emailAddressParameter = new SqlParameter("@EmailAddress", SqlDbType.VarChar, 50) { Value = customer.EmailAddress };
                command.Parameters.Add(emailAddressParameter);
                var hasCreditLimitParameter = new SqlParameter("@HasCreditLimit", SqlDbType.Bit) { Value = customer.HasCreditLimit };
                command.Parameters.Add(hasCreditLimitParameter);
                var creditLimitParameter = new SqlParameter("@CreditLimit", SqlDbType.Int) { Value = customer.CreditLimit };
                command.Parameters.Add(creditLimitParameter);
                var companyIdParameter = new SqlParameter("@CompanyId", SqlDbType.Int) { Value = customer.Company.Id };
                command.Parameters.Add(companyIdParameter);

                connection.Open();
                command.ExecuteNonQuery();
            }
        }
Пример #2
0
        public bool AddCustomer(string firstName, string lastName, string email, DateTime dateOfBirth, int companyId)
        {
            this.Customer = InitialiseCustomer.InitCustomer(firstName, lastName, email, dateOfBirth);

            if (this.Customer != null)
            {
                this.Customer.Company = this.CompanyRepository.GetById(companyId);
            }
            else
            {
                //TODO: add error message for customer
                return false;
            }

            if (!new CustomerValidation(this.Customer).ValidateCustomer())
            {
                return false;
            }

            switch (this.Customer.Company.Classification)
            {
                case Classification.Gold:
                    this.Customer.HasCreditLimit = false;
                    break;
                case Classification.Silver:
                    this.Customer.HasCreditLimit = true;
                    using (this.CustomerCreditService as IDisposable)
                    {
                        int creditLimit = this.CustomerCreditService.GetCreditLimit(this.Customer.FirstName, this.Customer.LastName,
                                                                               this.Customer.DateOfBirth);
                        this.Customer.CreditLimit = creditLimit * 2;
                    }
                    break;
                default:
                    this.Customer.HasCreditLimit = true;
                    using (this.CustomerCreditService as IDisposable)
                    {
                        this.Customer.CreditLimit = this.CustomerCreditService.GetCreditLimit(this.Customer.FirstName, this.Customer.LastName,
                                                                               this.Customer.DateOfBirth);
                    }
                    break;
            }

            if (this.Customer.HasCreditLimit && this.Customer.CreditLimit < 500)
            {
                //TODO: add warning message for customer
                return false;
            }

            //TODO: add information message for customer
            this.Provider.AddCustomer(this.Customer);

            return true;
        }
Пример #3
0
        public virtual void TestSetup()
        {
            ValidCustomer = InitialiseCustomer.InitCustomer("John", "Doe", "*****@*****.**", new DateTime(1979, 08, 30));
            InvalidCustomerAge = InitialiseCustomer.InitCustomer("John", "Doe", "*****@*****.**", new DateTime(1999, 08, 30));
            InvalidCustomerEmail = InitialiseCustomer.InitCustomer("John", "Doe", "email", new DateTime(1979, 08, 30));
            InvalidCustomerFirstName = InitialiseCustomer.InitCustomer(string.Empty, "Doe", "email.com", new DateTime(1979, 08, 30));
            InvalidCustomerLastName = InitialiseCustomer.InitCustomer("John", string.Empty, "email.com", new DateTime(1979, 08, 30));
            InvalidCustomerFirstNameAndLastName = InitialiseCustomer.InitCustomer(string.Empty, string.Empty, "email.com", new DateTime(1979, 08, 30));

            GoldCompany = new Company { Classification = Classification.Gold, Id  =1, Name = "GoldCompany" };
            SilverCompany = new Company { Classification = Classification.Silver, Id = 2, Name = "SilverCompany" };
            BrozneCompany = new Company { Classification = Classification.Bronze, Id = 3, Name = "BronzeCompany" };
        }
Пример #4
0
        public static void ProveAddCustomer(string[] args)
        {
            var companyRepository   = new CompanyRepository();
            var customerDataAccess  = new CustomerDataAccess();
            var configurationHelper = new ConfigurationHelpers();
            var creditHelper        = new CreditHelpers();
            var clientHelper        = new ClientHelpers(configurationHelper);
            var customerService     = new CustomerService(companyRepository, customerDataAccess, clientHelper, creditHelper);

            var custInfo = new entityCustomer
            {
                Firstname    = "Joe",
                Surname      = "Bloggs",
                EmailAddress = "*****@*****.**",
                DateOfBirth  = new DateTime(1980, 3, 27),
                CompanyId    = 4
            };
            var addResult = customerService.AddCustomer(custInfo);

            Console.WriteLine("Adding Joe Bloggs was " + (addResult ? "successful" : "unsuccessful"));
        }