Exemplo n.º 1
0
        public Customer GetOneCustomerById(int id)
        {
            Customer customer = new Customer();

            try
            {
                using (SqlConnection conn = GetSqlConnection())
                {
                    using (SqlCommand cmd = conn.CreateCommand())
                    {
                        cmd.CommandText = @"SELECT * FROM Customers WHERE id = @Id";
                        cmd.Parameters.AddWithValue("@Id", id);
                        SqlDataReader reader = cmd.ExecuteReader();

                        if (reader.Read())
                        {
                            customer = CustomerFactory.MakeCustomer(reader);
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw new Exception(ErrorTypes.ERROR_GETONE_CLIENT);
            }

            return(customer);
        }
Exemplo n.º 2
0
        public IEnumerable <Customer> GetCustomers()
        {
            List <Customer> customers = new List <Customer>();

            try
            {
                using (SqlConnection conn = GetSqlConnection())
                {
                    using (SqlCommand cmd = conn.CreateCommand())
                    {
                        cmd.CommandText = @"SELECT * FROM Customers";

                        SqlDataReader reader = cmd.ExecuteReader();
                        while (reader.Read())
                        {
                            Customer customer = CustomerFactory.MakeCustomer(reader);
                            customers.Add(customer);
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw new Exception(ErrorTypes.ERROR_GETLIST_CLIENT);
            }


            return(customers);
        }
Exemplo n.º 3
0
        public IEnumerable <Customer> GetCustomers()
        {
            try
            {
                XElement doc = XElement.Load(connectionString);

                IEnumerable <Customer> customers = (from node in doc.Elements("Customer")
                                                    select CustomerFactory.MakeCustomer(node));

                return(customers);
            }
            catch (Exception)
            {
                throw new Exception(ErrorTypes.ERROR_GETLIST_CLIENT);
            }
        }
Exemplo n.º 4
0
        public Customer GetOneCustomerById(int id)
        {
            try
            {
                XElement doc = XElement.Load(connectionString);

                Customer customer = (from node in doc.Elements("Customer")
                                     where node.Element("Id").Value == id.ToString()
                                     select CustomerFactory.MakeCustomer(node))
                                    .SingleOrDefault();

                return(customer);
            }
            catch (Exception)
            {
                throw new Exception(ErrorTypes.ERROR_GETONE_CLIENT);
            }
        }