Esempio n. 1
0
        // Create address
        public int create(String lineOne, String lineTwo, String lineThree, String lineFour, String lineFive,
                              String state, String county, String country, String postCode)
        {
            // Creates an address model
            AddressModel addressModel = new AddressModel();

            // Holds the new address
            Address newAddress = new Address();

            // Stored details for address
            newAddress.LineOne = lineOne;
            newAddress.LineTwo = lineTwo;
            newAddress.LineThree = lineThree;
            newAddress.LineFour = lineFour;
            newAddress.LineFive = lineFive;
            newAddress.State = state;
            newAddress.County = county;
            newAddress.Country = country;
            newAddress.PostalCode = postCode;

            // Adds the object to the database. Returns address ID
            int addressID = addressModel.CreateAddress(newAddress);

            // Return address ID
            return addressID;
        }
Esempio n. 2
0
        public int CreateAddress(Address a)
        {
            int ret = 0;

            using (connect = new MySqlConnection(_connectionString))
            {
                connect.Open();
                using (MySqlTransaction transaction = connect.BeginTransaction())
                {
                    try
                    {
                        string query = "NewAddress";
                        var cmd = new MySqlCommand(query, connect) { CommandType = CommandType.StoredProcedure };

                        cmd.Parameters.AddWithValue("AddressLine1", a.LineOne);
                        cmd.Parameters.AddWithValue("AddressLine2", a.LineTwo);
                        cmd.Parameters.AddWithValue("AddressLine3", a.LineThree);
                        cmd.Parameters.AddWithValue("AddressLine4", a.LineFour);
                        cmd.Parameters.AddWithValue("AddressLine5", a.LineFive);
                        cmd.Parameters.AddWithValue("Pstate", a.State);
                        cmd.Parameters.AddWithValue("Pcounty", a.County);
                        cmd.Parameters.AddWithValue("Pcountry", a.Country);
                        cmd.Parameters.AddWithValue("postalCode", a.PostalCode);

                        ret = int.Parse(cmd.ExecuteScalar().ToString());

                        transaction.Commit();

                        connect.Close();
                    }
                    catch (InvalidOperationException ioException)
                    {
                        transaction.Rollback();
                        connect.Close();
                    }
                }
            }
            return ret;
        }
Esempio n. 3
0
        // This method is used to get a list of addresses containing element in the address object.
        public List<Address> SearchAddressesByAddress(Address a)
        {
            var addressList = new List<Address>();

            using (connect = new MySqlConnection(_connectionString))
            {
                try
                {
                    string query = "SearchAddress";
                    var cmd = new MySqlCommand(query, connect) { CommandType = CommandType.StoredProcedure };

                    cmd.Parameters.AddWithValue("AddressID", a.ID);
                    cmd.Parameters.AddWithValue("AddressLine1", a.LineOne);
                    cmd.Parameters.AddWithValue("AddressLine2", a.LineTwo);
                    cmd.Parameters.AddWithValue("AddressLine3", a.LineThree);
                    cmd.Parameters.AddWithValue("AddressLine4", a.LineFour);
                    cmd.Parameters.AddWithValue("AddressLine5", a.LineFive);
                    cmd.Parameters.AddWithValue("Pstate", a.State);
                    cmd.Parameters.AddWithValue("Pcounty", a.County);
                    cmd.Parameters.AddWithValue("Pcountry", a.Country);
                    cmd.Parameters.AddWithValue("postalCode", a.PostalCode);

                    connect.Open();

                    var reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        var ad = new Address();

                        ad.ID = int.Parse(reader["Address_ID"].ToString());
                        ad.LineOne = reader["Address_Line1"].ToString();

                        if (reader["Address_Line2"] != null)
                        {
                            ad.LineTwo = reader["Address_Line2"].ToString();
                        }
                        if (reader["Address_Line3"] != null)
                        {
                            ad.LineThree = reader["Address_Line3"].ToString();
                        }
                        if (reader["Address_Line4"] != null)
                        {
                            ad.LineFour = reader["Address_Line4"].ToString();
                        }
                        if (reader["Address_Line5"] != null)
                        {
                            ad.LineFive = reader["Address_Line5"].ToString();
                        }
                        if (reader["State"] != null)
                        {
                            ad.State = reader["State"].ToString();
                        }
                        if (reader["County"] != null)
                        {
                            ad.County = reader["County"].ToString();
                        }
                        if (reader["Country"] != null)
                        {
                            ad.Country = reader["Country"].ToString();
                        }

                        ad.PostalCode = reader["Postal_Code"].ToString();

                        addressList.Add(ad);
                    }

                    connect.Close();
                }
                catch (InvalidOperationException ioException)
                {
                    connect.Close();
                }

                return addressList;
            }
        }
