Beispiel #1
0
        public int Add(Customers customer)
        {
            int result = dp.AddCustomer(customer);

            return result;
        }
Beispiel #2
0
        public List<Customers> GetAllCustomers()
        {
            List<Customers> retDataset = new List<Customers>();

            try
            {
                conn.Open();
                SqlCommand cmd = conn.CreateCommand();
                cmd.CommandType = System.Data.CommandType.StoredProcedure;
                cmd.CommandText = "spGetAllCustomers";

               SqlDataReader reader = cmd.ExecuteReader();
                if (reader != null)
                {
                    while(reader.Read())
                    {
                        var customer = new Customers();
                        customer.Id = int.Parse(reader["CustomerId"].ToString());
                        customer.FirstName = reader["FirstName"].ToString();
                        customer.LastName = reader["LastName"].ToString();
                        customer.Email = reader["Email"].ToString();
                        customer.Username = reader["Username"].ToString();
                        customer.Hash = reader["Hash"].ToString();
                        customer.Status = reader["Status"].ToString();
                        customer.StatusId = int.Parse(reader["StatusId"].ToString());
                        customer.Active = bool.Parse(reader["Active"].ToString());

                        retDataset.Add(customer);
                        
                    }
                    reader.Close();
                }



            }
            catch (Exception ex)
            {
                throw new OperationFailedException(ex.Message, ex);
            }
            finally
            {
                if (conn.State != System.Data.ConnectionState.Closed)
                {
                    conn.Close();
                }
            }

            return retDataset;
        }
Beispiel #3
0
        public int AddCustomer(Customers customer)
        {
            int newId = -1;
            
                try
                {
                    if (conn.State != ConnectionState.Open) { conn.Open(); }
                    SqlCommand cmd = conn.CreateCommand();
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.CommandText = "spAddCustomer";

                    var p2 = new SqlParameter[11];
                    for (int i = 0; i < 11; i++)
                        p2[i] = new SqlParameter();

                    p2[0] = new SqlParameter("firstName", customer.FirstName);
                    p2[1] = new SqlParameter("lastName", customer.LastName);
                    p2[2] = new SqlParameter("email", customer.Email);
                    p2[3] = new SqlParameter("username",  customer.Username);
                    p2[4] = new SqlParameter("updatUser", 100);
                    if (customer.Dob > DateTime.MinValue)
                    {
                        p2[5] = new SqlParameter("dob", customer.Dob);
                    }
                    else
                    {
                        p2[5] = new SqlParameter("dob",SqlDateTime.MinValue);
                    }

                    p2[6] = new SqlParameter("country",customer.Country);
                    p2[7] = new SqlParameter("city", customer.City);
                    p2[8] = new SqlParameter("town", customer.Town);
                    p2[9] = new SqlParameter("middleName", customer.MiddleName);
                    p2[10] = new SqlParameter("telephone", customer.Telephone);
                    
                    cmd.Parameters.AddRange(p2);

                    newId = int.Parse(cmd.ExecuteScalar().ToString());
                    if (conn.State != ConnectionState.Closed)
                    {
                        conn.Close();
                    }
                    UpdateUserSecurity(newId, customer.Hash, customer.SecurityQuestionId,
                        customer.SecurityAnswer);
               
                }
                catch (Exception ex)
                {
                    throw new OperationFailedException(ex.Message, ex);
                }
                finally
                {
                    if (conn.State != ConnectionState.Closed)
                    {
                        conn.Close();
                    }
                }
            
            return newId;
        }
Beispiel #4
0
        public Customers GetCustomerByLogon(string username)
        {
            Customers customer = null;

            try
            {
                if (conn.State != ConnectionState.Open || conn.State != ConnectionState.Connecting)
                conn.Open();
               

                SqlCommand cmd = conn.CreateCommand();
                cmd.CommandType = System.Data.CommandType.StoredProcedure;
                cmd.CommandText = "spGetCustomerByLogon";

                var p = new SqlParameter("username",username);
                
                cmd.Parameters.Add(p);

                SqlDataReader reader = cmd.ExecuteReader();
                if (reader != null)
                {
                    if (reader.Read())
                    {   
                        customer = new Customers();
                        customer.Id = int.Parse(reader["CustomerId"].ToString());
                        customer.FirstName = reader["FirstName"].ToString();
                        customer.LastName = reader["LastName"].ToString();
                        customer.Email = reader["Email"].ToString();
                        customer.Username = reader["Username"].ToString();
                        customer.Hash = reader["Hash"].ToString();
                        customer.Status = reader["Status"].ToString();
                        customer.StatusId = int.Parse(reader["StatusId"].ToString());
                        customer.MiddleName = reader["MiddleName"].ToString();
                        customer.Country = reader["Country"].ToString();
                        customer.City = reader["City"].ToString();
                        customer.Town = reader["Town"].ToString();
                        customer.Telephone = reader["Telephone"].ToString();
                        customer.Dob = DateTime.Parse(reader["Dob"].ToString());
                        customer.Active = bool.Parse(reader["Active"].ToString());
                    }
                    reader.Close();
                }



            }
            catch (Exception ex)
            {
                throw new OperationFailedException(ex.Message, ex);
            }
            finally
            {
                if (conn.State != System.Data.ConnectionState.Closed)
                {
                    conn.Close();
                }
            }

            return customer;
        }