Пример #1
0
        public void SaveCustomer(ref Customer customer)
        {
            int customerId = customer.Id;

            var existingCustomer = _customers.FirstOrDefault(x => x.Id == customerId);
            if (existingCustomer == null)
            {
                customer.Id = _customers.Count + 1;
                _customers.Add(customer);
            }
            else
            {
                existingCustomer.FirstName = customer.FirstName;
                existingCustomer.LastName = customer.LastName;
            }
           
        }
Пример #2
0
        private void Start()
        {
            var customerServices = ObjectFactory.GetInstance<ICustomerService>();

            var customer1 = customerServices.GetCustomer(1);
            
            Console.WriteLine("Customer 1 Last name is '{0}'", customer1.LastName);

            var newCustomer = new Customer() {FirstName = "Sue", LastName = "Queue"};
            customerServices.SaveCustomer(ref newCustomer);

            Console.WriteLine("New Customer ID is '{0}', FirstName: {1}, LastName: {2}", newCustomer.Id, newCustomer.FirstName, newCustomer.LastName);

            newCustomer.LastName = "Smith"; 
            customerServices.SaveCustomer(ref newCustomer);

            Console.WriteLine("New Customer ID is '{0}', FirstName: {1}, LastName: {2}", newCustomer.Id, newCustomer.FirstName, newCustomer.LastName);

            Console.Read();
        }