Exemple #1
0
 public static void CreditCheck(this Customer customer)
 {
     if (customer.Company.Name == Company.VERY_IMPORTANT_COMPANY)
     {
         // Skip credit check
         customer.HasCreditLimit = false;
     }
     else if (customer.Company.Name == Company.IMPORTANT_COMPANY)
     {
         // Do credit check and double credit limit
         customer.HasCreditLimit = true;
         using (var customerCreditService = new CustomerCreditServiceClient()) {
             var creditLimit = customerCreditService.GetCreditLimit(customer.Firstname, customer.Surname, customer.DateOfBirth);
             creditLimit          = creditLimit * 2;
             customer.CreditLimit = creditLimit;
         }
     }
     else
     {
         // Do credit check
         customer.HasCreditLimit = true;
         using (var customerCreditService = new CustomerCreditServiceClient()) {
             var creditLimit = customerCreditService.GetCreditLimit(customer.Firstname, customer.Surname, customer.DateOfBirth);
             customer.CreditLimit = creditLimit;
         }
     }
 }
 public CreditLimit GetCreditLimit(Customer customer)
 {
     using (var service = new CustomerCreditServiceClient())
     {
         return(service.GetCreditLimit(customer.Firstname,
                                       customer.Surname, customer.DateOfBirth));
     }
 }
        public int GetCreditLimitWithNormalClient(Customer customer)
        {
            int creditLimit;

            using (var customerCreditService = new CustomerCreditServiceClient())
            {
                creditLimit = customerCreditService.GetCreditLimit(customer.Firstname, customer.Surname,
                                                                   customer.DateOfBirth);
                customer.CreditLimit = creditLimit;
            }
            return(creditLimit);
        }
        public IAddCustomerResponse AddCustomer(IAddCustomerRequest request)
        {
            var response = new AddCustomerResponse(request);
            var company  = this.companyRepository.GetById(request.CompanyId);

            var customer = new Customer
            {
                Company      = company,
                DateOfBirth  = request.DateOfBirth,
                EmailAddress = request.Email,
                Firstname    = request.FirstName,
                Surname      = request.SurName
            };

            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 (var customerCreditService = new CustomerCreditServiceClient())
                {
                    var creditLimit = customerCreditService.GetCreditLimit(customer.Firstname, customer.Surname, customer.DateOfBirth);
                    creditLimit          = creditLimit * 2;
                    customer.CreditLimit = creditLimit;
                }
            }
            else
            {
                // Do credit check
                customer.HasCreditLimit = true;
                using (var customerCreditService = new CustomerCreditServiceClient())
                {
                    var creditLimit = customerCreditService.GetCreditLimit(customer.Firstname, customer.Surname, customer.DateOfBirth);
                    customer.CreditLimit = creditLimit;
                }
            }

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

            CustomerDataAccess.AddCustomer(customer);

            response.IsCustomerAdded = true;
            return(response);
        }
Exemple #5
0
        public bool AddCustomer(string firstName, string surName, string email, DateTime dateOfBirth, int companyId)
        {
            if (!ValidateInput(firstName, surName, email, dateOfBirth)) return false;

            var company = _companyRepository.GetById(companyId);
            if (company == null) return false; //Todo: create a new company

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

            switch (company.Name.ToLower())
            {
                case "veryimportantclient":
                    customer.HasCreditLimit = false;
                    break;
                case "importantclient":
                    customer.HasCreditLimit = true;
                    using (var customerCreditService = new CustomerCreditServiceClient())
                    {
                        var creditLimit = customerCreditService.GetCreditLimit(customer.Firstname, customer.Surname, customer.DateOfBirth);
                        creditLimit = creditLimit * 2;
                        customer.CreditLimit = creditLimit;
                    }
                    break;
                default:
                    customer.HasCreditLimit = true;
                    using (var customerCreditService = new CustomerCreditServiceClient())
                    {
                        var creditLimit = customerCreditService.GetCreditLimit(customer.Firstname, customer.Surname, customer.DateOfBirth);
                        customer.CreditLimit = creditLimit;
                    }
                    break;
            }

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

            CustomerDataAccess.AddCustomer(customer);

            return true;
        }
        public bool AddCustomer(Customer customer)
        {
            if (!IsCustomerVaild(customer))
            {
                return(false);
            }

            var companyRepository = new CompanyRepository();
            var company           = companyRepository.GetById(customer.Company.Id);

            customer.Company = company;

            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 (var customerCreditService = new CustomerCreditServiceClient())
                {
                    var creditLimit = customerCreditService.GetCreditLimit(customer.Firstname, customer.Surname, customer.DateOfBirth);
                    creditLimit          = creditLimit * 2;
                    customer.CreditLimit = creditLimit;
                }
            }
            else
            {
                // Do credit check
                customer.HasCreditLimit = true;
                using (var customerCreditService = new CustomerCreditServiceClient())
                {
                    var creditLimit = customerCreditService.GetCreditLimit(customer.Firstname, customer.Surname, customer.DateOfBirth);
                    customer.CreditLimit = creditLimit;
                }
            }

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

            CustomerDataAccess.AddCustomer(customer);

            return(true);
        }
Exemple #7
0
        public bool CheckCompany(Company company, Customer customer)
        {
            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 (var customerCreditService = new CustomerCreditServiceClient())
                {
                    var creditLimit = customerCreditService.GetCreditLimit(customer.Firstname, customer.Surname, customer.DateOfBirth);
                    creditLimit          = creditLimit * 2;
                    customer.CreditLimit = creditLimit;
                }
            }
            else
            {
                // Do credit check
                customer.HasCreditLimit = true;
                using (var customerCreditService = new CustomerCreditServiceClient())
                {
                    var creditLimit = customerCreditService.GetCreditLimit(customer.Firstname, customer.Surname, customer.DateOfBirth);
                    customer.CreditLimit = creditLimit;
                }
            }

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

            return(true);
        }