Ejemplo n.º 1
0
        private static void AddCustomer()
        {
            try
            {
                using (CustomerServiceClient client = new CustomerServiceClient())
                {
                    int index = client.AddCustomer(new Customer
                    {
                        CustomerId   = 101,
                        CustomerName = "Anish",
                        City         = "Kolkata",
                        State        = "West Bengal"
                    });
                    Console.WriteLine("{0}", index);
                }
            }

            // == Using normal exception and Fault exception ==
            //catch (Exception ex)
            //{
            //    Console.ForegroundColor = ConsoleColor.Red;
            //    Console.WriteLine(ex.Message);
            //    Console.ForegroundColor = ConsoleColor.White;
            //}

            catch (FaultException <InvalidCustomerEntry> ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("{0}:{1}", ex.Detail.ErrorCode, ex.Detail.ErrorMessage);
                Console.ForegroundColor = ConsoleColor.White;
            }
        }
Ejemplo n.º 2
0
        public void AddCustomer(string firstName, string lastName)
        {
            CustomerServiceClient customerServiceClient = new CustomerServiceClient();
            try
            {
                customerServiceClient.AddCustomer(new AddCustomerRequest
                                                      {
                                                          CustomerDto = new CustomerDto
                                                                            {
                                                                                FirstName = firstName,
                                                                                LastName = lastName
                                                                            }

                                                      });
            }
            catch (Exception exception)
            {
                string message = string.Format("An error occured while in type :{0} , method :{1} ", "CustomerServiceManager", MethodBase.GetCurrentMethod().Name);
                CommonLogManager.Log.Error(message, exception);
                throw;
            }
            finally
            {
                customerServiceClient.Close();
            }
        }
Ejemplo n.º 3
0
        private void button2_Click(object sender, RoutedEventArgs e)
        {
            CustomerServiceClient proxy = new CustomerServiceClient("BasicHttpBinding_CustomerService");


            proxy.AddCustomer(txtCustomerId.Text, txtCompnayName.Text, txtAddress.Text, txtCity.Text);
        }
Ejemplo n.º 4
0
        public void ExecuteNewCommand(object obj)
        {
            AddCustomerController newModel = new AddCustomerController();
            Customer newCustomer           = newModel.AddCustomer();

            if (newCustomer == null)
            {
                return;
            }
            _socket.AddCustomer(newCustomer);
            ExecuteLoadCommand(obj);
        }
Ejemplo n.º 5
0
        private void ExecuteNewCustomer(object o)
        {
            var controller = new AddWindowController();
            var customer   = controller.AddCustomer();

            if (customer != null)
            {
                if (client.AddCustomer(customer))
                {
                    ExecuteGetAll(o);
                }
            }
        }
        protected void btSubmit_Click(object sender, EventArgs e)
        {
            Customer cust = new Customer();

            cust.Billing         = Convert.ToInt32(tbBilling.Text);
            cust.PhoneNumber     = Convert.ToInt32(tbPhoneNumber.Text);
            cust.ShippingAddress = tbShippingAddress.Text;
            cust.CompanyName     = tbCompanyName.Text;
            cust.EmailAddress    = tbEmailAddress.Text;
            client.AddCustomer(cust);
            clearTxt();
            addCustomer.Style["Display"] = "None";
            bind(client);
        }
Ejemplo n.º 7
0
        public ActionResult Register(UserAccountViewModel userAccountViewModel)
        {
            if (ModelState.IsValid)
            {
                var alreadyCustomer = customerServiceClient.GetCustomerByEmail(userAccountViewModel.Email);
                if (alreadyCustomer != null)
                {
                    ModelState.AddModelError("Password", "An account with the same email already exists!");
                    return(View());
                }

                var customer    = Mapper.Map <Customer>(userAccountViewModel);
                var createdUser = customerServiceClient.AddCustomer(customer);
                orderServiceClient.CreateCart(customer.Email);
                if (createdUser != null)
                {
                    return(RedirectToAction("Login"));
                }
                ModelState.AddModelError("Password", "An error ocurred!");
                return(View());
            }

            return(View());
        }
