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 int InsertRoomType(int roomstyleid, int roomsizeid, int price, string description) { int id = 0; using (SqlConnection conn = Connection.GetConnection()) { if (conn != null) { if (!RoomTypeDAO.CheckIsExistRoomTypeByStyleIdAndSizeId(roomstyleid, roomsizeid)) { SqlCommand cm = conn.CreateCommand(); cm.CommandText = "pro_CreateRoomType"; cm.CommandType = System.Data.CommandType.StoredProcedure; var rs = cm.ExecuteReader(); if (rs.HasRows) { rs.Read(); id = Decimal.ToInt32(rs.GetDecimal(0)); } conn.Close(); conn.Open(); if (id > 0) { string sql = "UPDATE RoomType SET RoomStyleID = @roomstyleid, RoomSizeID = @roomsizeid, Price = @price, Description = @description where RoomTypeID = @roomtypeid "; cm = new SqlCommand(sql, conn); cm.Parameters.AddWithValue("@roomtypeid", SqlDbType.Int).Value = id; cm.Parameters.AddWithValue("@roomstyleid", SqlDbType.Int).Value = roomstyleid; cm.Parameters.AddWithValue("@roomsizeid", SqlDbType.Int).Value = roomsizeid; cm.Parameters.AddWithValue("@price", SqlDbType.Int).Value = price; cm.Parameters.AddWithValue("@description", SqlDbType.NVarChar).Value = description; int row = cm.ExecuteNonQuery(); if (row > 0) { return(id); } } } } } return(0); }
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); }