示例#1
0
 public int CreditLimit(Customer customer)
 {
     using (var customerCreditService = new CustomerCreditServiceClient())
     {
         return(customerCreditService.GetCreditLimit(customer));
     }
 }
示例#2
0
 public int GetCreditLimit(string firstname, string surname, DateTime dateOfBirth)
 {
     using (var customerCreditService = new CustomerCreditServiceClient())
     {
         return(customerCreditService.GetCreditLimit(firstname, surname, dateOfBirth));
     }
 }
示例#3
0
 public Customer CalculateCreditLimit(Customer customer, int multiplyer)
 {
     customer.HasCreditLimit = true;
     using (var customerCreditService = new CustomerCreditServiceClient())
     {
         var creditLimit = customerCreditService.GetCreditLimit(customer.Firstname, customer.Surname, customer.DateOfBirth);
         customer.CreditLimit = creditLimit * multiplyer;
     }
     return(customer);
 }
示例#4
0
        //TODO: I would put the logic for this back into the Customer service code - in a reallife example into the business layer.
        // I also assume that the copany name is replaced with classification so gold = veryImportant , silver = important and bronze = others and would refactor accordingly
        public void SetCreditLimit()
        {
            if (Company.Name == "VeryImportantClient")
            {
                // Skip credit check
                HasCreditLimit = false;
            }
            else
            {
                // Do credit check
                HasCreditLimit = true;
                using (var customerCreditService = new CustomerCreditServiceClient())
                {
                    var creditLimit = customerCreditService.GetCreditLimit(Firstname, Surname, DateOfBirth);

                    CreditLimit = creditLimit;
                    //double credit limit for important clients
                    if (Company.Name == "ImportantClient")
                    {
                        creditLimit = creditLimit * 2;
                    }
                }
            }
        }
示例#5
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 companyRepository = new CompanyRepository();
            var company           = companyRepository.GetById(companyId);

            var customer = new Customer
            {
                Company      = company,
                DateOfBirth  = dateOfBirth,
                EmailAddress = email,
                Firstname    = firname,
                Surname      = 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)
            {
                return(false);
            }

            CustomerDataAccess.AddCustomer(customer);

            return(true);
        }