public void AddCustomerToCollection()
        {
            // generate a customer
            Customer customer = new Customer();;

            customer.Name          = "AddCustomerToCollection";
            customer.StreetAddress = "STREETADDRESS";
            customer.City          = "CITY";
            customer.State         = "STATE";
            customer.PostalCode    = "POSTALCODE";
            customer.PhoneNumber   = "PHONENUMBER";


            // capture the existing record count. The test will use this
            // to determine if the add method increased the number of records
            int initialRecordCount = _customerManager.GetCustomers().Count();

            // assign the id to the customer object using AddCustomer
            customer.Id = _customerManager.AddCustomer(customer);

            // get the customer from the manager
            Customer storedCustomer = _customerManager.GetSingleCustomer(customer.Id);

            // There are customers in the list
            Assert.True(_customerManager.GetCustomers().Count() > initialRecordCount);

            // The customer created by the test is in the list
            Assert.Equal(customer.Id, storedCustomer.Id);
        }
Ejemplo n.º 2
0
        public void Test_Orders_Update()
        {
            CustomerManager cm = new CustomerManager(new UnitOfWork(new DataContext("development")));
            OrderManager    om = new OrderManager(new UnitOfWork(new DataContext("development")));

            om.RemoveAll();
            cm.RemoveAll();
            cm.AddCustomer(new Customer("Tim", "Azaleastraat 57, 9940 Evergem"));
            Customer c = cm.GetAll().Last();

            om.Add(new Order(c, Product.DUVEL, 5));
            Order order = om.GetAll().Last();

            Assert.AreEqual(order.CustomerID, c.ID);
            Assert.AreEqual(order.Product, Product.DUVEL);
            Assert.AreEqual(order.Amount, 5);
            cm.AddCustomer(new Customer("Jolien", "Wolffaertshoflaan 3, 2630 Aartselaar"));
            int c2_id = cm.GetAll().Last().ID;

            order.CustomerID = c2_id;
            order.Product    = Product.LEFFE;
            order.Amount     = 3;
            om.Update(order);
            Order o2 = om.GetByID(order.ID);

            Assert.AreEqual(o2.CustomerID, c2_id);
            Assert.AreEqual(o2.Product, Product.LEFFE);
            Assert.AreEqual(o2.Amount, 3);
            om.RemoveAll();
        }
Ejemplo n.º 3
0
        public void AddNewCustomer()
        {
            Customer customerToAdd = new Customer()
            {
                Name    = "Meg Ducharme",
                Address = "West Nashville",
                City    = "Nashville",
                State   = "TN",
                ZipCode = 37209,
                Phone   = "5555555555"
            };

            Console.WriteLine(customerToAdd.ZipCode);

            List <Customer> emptyList = _customerManager.GetAllCustomers();

            Assert.True(emptyList.Count == 0);

            int customerId = _customerManager.AddCustomer(customerToAdd);

            customerToAdd.Id = customerId;

            List <Customer> allCustomers = _customerManager.GetAllCustomers();

            Assert.Equal(customerToAdd.Name, allCustomers[0].Name);
            Assert.Equal(customerToAdd.Address, allCustomers[0].Address);
            Assert.Equal(customerToAdd.City, allCustomers[0].City);
            Assert.Equal(customerToAdd.State, allCustomers[0].State);
            Assert.Equal(customerToAdd.ZipCode, allCustomers[0].ZipCode);
            Assert.Equal(customerToAdd.Phone, allCustomers[0].Phone);
        }
Ejemplo n.º 4
0
        public void AddCustomerShould()
        {
            Customer newCustomer = new Customer();

            int result = _cm.AddCustomer(newCustomer);

            Assert.IsType <int>(result);
        }
Ejemplo n.º 5
0
 public void Test_Customers_GetAll()
 {
     CustomerManager cm = new CustomerManager(new UnitOfWork(new DataContext("development")));
     cm.RemoveAll();
     cm.AddCustomer(new Customer("Tim", "Azaleastraat 57, 9940 Evergem"));
     cm.AddCustomer(new Customer("Tim", "Azaleastraat 57, 9940 Evergem"));
     cm.AddCustomer(new Customer("Tim", "Azaleastraat 57, 9940 Evergem"));
     Assert.AreEqual(cm.GetAll().Count, 3);
     cm.RemoveAll();
 }