Esempio n. 4
0
 // Method calls main method for getting addressed
 public Address SearchAddress(Address a)
 {
     return SearchAddress(a.ID);
 }
Esempio n. 5
0
        // This is the main method to get an address.
        public Address SearchAddress(int ID)
        {
            var address = new Address();

            using (connect = new MySqlConnection(_connectionString))
            {
                try
                {
                    string query = "GetAddress";
                    var cmd = new MySqlCommand(query, connect) { CommandType = CommandType.StoredProcedure };

                    cmd.Parameters.AddWithValue("AddressID", ID);

                    connect.Open();

                    var reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        address.ID = int.Parse(reader["Address_ID"].ToString());
                        address.LineOne = reader["Address_Line1"].ToString();

                        if (reader["Address_Line2"] != null)
                        {
                            address.LineTwo = reader["Address_Line2"].ToString();
                        }
                        if (reader["Address_Line3"] != null)
                        {
                            address.LineThree = reader["Address_Line3"].ToString();
                        }
                        if (reader["Address_Line4"] != null)
                        {
                            address.LineFour = reader["Address_Line4"].ToString();
                        }
                        if (reader["Address_Line5"] != null)
                        {
                            address.LineFive = reader["Address_Line5"].ToString();
                        }
                        if (reader["State"] != null)
                        {
                            address.State = reader["State"].ToString();
                        }
                        if (reader["County"] != null)
                        {
                            address.County = reader["County"].ToString();
                        }
                        if (reader["Country"] != null)
                        {
                            address.Country = reader["Country"].ToString();
                        }

                        address.PostalCode = reader["Postal_Code"].ToString();

                    }

                    connect.Close();
                }
                catch (InvalidOperationException ioException)
                {
                    connect.Close();
                }

                return address;
            }
        }
Esempio n. 6
0
        public List<Address> GetAddressesList()
        {
            var addressList = new List<Address>();

            using (connect = new MySqlConnection(_connectionString))
            {
                try
                {
                    string query = "ListAddress";
                    var cmd = new MySqlCommand(query, connect) { CommandType = CommandType.StoredProcedure };

                    connect.Open();

                    var reader = cmd.ExecuteReader();

                    while (reader.Read())
                    {
                        var a = new Address();

                        a.ID = int.Parse(reader["Address_ID"].ToString());
                        a.LineOne = reader["Address_Line1"].ToString();

                        if(reader["Address_Line2"] != null)
                        {
                                a.LineTwo = reader["Address_Line2"].ToString();
                        }
                        if (reader["Address_Line3"] != null)
                        {
                            a.LineThree = reader["Address_Line3"].ToString();
                        }
                        if (reader["Address_Line4"] != null)
                        {
                            a.LineFour = reader["Address_Line4"].ToString();
                        }
                        if (reader["Address_Line5"] != null)
                        {
                            a.LineFive = reader["Address_Line5"].ToString();
                        }
                        if (reader["State"] != null)
                        {
                            a.State = reader["State"].ToString();
                        }
                        if (reader["County"] != null)
                        {
                            a.County = reader["County"].ToString();
                        }
                        if (reader["Country"] != null)
                        {
                            a.Country = reader["Country"].ToString();
                        }

                        a.PostalCode = reader["Postal_Code"].ToString();

                        addressList.Add(a);
                    }

                    connect.Close();
                }
                catch (InvalidOperationException ioException)
                {
                    connect.Close();
                }

                return addressList;
            }
        }
