コード例 #1
0
        public CreditStatus Apply(Customer customer)
        {
            var company      = _companyRepository.GetById(customer.Company.Id);
            var creditStatus = new CreditStatus();

            if (company.Name == "VeryImportantClient")
            {
                // Skip credit check
                creditStatus.HasCreditLimit = false;
            }
            else if (company.Name == "ImportantClient")
            {
                // Do credit check and double credit limit
                creditStatus.HasCreditLimit = true;
                var creditLimit = _customerCreditService.GetCreditLimit(customer.Firstname, customer.Surname, customer.DateOfBirth);
                creditLimit = creditLimit * 2;
                creditStatus.CreditLimit = creditLimit;
            }
            else
            {
                // Do credit check
                creditStatus.HasCreditLimit = true;
                var creditLimit = _customerCreditService.GetCreditLimit(customer.Firstname, customer.Surname, customer.DateOfBirth);
                creditStatus.CreditLimit = creditLimit;
            }

            if (creditStatus.HasCreditLimit && creditStatus.CreditLimit < _creditLimit)
            {
                creditStatus.Failed = true;
            }

            return(creditStatus);
        }
コード例 #2
0
        // ***We can move this as part of NEW/independent Comapnyservice

        // Check customer Credit score before creating them into system
        private bool IsValidCreditScore(Customer customer, int companyId)
        {
            // Get Company Details
            customer.Company = _companyRepository.GetById(companyId);

            // Based on customer company profile get credit limit
            switch (customer.Company.Name)
            {
            case "VeryImportantClient":
                // Skip credit check
                customer.HasCreditLimit = false;
                break;

            case "ImportantClient":
                // Do credit check and double credit limit
                customer.HasCreditLimit = true;
                var creditLimit = _customerCreditService.GetCreditLimit(customer.Firstname, customer.Surname, customer.DateOfBirth);
                customer.CreditLimit = creditLimit * 2;
                break;

            default:
                // Do credit check
                customer.HasCreditLimit = true;
                customer.CreditLimit    = _customerCreditService.GetCreditLimit(customer.Firstname, customer.Surname, customer.DateOfBirth);
                break;
            }

            return(!customer.HasCreditLimit || customer.CreditLimit >= 500);
        }
コード例 #3
0
        public int RetriveCreditLimit(Customer customer, int bonusCredit = 1)
        {
            var creditLimit = _creditClient.GetCreditLimit(customer.Firstname, customer.Surname, customer.DateOfBirth);

            creditLimit = creditLimit * bonusCredit;
            return(creditLimit);
        }
コード例 #4
0
        private void SetCreditLimit(CreditLimit creditLimitType, Customer customer)
        {
            if (creditLimitType == CreditLimit.None)
            {
                customer.HasCreditLimit = false;
            }
            else
            {
                customer.HasCreditLimit = true;

                var creditLimit = _customerCreditService.GetCreditLimit(customer.Firstname, customer.Surname, customer.DateOfBirth);
                creditLimit          = creditLimitType == CreditLimit.Normal ? creditLimit : creditLimit * 2;
                customer.CreditLimit = creditLimit;
            }
        }
コード例 #5
0
ファイル: CreditProvider.cs プロジェクト: kotasha/Chsharp
 int GetCreditLimit()
 {
     return(_customerCreditService.GetCreditLimit(_customer.Firstname, _customer.Surname, _customer.DateOfBirth));
 }
コード例 #6
0
        public bool AddCustomer(string firname, string surname, string email, DateTime dateOfBirth, int companyId)
        {
            if (string.IsNullOrEmpty(firname) || string.IsNullOrEmpty(surname))
            {
                return(false);
            }

            if (!email.Contains("@") && !email.Contains("."))
            {
                return(false);
            }

            var now = DateTime.Now;
            int age = now.Year - dateOfBirth.Year;

            if (now.Month < dateOfBirth.Month || (now.Month == dateOfBirth.Month && now.Day < dateOfBirth.Day))
            {
                age--;
            }

            if (age < 21)
            {
                return(false);
            }

            var company = dataAccess.GetCompanyById(companyId);

            var customer = new Customer
            {
                Company      = company,
                DateOfBirth  = dateOfBirth,
                EmailAddress = email,
                Firstname    = firname,
                Surname      = surname
            };

            if (company.Classification == Classification.Gold)
            {
                // skip credit check
                customer.HasCreditLimit = false;
            }
            if (company.Classification == Classification.Silver)
            {
                // do credit check and double credit limit
                customer.HasCreditLimit = true;

                var creditLimit = customerCreditService.GetCreditLimit(customer.Firstname, customer.Surname, customer.DateOfBirth);
                creditLimit          = creditLimit * 2;
                customer.CreditLimit = creditLimit;
            }
            else
            {
                // do credit check
                customer.HasCreditLimit = true;

                var creditLimit = customerCreditService.GetCreditLimit(customer.Firstname, customer.Surname, customer.DateOfBirth);
                customer.CreditLimit = creditLimit;
            }

            if (customer.HasCreditLimit && customer.CreditLimit < 500)
            {
                return(false);
            }

            dataAccess.AddCustomer(customer);

            return(true);
        }
コード例 #7
0
        public Customer enrichCustomerDetail(string firname, string surname, string email, DateTime dateOfBirth, int companyId)
        {
            var now = DateTime.Now;
            int age = now.Year - dateOfBirth.Year;

            if (now.Month < dateOfBirth.Month || (now.Month == dateOfBirth.Month && now.Day < dateOfBirth.Day))
            {
                age--;
            }

            if (age < 21)
            {
                return(null);
            }

            // var companyRepository = new CompanyRepository();
            var company = _companyRepository.GetById(companyId);

            var customer = new Customer
            {
                Company      = company,
                DateOfBirth  = dateOfBirth,
                EmailAddress = email,
                Firstname    = firname,
                Surname      = surname
            };

            // I did this because maybe we have a company that is not stored in our DB perhaps and it will throw a null exception
            if (!(company == null))
            {
                if (company.Name == "VeryImportantClient")
                {
                    // Skip credit check
                    customer.HasCreditLimit = false;
                }
                else if (company.Name == "ImportantClient")
                {
                    // Do credit check and double credit limit
                    customer.HasCreditLimit = true;
                    using (_customerCreditService)
                    {
                        var creditLimit = _customerCreditService.GetCreditLimit(customer.Firstname, customer.Surname, customer.DateOfBirth);
                        creditLimit          = creditLimit * 2;
                        customer.CreditLimit = creditLimit;
                    }
                }
                else
                {
                    // Do credit check
                    customer.HasCreditLimit = true;

                    // ICustomerCreditService is being disposed after using, so everything which is unmanaged will be out of scope.
                    using (_customerCreditService)
                    {
                        var creditLimit = _customerCreditService.GetCreditLimit(customer.Firstname, customer.Surname, customer.DateOfBirth);
                        customer.CreditLimit = creditLimit;
                    }
                }
            }


            if (customer.HasCreditLimit && customer.CreditLimit < 500)
            {
                return(null);
            }

            return(customer);
        }