Ejemplo n.º 6
0
        public void GetSingleCustomer()
        {
            CustomerManagerShould();
            CustomerManager newCustomer = new CustomerManager(_db);

            newCustomer.AddCustomer(_customer);
            Customer theCustomer = newCustomer.GetSingleCustomer(1);
            int      result      = newCustomer.AddCustomer(_customer);

            Assert.True(result > 0);
        }
Ejemplo n.º 7
0
        public void GetAllCustomers()
        {
            CustomerManagerShould();
            CustomerManager newCustomer = new CustomerManager(_db);

            newCustomer.AddCustomer(_customer);
            List <Customer> allCustomers = newCustomer.GetAllCustomers();
            int             result       = newCustomer.AddCustomer(_customer);

            Assert.True(result > 0);
        }
Ejemplo n.º 8
0
        public void Test_Customers_DeleteAll()
        {
            CustomerManager CManager = new CustomerManager(new UnitOfWork(new DataContext("test")));

            CManager.DeleteAllCustomer();
            CManager.AddCustomer(new Customer("A Name", "A Adress value"));
            CManager.AddCustomer(new Customer("A Name1", "A Adress value1"));
            CManager.AddCustomer(new Customer("A Name2", "A Adress value2"));
            Assert.AreEqual(CManager.GetAllCustomers().Count, 3);
            CManager.DeleteAllCustomer();
            Assert.AreEqual(CManager.GetAllCustomers().Count, 0);
        }
Ejemplo n.º 9
0
            static void Main(string[] args)
            {
                Customer        c1  = new Customer(100, "Santwana", "Delhi", 5000);
                Customer        c2  = new Customer(200, "Amrita", "Bihar", 10000);
                Customer        c3  = new Customer(300, "Vipul", "Pune", 7000);
                CustomerManager mgr = new CustomerManager();

                mgr.AddCustomer(c1);
                mgr.AddCustomer(c2);
                mgr.AddCustomer(c3);

                mgr.ViewAllCustomer();
                mgr.DeleteCustomer(300);
                mgr.ViewAllCustomer();
            }
        public ActionResult Add(Customer customer)
        {
            _customerManager.AddCustomer(customer);

            aCustomer.Customers = _customerManager.GetAll();
            return(View(aCustomer));
        }
        /// <summary>
        /// Adds a new membership user to the data source.
        /// </summary>
        /// <param name="username">The user name for the new user.</param>
        /// <param name="password">The password for the new user.</param>
        /// <param name="email">The e-mail address for the new user.</param>
        /// <param name="passwordQuestion">The password question for the new user.</param>
        /// <param name="passwordAnswer">The password answer for the new user.</param>
        /// <param name="isApproved">Whether or not the new user is approved to be validated.</param>
        /// <param name="providerUserKey">The unique identifier from the membership data source for the user.</param>
        /// <param name="status">A MembershipCreateStatus enumeration value indicating whether the user was created successfully.</param>
        /// <returns>A MembershipUser object populated with the information for the newly created user.</returns>
        public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
        {
            MembershipUser user = null;

            string _username = string.Empty;
            string _email    = string.Empty;

            if (CustomerManager.UsernamesEnabled)
            {
                _username = username;
                _email    = email;
            }
            else
            {
                //little hack here. username variable was used to store customer email
                _username = username;
                _email    = username;
            }

            Customer customer = CustomerManager.AddCustomer(_email, _username, password,
                                                            false, false, true, out status);

            if (status == MembershipCreateStatus.Success)
            {
                DateTime dt = DateTimeHelper.ConvertToUtcTime(DateTime.Now);
                user = new MembershipUser(this.Name, _username, customer.CustomerGUID, _email, string.Empty, null, true, false, dt, dt, dt, dt, dt);
            }
            return(user);
        }
        public void AddCustomerStringBuilder(CustomerManager SB)
        {
            Customer customer = new Customer();

            Console.WriteLine("Enter customer first name");
            Console.Write("> ");
            customer.FirstName = Console.ReadLine();
            Console.WriteLine("Enter customer last name");
            Console.Write("> ");
            customer.LastName = Console.ReadLine();
            Console.WriteLine("Enter customer Street");
            Console.Write("> ");
            customer.Street = Console.ReadLine();
            Console.WriteLine("Enter customer City");
            Console.Write("> ");
            customer.City = Console.ReadLine();
            Console.WriteLine("Enter customer State");
            Console.Write("> ");
            customer.State = Console.ReadLine();
            Console.WriteLine("Enter customer postal code");
            Console.Write("> ");
            customer.ZipCode = Int32.Parse(Console.ReadLine());
            Console.WriteLine("Enter customer phone number");
            Console.Write("> ");
            customer.PhoneNumber = Console.ReadLine();
            SB.AddCustomer(customer);
            Menus.MainMenu();
        }
