Exemple #1
0
        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);
        }
Exemple #2
0
        public IEnumerable <Bookings> GetAllBookings()
        {
            DbPayment       dbp      = new DbPayment();
            DbCustomer      dbc      = new DbCustomer();
            DbDeparture     dbd      = new DbDeparture();
            List <Bookings> bookings = new List <Bookings>();
            DbCity          dbCity   = new DbCity();

            using (SqlConnection con = new SqlConnection(data.GetConnectionString()))
            {
                con.Open();

                using (SqlCommand cmd = con.CreateCommand())
                {
                    cmd.CommandText = "SELECT * FROM dbo.Booking_Booking";
                    var rdr = cmd.ExecuteReader();

                    while (rdr.Read())
                    {
                        bookings.Add(new Bookings
                        {
                            Id         = (int)rdr["Id"],
                            Payment    = dbp.Get((int)rdr["Payment_Id"]),
                            Customer   = dbc.Get((int)rdr["Customer_Id"]),
                            Departure  = dbd.Get((int)rdr["Departure_Id"]),
                            Date       = (DateTime)rdr["Date"],
                            TotalPrice = (int)rdr["Price"]
                        });
                    }
                }
            }
            return(bookings);
        }
Exemple #3
0
        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);
        }