Esempio n. 7
0
        public void EditAddress(Address a)
        {
            using (connect = new MySqlConnection(_connectionString))
            {
                connect.Open();
                using (MySqlTransaction transaction = connect.BeginTransaction())
                {
                    try
                    {
                        string query = "EditAddress";
                        var cmd = new MySqlCommand(query, connect) { CommandType = CommandType.StoredProcedure };

                        cmd.Parameters.AddWithValue("AddressID", a.ID);
                        cmd.Parameters.AddWithValue("AddressLine1", a.LineOne);
                        cmd.Parameters.AddWithValue("AddressLine2", a.LineTwo);
                        cmd.Parameters.AddWithValue("AddressLine3", a.LineThree);
                        cmd.Parameters.AddWithValue("AddressLine4", a.LineFour);
                        cmd.Parameters.AddWithValue("AddressLine5", a.LineFive);
                        cmd.Parameters.AddWithValue("Pstate", a.State);
                        cmd.Parameters.AddWithValue("Pcounty", a.County);
                        cmd.Parameters.AddWithValue("Pcountry", a.Country);
                        cmd.Parameters.AddWithValue("postalCode", a.PostalCode);

                        cmd.ExecuteNonQuery();

                        transaction.Commit();

                        connect.Close();
                    }
                    catch (InvalidOperationException ioException)
                    {
                        transaction.Rollback();
                        connect.Close();
                    }
                }
            }
        }
Esempio n. 8
0
 // This method is to get orders that match on elements included in the address object.
 // Will match on items being source of destination, specified by AddressType enum.
 public List<Order> SearchOrder(Address a, AddressType type)
 {
     throw new NotImplementedException();
 }
Esempio n. 9
0
 // This method is to get packages that match on elements included in the address object.
 // Will match on items being source of destination, specified by AddressType enum.
 public List<Package> SearchPackage(Address a, AddressType type)
 {
     throw new NotImplementedException();
 }
Esempio n. 10
0
        // Controller for modification of an address
        public ActionResult edit()
        {
            // Null handling
            if (Session["loggedInState"] == null)
            {
                return Redirect("/403.html");
            }

            // Checks if logged in
            bool state = (bool)Session["loggedInState"];
            if (state == true)
            {
                // Creates an address placeholder
                var address = new Address();

                // Setup address edit
                address.ID = int.Parse(Request.Form["id"]);
                address.LineOne = Request.Form["lineOne"].ToString();
                address.LineTwo = Request.Form["lineTwo"].ToString();
                address.LineThree = Request.Form["lineThree"].ToString();
                address.LineFour = Request.Form["lineFour"].ToString();
                address.LineFive = Request.Form["lineFive"].ToString();
                address.PostalCode = Request.Form["postalCode"].ToString();
                address.County = Request.Form["county"].ToString();
                address.Country = Request.Form["country"].ToString();

                // Establish address model
                var addressModel = new AddressModel();

                // Conduct edit
                addressModel.EditAddress(address);

                // Passes back to the view
                return View();
            }
            else
            {
                // If not logged in
                return Redirect("/login.html");
            }
        }
Esempio n. 11
0
 // Finds customers that have the deatils specified in the address object.
 public List<Customer> SearchCustomers(Address a)
 {
     throw new NotImplementedException();
 }
Esempio n. 12
0
 // Gets a list of account that have the address specified in the address object.
 public List<Account> SearchAccounts(Address a)
 {
     throw new NotImplementedException();
 }