Ejemplo n.º 13
0
 public ActionResult Register(Customer customer, string confirmPassword)
 {
     if (customerManager.CheckUserName(customer.UserName))
     {
         ModelState.AddModelError("", "Username already exists");
         return(View());
     }
     else if (customer.Password != customer.ConfirmPassword)
     {
         ModelState.AddModelError("", "Passwords do not match");
         return(View());
     }
     else
     {
         try
         {
             customerManager.AddCustomer(customer);
             Customer user = customerManager.GetCustomerByUserName(customer.UserName);
             Session["AccessToken"] = SecurityManager.LogInUser(user);
             return(View("../Home/Index"));
         }
         catch (Exception ex)
         {
             ModelState.AddModelError("", ex.Message);
             return(View());
         }
     }
 }
Ejemplo n.º 14
0
        public ActionResult Add(CustomerViewModel customerViewModel)
        {
            if (ModelState.IsValid)
            {
                string fileName = Path.GetFileNameWithoutExtension(customerViewModel.ImageFile.FileName);
                customerViewModel.Image = customerViewModel.Code + fileName + System.IO.Path.GetExtension(customerViewModel.ImageFile.FileName);
                fileName = "~/images/CustomerImages/" + customerViewModel.Code + fileName + System.IO.Path.GetExtension(customerViewModel.ImageFile.FileName);
                customerViewModel.ImageFile.SaveAs(Server.MapPath(fileName));

                Customer customer = new Customer();
                customer = Mapper.Map <Customer>(customerViewModel);

                if (_customerManager.AddCustomer(customer))
                {
                    ViewBag.Message = "Saved";
                }
                else
                {
                    ViewBag.Message = "Failed";
                }
            }
            else
            {
                ViewBag.Message = "Validation Error";
            }

            return(View());
        }
Ejemplo n.º 15
0
    private Customer AddCustomer()
    {
        Customer customer = new Customer()
        {
            Address      = BillingAddressControl.Address,
            CellPhone    = CellPhoneTextBox.Text,
            City         = BillingAddressControl.City,
            Company      = ComapnyTextBox.Text,
            CountryID    = BillingAddressControl.CountryID,
            DateCreated  = DateTime.Now,
            DateUpdated  = DateTime.Now,
            DayPhone     = DayPhoneTextBox.Text,
            Email        = EmailTextBox.Text,
            EveningPhone = EveningPhoneTextBox.Text,
            Fax          = FaxTextBox.Text,
            StateID      = BillingAddressControl.StateID,
            FirstName    = FirstNameTextBox.Text,
            LastName     = LastNameTextBox.Text,
            ProvinceID   = BillingAddressControl.ProvinceID,
            Zipcode      = BillingAddressControl.Zipcode,
            Active       = true
        };

        return(CustomerManager.AddCustomer(customer));
    }