Ejemplo n.º 8
0
        static void Main(string[] args)
        {
            CustomerServiceClient client = new CustomerServiceClient("BasicHttpBinding_ICustomerService");

            Console.WriteLine("This is a customer service\n Enter 1 for adding a customer\n Enter 2 for deleting your customer\n Enter 3 for retrieving a customer\n Enter 4 for retrieving all your customers\n");

            switch (Console.ReadKey().KeyChar)
            {
            case '1':
                Console.WriteLine();
                Customer newCustomer = new Customer();
                Console.WriteLine("Enter new customer details as required\n");
                Console.WriteLine("Enter the customer's First name and press an enter\n");
                newCustomer.FirstName = Console.ReadLine();
                Console.WriteLine("Enter the customer's Last name and press an enter\n");
                newCustomer.LastName = Console.ReadLine();
                Console.WriteLine("Enter the customer's Id and press an enter\n");
                newCustomer.CustomerId = Convert.ToInt32(Console.ReadLine());
                if (client.AddCustomer(newCustomer))
                {
                    Console.WriteLine("you have added a new customer please check the updated list below\n");
                    DisplayUpdatedCustomers();
                }
                else
                {
                    Console.WriteLine("\nyou have entered wrong data aborting");
                }
                break;

            case '2':
                Console.WriteLine();
                Console.WriteLine("Enter the customer id of the customer you want to delete");
                int tempId = Convert.ToInt32(Console.ReadLine());
                client.DeleteCustomerWithThisId(tempId);
                Console.WriteLine("you have deleted a customer with the specified ID please check the updated list below\n");
                DisplayUpdatedCustomers();
                break;

            case '3':
                Console.WriteLine();
                Console.WriteLine("Enter the customer id of the customer you want to retrieve");
                int tempCustId = Convert.ToInt32(Console.ReadLine());
                Console.WriteLine("PFB for the required details");
                Console.WriteLine("CustomerId\tFirstName\tLastName");
                Customer customerRetrieved = client.RetrieveCustomer(tempCustId);
                Console.WriteLine(customerRetrieved.CustomerId + "\t" + customerRetrieved.FirstName + "\t" + customerRetrieved.LastName);
                break;

            case '4':
                Console.WriteLine();
                DisplayUpdatedCustomers();
                break;
            }

            Console.WriteLine();

            void DisplayUpdatedCustomers()
            {
                List <Customer> customerList = client.RetrieveAllCustomers().ToList();

                Console.WriteLine("CustomerId\tFirstName\tLastName");
                foreach (Customer cust in customerList)
                {
                    Console.WriteLine(cust.CustomerId + "\t" + cust.FirstName + "\t" + cust.LastName);
                }
            }

            Console.WriteLine("\nThank you....bye bye\n press any key to exit");
            Console.ReadKey();
        }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            CustomerServiceClient _csClient = new CustomerServiceClient(new WSHttpBinding(), new EndpointAddress("http://localhost:51490/Services/CustomerService.svc"));

            try
            {
                // 1.Checks if there is a customer with a given customer number in the database
                Customer foundCustomer = _csClient.FindByCustomerNumber("3123123");
                if (foundCustomer != null)
                {
                    Console.WriteLine("The customer was found.");
                    Console.WriteLine("Name: {0}", foundCustomer.Name);
                    Console.WriteLine("Surname: {0}", foundCustomer.Surname);
                    Console.WriteLine("Phone number: {0}", foundCustomer.PhoneNumber);
                    Console.WriteLine("*******");
                }

                // 2.Gets all the customers from database
                List <Customer> customers = _csClient.GetAll().ToList();
                foreach (var customer in customers)
                {
                    Console.WriteLine("Name: {0}", customer.Name);
                    Console.WriteLine("Surname: {0}", customer.Surname);
                    Console.WriteLine("Phone number: {0}", customer.PhoneNumber);
                    Console.WriteLine("*******");
                }

                // 3.Creates and adds a new customer to the database

                Customer customerToAdd = new Customer
                {
                    Name           = "Jan",
                    Surname        = "Jarek",
                    CustomerNumber = DateTime.Now.Millisecond.ToString()
                };

                _csClient.AddCustomer(customerToAdd);
            }

            catch (DbUpdateException e)
            {
                Console.WriteLine("The given customer already exists in the database.");
                Console.WriteLine(e.ToString());
            }

            catch (TimeoutException timeProblem)
            {
                Console.WriteLine("The service operation timed out. " + timeProblem.Message);
                _csClient.Abort();
                Console.Read();
            }
            catch (CommunicationException commProblem)
            {
                Console.WriteLine("There was a communication problem. " + commProblem.Message);
                _csClient.Abort();
                Console.Read();
            }

            catch (Exception e)
            {
                Console.WriteLine("An unexpected error occured.");
                Console.WriteLine(e.ToString());
            }
        }
Ejemplo n.º 10
0
 public void AddCustomer(Customer customer)
 {
     serviceProxy.AddCustomer(customer);
 }