public void updateCustomers()
        {
            Customers customer = new CustomersBuilder("MILBO", "MBM - Solutions").Build();
            string    res      = repo.updateCustomers(customer);

            Assert.IsNotNull(res);
        }
Example #2
0
        public Customers findCustomerByNameAndPassword(string username, string password)
        {
            Customers customer = null;

            Connection    conn       = new Connection();
            SqlConnection connection = conn.SqlConnection;

            SqlCommand selectCommand = new SqlCommand();

            selectCommand.Connection  = connection;
            selectCommand.CommandType = CommandType.Text;
            selectCommand.CommandText = "select * from Customers where ContactName = @ContactName and PostalCode = @Password";

            selectCommand.Parameters.Add("@ContactName", SqlDbType.NChar);
            selectCommand.Parameters["@ContactName"].Value = username;

            selectCommand.Parameters.Add("@Password", SqlDbType.NChar);
            selectCommand.Parameters["@Password"].Value = password;

            try
            {
                connection.Open();
                SqlDataReader dataReader = selectCommand.ExecuteReader();

                if (dataReader.HasRows)
                {
                    dataReader.Read();
                    customer = new CustomersBuilder(dataReader.GetString(0), dataReader.GetString(1))
                               .ContactName(dataReader.IsDBNull(2) ? (string)null : dataReader.GetString(2))
                               .ContactTitle(dataReader.IsDBNull(3) ? (string)null : dataReader.GetString(3))
                               .Address(dataReader.IsDBNull(4) ? (string)null : dataReader.GetString(4))
                               .City(dataReader.IsDBNull(5) ? (string)null : dataReader.GetString(5))
                               .Region(dataReader.IsDBNull(6) ? (string)null : dataReader.GetString(6))
                               .PostalCode(dataReader.IsDBNull(7) ? (string)null : dataReader.GetString(7))
                               .Country(dataReader.IsDBNull(8) ? (string)null : dataReader.GetString(8))
                               .Phone(dataReader.IsDBNull(9) ? (string)null : dataReader.GetString(9))
                               .Fax(dataReader.IsDBNull(10) ? (string)null : dataReader.GetString(10))
                               .Build();
                }
                dataReader.Close();
            }
            catch (Exception exc)
            {
                logger.logError(DateTime.Now, "Error while trying to get Customer with ContactName = " + username + " and PostalCode = " + password);
                MessageBox.Show(exc.Message);
            }
            finally
            {
                connection.Close();
            }
            logger.logInfo(DateTime.Now, "GetCustomerById method has sucessfully invoked.");
            return(customer);
        }
Example #3
0
        public Customers getCustomerById(string customerID)
        {
            Customers customer = null;

            Connection    conn       = new Connection();
            SqlConnection connection = conn.SqlConnection;

            SqlCommand selectCommand = new SqlCommand();

            selectCommand.Connection  = connection;
            selectCommand.CommandType = CommandType.StoredProcedure;
            selectCommand.CommandText = "GetCustomerById";

            selectCommand.Parameters.Add("@CustomerID", SqlDbType.NChar);
            selectCommand.Parameters["@CustomerID"].Value = customerID;

            {
                try
                {
                    connection.Open();
                    SqlDataReader dataReader = selectCommand.ExecuteReader();

                    if (dataReader.HasRows)
                    {
                        dataReader.Read();
                        customer = new CustomersBuilder(dataReader.GetString(0), dataReader.GetString(1))
                                   .ContactName(dataReader.IsDBNull(2) ? (string)null : dataReader.GetString(2))
                                   .ContactTitle(dataReader.IsDBNull(3) ? (string)null : dataReader.GetString(3))
                                   .Address(dataReader.IsDBNull(4) ? (string)null : dataReader.GetString(4))
                                   .City(dataReader.IsDBNull(5) ? (string)null : dataReader.GetString(5))
                                   .Region(dataReader.IsDBNull(6) ? (string)null : dataReader.GetString(6))
                                   .PostalCode(dataReader.IsDBNull(7) ? (string)null : dataReader.GetString(7))
                                   .Country(dataReader.IsDBNull(8) ? (string)null : dataReader.GetString(8))
                                   .Phone(dataReader.IsDBNull(9) ? (string)null : dataReader.GetString(9))
                                   .Fax(dataReader.IsDBNull(10) ? (string)null : dataReader.GetString(10))
                                   .Build();
                    }
                    dataReader.Close();
                }
                catch (Exception exc)
                {
                    logger.logError(DateTime.Now, "Error while trying to get Customer with CustomerID = " + customerID + ".");
                    MessageBox.Show(exc.Message);
                }
                finally
                {
                    connection.Close();
                }
                logger.logInfo(DateTime.Now, "GetCustomerById method has sucessfully invoked.");
                return(customer);
            }
        }
 private Customers(CustomersBuilder builder)
 {
     this.customerID   = builder.GetCustomerID;
     this.companyName  = builder.GetCompanyName;
     this.contactName  = builder.GetContactName;
     this.contactTitle = builder.GetContactTitle;
     this.address      = builder.GetAddress;
     this.city         = builder.GetCity;
     this.region       = builder.GetRegion;
     this.postalCode   = builder.GetPostalCode;
     this.country      = builder.GetCountry;
     this.phone        = builder.GetPhone;
     this.fax          = builder.GetFax;
 }
Example #5
0
        public List <Customers> getAllCustomers()
        {
            List <Customers> customersList = new List <Customers>();

            Connection    conn       = new Connection();
            SqlConnection connection = conn.SqlConnection;

            using (SqlCommand command = new SqlCommand("select * from Customers", connection))
            {
                try
                {
                    connection.Open();
                    SqlDataReader dataReader = command.ExecuteReader();

                    while (dataReader.Read())
                    {
                        Customers customer = new CustomersBuilder(dataReader.GetString(0), dataReader.GetString(1))
                                             .ContactName(dataReader.IsDBNull(2) ? (string)null : dataReader.GetString(2))
                                             .ContactTitle(dataReader.IsDBNull(3) ? (string)null : dataReader.GetString(3))
                                             .Address(dataReader.IsDBNull(4) ? (string)null : dataReader.GetString(4))
                                             .City(dataReader.IsDBNull(5) ? (string)null : dataReader.GetString(5))
                                             .Region(dataReader.IsDBNull(6) ? (string)null : dataReader.GetString(6))
                                             .PostalCode(dataReader.IsDBNull(7) ? (string)null : dataReader.GetString(7))
                                             .Country(dataReader.IsDBNull(8) ? (string)null : dataReader.GetString(8))
                                             .Phone(dataReader.IsDBNull(9) ? (string)null : dataReader.GetString(9))
                                             .Fax(dataReader.IsDBNull(10) ? (string)null : dataReader.GetString(10))
                                             .Build();
                        customersList.Add(customer);
                    }

                    dataReader.Close();
                }
                catch (Exception exc)
                {
                    logger.logError(DateTime.Now, "Error while trying to get all Customers.");
                    MessageBox.Show(exc.Message);
                }
                logger.logInfo(DateTime.Now, "GetAllCustomers method has sucessfully invoked.");
                return(customersList);
            }
        }