public Customer Get(int id) { DbCity dbc = new DbCity(); Customer customer; using (SqlConnection con = new SqlConnection(data.GetConnectionString())) { con.Open(); SqlCommand cmd = new SqlCommand("SELECT * FROM dbo.Booking_Customer WHERE Id = @id", con); cmd.Parameters.Add("@Id", SqlDbType.Int).Value = id; SqlDataReader rdr = cmd.ExecuteReader(); rdr.Read(); customer = new Customer { Id = (int)rdr["Id"], CPR = (long)rdr["Cpr"], PhoneNumber = (long)rdr["PhoneNo"], City = dbc.Get((int)rdr["City_Id"]), FirstName = (string)rdr["FirstName"], LastName = (string)rdr["LastName"], Email = (string)rdr["Email"], Address = (string)rdr["Address"], Password = (string)rdr["Password"], Confirmed = (bool)rdr["Cofirmed"] }; } return(customer); }
public IEnumerable <Customer> GetAllCustomers() { List <Customer> customers = new List <Customer>(); DbCity dbCity = new DbCity(); DbPayment dbp = new DbPayment(); using (SqlConnection con = new SqlConnection(data.GetConnectionString())) { con.Open(); using (SqlCommand cmd = con.CreateCommand()) { cmd.CommandText = "SELECT * FROM dbo.Booking_Customer"; var rdr = cmd.ExecuteReader(); while (rdr.Read()) { customers.Add(new Customer { Id = (int)rdr["Id"], FirstName = (string)rdr["FirstName"], LastName = (string)rdr["LastName"], Email = (string)rdr["Email"], CPR = (long)rdr["Cpr"], PhoneNumber = (long)rdr["PhoneNo"], City = dbCity.Get((int)rdr["City_Id"]), Address = (string)rdr["Address"], Password = (string)rdr["Password"], Confirmed = (bool)rdr["Cofirmed"], Role = (string)rdr["Roles"] }); } } } return(customers); }