public static RoomViewModel GetRoomViewModel(int roomid) { RoomViewModel model = null; using (SqlConnection conn = Connection.GetConnection()) { if (conn != null) { SqlCommand cm = new SqlCommand("select * from Room where RoomID = @roomid", conn); cm.Parameters.AddWithValue("@roomid", roomid); var rs = cm.ExecuteReader(); if (rs.HasRows) { rs.Read(); model = new RoomViewModel(); model.RoomID = rs.GetInt32(0); model.RoomType = RoomTypeDAO.GetRoomTypeModel(rs.GetInt32(1)); model.Status = rs.GetString(2); Booking CurrentBooking = BookingDAO.GetCurrentBookingOfRoom(model.RoomID); if (CurrentBooking != null) { model.Guests = StayDAO.GetALLGuestsOfBooking(CurrentBooking.BookingID); model.RemainingTime = BookingDAO.GetRemainingTimeOfBooking(CurrentBooking.BookingID); } else { model.Guests = new List <Guest>(); model.RemainingTime = TimeSpan.Zero; } } conn.Close(); } } return(model); }
public static RoomModel GetRoomModel(int roomid) { RoomModel r = null; SqlConnection conn = Connection.GetConnection(); if (conn != null) { string sql = "select * from Room where RoomID = @roomid"; SqlCommand cm = new SqlCommand(sql, conn); cm.Parameters.AddWithValue("@roomid", roomid); var rs = cm.ExecuteReader(); if (rs.HasRows) { rs.Read(); r = new RoomModel(); r.RoomID = rs.GetInt32(0); r.RoomType = RoomTypeDAO.GetRoomTypeModel(rs.GetInt32(1)); r.Status = rs.GetString(2); } conn.Close(); } return(r); }