Exemplo n.º 1
0
        /// <summary>
        /// Prompts the user to enter the credentials for creating a new
        /// customer.
        /// </summary>
        private static void AddCustomer()
        {
            bool retry = true; // process will continue to retry if

            string        usernameInput;
            string        emailInput;
            CustomerLogic customerLogic = new CustomerLogic();

            do
            {
                // Prompt user to enter usrname and email address
                Console.WriteLine("Please enter a username (max length 10):");
                usernameInput = Console.ReadLine();

                Console.WriteLine("Please enter a email (max length 50):");
                emailInput = Console.ReadLine();

                var response = customerLogic.AddCustomer(usernameInput, emailInput);

                Console.WriteLine(response.Text + "\n");
                if (response.Status == PacketStatus.Invalid)
                {
                    Console.WriteLine("Please try again...\n");
                }
                else
                {
                    retry = false;
                }
            } while (retry);
        }
        public void EmptyCustomerEmailTest()
        {
            CustomerLogic customerLogic       = new CustomerLogic();
            string        expectedFailMessage = "Please enter a valid email";
            var           response            = customerLogic.AddCustomer("aUser", "");

            Assert.Equal(expectedFailMessage, response.Text);
        }
        public void EmptyCustomerUsernameTest()
        {
            CustomerLogic customerLogic       = new CustomerLogic();
            string        expectedFailMessage = "Please enter a valid username";
            var           response            = customerLogic.AddCustomer("", "*****@*****.**");

            Assert.Equal(expectedFailMessage, response.Text);
        }
        public void TooLongCustomerEmailTest()
        {
            CustomerLogic customerLogic       = new CustomerLogic();
            string        longEmail           = "*****@*****.**";
            string        expectedFailMessage = "Emails need to be 50 characters or less";
            var           response            = customerLogic.AddCustomer("aUser", longEmail);

            Assert.Equal(expectedFailMessage, response.Text);
        }
        public void TooLongCustomerUsernameTest()
        {
            CustomerLogic customerLogic       = new CustomerLogic();
            string        longUsername        = "******";
            string        expectedFailMessage = "Usernames need to be 10 characters or less";
            var           response            = customerLogic.AddCustomer(longUsername, "*****@*****.**");

            Assert.Equal(expectedFailMessage, response.Text);
        }
        public void AddCustomerService(CustomerInfo customerinfo)
        {
            if (customerinfo.FirstName == null || customerinfo == null || customerinfo == null || customerinfo == null)
            {
                throw new FaultException("Yours input are not correct, please try again");
            }

            _customer.AddCustomer(customerinfo);
        }
Exemplo n.º 7
0
 public IHttpActionResult AddCustomer(CustomerDto am)
 {
     try
     {
         ML.AddCustomer(am);
         Console.WriteLine("dfd");
         return(Ok("pppp0"));
     }
     catch (Exception e)
     {
         return(BadRequest(e.ToString()));
     }
 }
Exemplo n.º 8
0
        private async void ToolbarItem_Clicked(object sender, System.EventArgs e)
        {
            var customer = new Customer
            {
                FirstName = firstNameEntry.Text,
                Surname   = surnameEntry.Text,
                Hire_Date = hire_datePicker.Date,
                Age       = int.Parse(ageEntry.Text)
            };

            await CustomerLogic.AddCustomer(customer);

            await Navigation.PopAsync();
        }
Exemplo n.º 9
0
        public string AddCustomer(Customer customer)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    customer.CustomerID = Guid.NewGuid();
                    var status = cust.AddCustomer(customer);

                    return(JsonConvert.SerializeObject(cust.GetCustomerByID(customer.CustomerID)));
                }
                else
                {
                    throw new Exception(JsonConvert.SerializeObject(CollectModelErrors()));
                }
            }
            catch (Exception ex)
            {
                Response.StatusCode = 512;
                return(JsonConvert.SerializeObject(ex.Message));
            }
        }