Example #1
0
 private void btnReserve_Click(object sender, EventArgs e)
 {
     var client = new ClientDTO
     {
         FirstName = tbxFirstName.Text,
         LastName = tbxLastName.Text,
         Email = tbxEmail.Text,
         Phone = tbxPhone.Text
     };
     _service.InsertClient(client);
     int clientId = _service.GetClientId(client.Email);
     int hotelId = _service.GetHotelId(cbxHotel.SelectedValue.ToString());
     MessageBox.Show(hotelId.ToString());
     string roomName = cbxRoom.SelectedValue.ToString();
     bool approved = cbxStatus.Checked;
     var room = new RoomDTO
     {
         ClientId = clientId,
         HotelId = hotelId,
         Name = roomName,
         Approved = approved
     };
     _service.InsertRoom(room);
     lbxClients.DataSource = _service.GetClients();
     ResetInfo();
 }
        public RoomDTO GetRowById(int id)
        {
            string connectionString = ConfigurationManager.ConnectionStrings["ConnectToSQL"].ConnectionString;
            IRoomRepository repository = new RoomRepository(connectionString);

            using (SqlConnection connection = new SqlConnection(connectionString))
            {
                connection.Open();
                using (SqlCommand command = new SqlCommand(queryGetAllId, connection))
                {
                    command.Parameters.AddWithValue("id", id);
                    using (SqlDataReader reader = command.ExecuteReader())
                    {
                        RoomDTO room = new RoomDTO();
                        if (reader.Read())
                        {
                            room = (new RoomDTO()
                            {
                                Id = (int)reader["id"],
                                Name = (string)reader["Name"],
                                Price = (int)reader["Price"]
                            });
                            return room;
                        }
                        else
                        {
                            return null;
                        }

                    }
                }
            }
        }
Example #3
0
 public void InsertRoom(RoomDTO roomDTO)
 {
     var room = new Room
     {
         ClientId = roomDTO.ClientId,
         HotelId = roomDTO.HotelId,
         Name = roomDTO.Name,
         Approved = roomDTO.Approved
     };
     string connectionString = ConfigurationManager.ConnectionStrings["HotelServiceDB"].ConnectionString;
     IRoomRepository repository = new RoomRepository(connectionString);
     repository.Insert(room);
 }