Ejemplo n.º 16
0
        private void AddItem_Click(object sender, RoutedEventArgs e)
        {
            bool x = false;

            using (var db = new SouthwindContext())
            {
                //Change so that query calls a method from Customer Manager, Don't have gui talking to databse
                var query =
                    from c in db.Customers
                    where c.CustomerId == CustomerIdInput.Text
                    select c.CustomerId;
                if (query.Contains(CustomerIdInput.Text))
                {
                    MessageBox.Show("Error, CustomerId already taken. Please enter a different option");
                }
                else
                {
                    x = true;
                }
            }
            if (x == true)
            {
                _customerManager.AddCustomer(CustomerIdInput.Text, ContactNameInput.Text, CompanyNameInput.Text);
            }
            FillListBox();
        }
 private void AddButton_Click(object sender, EventArgs e)
 {
     try
     {
         _customer.Name     = nameTextBox.Text;
         _customer.Address  = addressTextBox.Text;
         _customer.Contact  = contactTextBox.Text;
         _customer.Item     = comboBoxItem.Text;
         _customer.Quantity = Convert.ToInt32(quantityTextBox.Text);
         DataTable isSearch = _customerManager.SearchCustomer(_customer);
         if (isSearch.Rows.Count > 0)
         {
             MessageBox.Show("Name Exists");
         }
         else
         {
             bool isAdded = _customerManager.AddCustomer(_customer);
             if (isAdded)
             {
                 MessageBox.Show("Saved");
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
        public void AddNewCustomer()
        {
            Customer newCustomer = new Customer("Dude McDude", "Address", "City", "State", 37209, "111-222-333");
            int      customerId  = _customer.AddCustomer(newCustomer);

            Assert.True(customerId != 0);
        }
Ejemplo n.º 19
0
        public void AddCustomer()
        {
            CustomerManagerShould();
            Customer Pippins = new Customer();
            int      result  = _cm.AddCustomer(Pippins);

            Assert.True(result > 0);
        }
Ejemplo n.º 20
0
        public IHttpActionResult CreateUserAccount(RegistrationDTO userInput) // CREATE ACCOUNT
        {
            TextResult          httpResponse = new TextResult("There is already an account with that name!", msg);
            UserAccountsManager umgr         = new UserAccountsManager();
            CustomerManager     cmgr         = new CustomerManager();

            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            bool EmailIsOk = cmgr.IsValidEmail(userInput.Email);

            if (EmailIsOk.Equals(false))
            {
                httpResponse.ChangeHTTPMessage("Enter valid email!", msg);
                return(httpResponse); // HTTP response if accountname already exists
            }
            ;
            bool accNameExist = umgr.CheckIfAccountNameExists(userInput.AccountName); // Check if username already exists, returns bool

            if (accNameExist.Equals(true))
            {
                return(httpResponse); // HTTP response if accountname already exists
            }
            ;
            bool emailExists = cmgr.CheckIfEmailExists(userInput.Email); // check if email already exists, returns bool

            if (emailExists.Equals(true))
            {
                httpResponse.ChangeHTTPMessage("Email already exists!", msg); // If email exists, HTTP response
                return(httpResponse);
            }
            ;
            bool passwordIsNotOk = umgr.CheckIfPasswordIsOk(userInput.AccountPassword); // checks if password is ok

            if (passwordIsNotOk.Equals(true))
            {
                httpResponse.ChangeHTTPMessage("Password must contain atleast six characters, one digit and one uppercase!", msg); // If password is not ok, HTTP response
                return(httpResponse);
            }
            ;
            var customerObject = cmgr.AddCustomer(userInput.Email);                                                                                                       // Creates customer entity
            var userObject     = umgr.CreateUserAccount(userInput.AccountName, userInput.AccountPassword, userInput.PhoneNumber, userInput.CustomerName, customerObject); // creates useraccount entity

            try
            {
                db.Customers.Add(customerObject); // adds customer entity to DB
                db.UserAccounts.Add(userObject);  // adds useraccount to DB
                db.SaveChanges();
            }
            catch
            {
                httpResponse.ChangeHTTPMessage("Failed to create account!", msg); // HTTP response if fails to savechanges to DB
                return(httpResponse);
            }

            return(Ok()); // returns login token if registration succesfull
        }
Ejemplo n.º 21
0
        public void AddCustomerReturnInt()
        {
            Customer _custy = new Customer("Dylan", "Smith", "WarriorDr", "Murfreesboro", "TN", 37128, "615-481-2667");

            var X = _Dylan.AddCustomer(_custy);

            Assert.True(X != 0);
            Console.WriteLine(X);
        }
Ejemplo n.º 22
0
 public void CreatedANewCustomer()
 {
     using (var db = new SouthwindContext())
     {
         var x = db.Customers.Count();
         _customerManager.AddCustomer("WILLC", "Michael Willcock", "Sparta Global");
         var y = db.Customers.Count();
         Assert.AreEqual(y, x + 1);
     }
 }
Ejemplo n.º 23
0
 public ActionResult AddCustomer(Customer customer)
 {
     try
     {
         if (customerManager.AddCustomer(customer))
         {
             ViewBag.SMsg = "Saved Successfully";
         }
         else
         {
             ViewBag.FMsg = "Not Saved..!!!";
         }
     }
     catch (Exception ex)
     {
         ViewBag.FMsg = ex.Message;
     }
     return(View());
 }
Ejemplo n.º 24
0
        public void SetActiveCustomer_Should()
        {
            // Adds a customer to the database and returns the ID of that new customer
            int id = _customerManager.AddCustomer(_customer);

            // Method to extract the customer based off the ID of the newly added customer
            var ac = _activeCustomerManager.SetActiveCustomer(id);

            // Asserts that the id of the new customer and the id of the returned customer from SetActiveCustomer are the same
            Assert.Equal(id, ac.Id);
        }
Ejemplo n.º 25
0
        public void CheckForIncompleteOrderShould()
        {
            CustomerManager _customerManager = new CustomerManager(_db);
            ActiveCustomer  _activeManager   = new ActiveCustomer();
            var             newCustomerId    = _customerManager.AddCustomer(new Customer("Bob", "Some Street", "City", "TN", 12345, "5555555555"));

            _activeManager.setActiveCustomerId(newCustomerId);
            var incompleteOrderId = _orderManager.CheckForIncompleteOrder();

            Assert.Null(incompleteOrderId);
        }
Ejemplo n.º 26
0
        public void CreateOrderShould()
        {
            CustomerManager _customerManager = new CustomerManager(_db);
            ActiveCustomer  _activeManager   = new ActiveCustomer();
            var             newCustomerId    = _customerManager.AddCustomer(new Customer("Ryan McCarty", "3041 Old Field Way", "Lexington", "Ky", 40513, "859-588-2850"));

            _activeManager.setActiveCustomerId(newCustomerId);
            var newOrderId = _orderManager.CreateOrder();

            Assert.IsType <int>(newOrderId);
        }
Ejemplo n.º 27
0
        public IHttpActionResult CustomerBooking(CustomerBookingDTO booking) // BOOKING WITHOUT USER ACCOUNT, ONLY AS CUSTOMER
        {
            if (!ModelState.IsValid)
            {
                var errors = this.ModelState.Keys.SelectMany(key => this.ModelState[key].Errors);
                return(BadRequest(ModelState));
            }
            TextResult      httpResponse     = new TextResult("", msg);
            SeatManager     smgr             = new SeatManager();
            CustomerManager cmgr             = new CustomerManager();
            BookingManager  bmgr             = new BookingManager();
            Customers       custEntity       = new Customers();
            Bookings        bookingEntity    = new Bookings();
            int?            customerId       = null;
            DateTime        currentDate      = DateTime.Now;
            var             convertedForDate = bmgr.DateTimeConverter(booking.BookingForDate);                 // Convert dates passed from fronted to DateTime objects
            int?            allSeatsId       = smgr.GetSeatPlacementId(booking.RowNumber, booking.SeatNumber); // Gets the allSeatsId from AllSeats from row and seatnumber

            try
            {
                custEntity = cmgr.AddCustomer(booking.Email); // try to create new customer entity
                db.Customers.Add(custEntity);
                db.SaveChanges();                             // if customer entity exists, trying to insert a new customer will cause exception due to duplicate keys
            } catch
            {
                customerId = cmgr.FindCustomerId(booking.Email);                                             // if customer entity already exists, get customerID from email input
            }
            if (customerId != null)                                                                          // if customer entity already exists, customerId is not null, use customerId instead of entity
            {
                bookingEntity = bmgr.CustomerBooking(convertedForDate, currentDate, allSeatsId, customerId); // creates booking entity with customerId
                try
                {
                    db.Bookings.Add(bookingEntity);     // creates booking enitity, with customerId
                    db.SaveChanges();
                }
                catch
                {
                    httpResponse.ChangeHTTPMessage("Could not make booking!", msg);
                    return(httpResponse);
                }
            }
            bookingEntity = bmgr.CustomerBooking(custEntity, convertedForDate, currentDate, allSeatsId); // creates booking entity, with customerEntity
            try
            {
                db.Bookings.Add(bookingEntity);
                db.SaveChanges();
            }   catch
            {
                httpResponse.ChangeHTTPMessage("Could not make booking!", msg);
                return(httpResponse);
            }
            httpResponse.ChangeHTTPMessage("Booking completed!", msg);
            return(httpResponse);
        }
Ejemplo n.º 28
0
 public void Test_Customers_RemoveByID()
 {
     CustomerManager cm = new CustomerManager(new UnitOfWork(new DataContext("development")));
     cm.RemoveAll();
     cm.AddCustomer(new Customer("Tim", "Azaleastraat 57, 9940 Evergem"));
     Customer c = cm.GetAll().Last();
     int amount = cm.GetAll().Count;
     cm.Remove(c.ID);
     int newAmount = cm.GetAll().Count;
     Assert.AreEqual(newAmount, amount - 1);
     cm.RemoveAll();
 }
Ejemplo n.º 29
0
 public void Test_Customers_Get()
 {
     CustomerManager cm = new CustomerManager(new UnitOfWork(new DataContext("development")));
     cm.RemoveAll();
     cm.AddCustomer(new Customer("Tim", "Azaleastraat 57, 9940 Evergem"));
     int id = cm.GetAll().Last().ID;
     Customer c = cm.GetByID(id);
     Assert.AreEqual(c.ID, id);
     Assert.AreEqual(c.Name, "Tim");
     Assert.AreEqual(c.Address, "Azaleastraat 57, 9940 Evergem");
     cm.RemoveAll();
 }
        protected void addBtn_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(nameTxtBox.Text))
            {
                lblerrormsg.Text = "Name cannot be empty.";
                nameTxtBox.Focus();
                return;
            }

            if (string.IsNullOrEmpty(addressTxtBox.Text))
            {
                lblerrormsg.Text = "Address cannot be empty.";
                addressTxtBox.Focus();
                return;
            }

            bool     isInsert = true;
            Customer obj      = new Customer();

            if (!string.IsNullOrEmpty(hdnUserId.Value))
            {
                obj.CustomerID = int.Parse(hdnUserId.Value);
                isInsert       = false;
            }

            obj.Name    = nameTxtBox.Text;
            obj.Address = addressTxtBox.Text;

            if (MaleRadioButton.Checked)
            {
                obj.Gender = MaleRadioButton.Text;
            }
            if (FemaleRadioButton.Checked)
            {
                obj.Gender = FemaleRadioButton.Text;
            }

            bool status = CustomerManager.AddCustomer(obj, isInsert);

            if (status)
            {
                if (isInsert)
                {
                    string message = "Customer added successfully.";
                    Response.Redirect("~/Web/Customer/CustomerList.aspx?status=" + message);
                }
                else
                {
                    string message = "Customer details edited successfully.";
                    Response.Redirect("~/Web/Customer/CustomerList.aspx?status=" + message);
                }
            }
        }