add functionality to create a room

This commit is contained in:
Andreas Zweili 2018-08-23 22:48:13 +02:00
parent 6d808b7a6e
commit 49914d3cd8
1 changed files with 26 additions and 2 deletions

View File

@ -12,8 +12,24 @@ namespace Plattform
{
public partial class Default: System.Web.UI.Page
{
List<Hotel> Hotels { get; set; }
List<RoomType> RoomTypes { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
HotelDB hotelDB = new HotelDB();
RoomTypeDB roomTypeDB = new RoomTypeDB();
this.Hotels = hotelDB.GetAllHotels();
DropDownHotel.DataSource = Hotels;
DropDownHotel.DataTextField = "Name";
DropDownHotel.DataValueField = "HotelID";
DropDownHotel.DataBind();
RoomTypes = roomTypeDB.GetAllRoomTypes();
DropDownRoomType.DataSource = RoomTypes;
DropDownRoomType.DataTextField = "Name";
DropDownRoomType.DataValueField = "RoomTypeID";
DropDownRoomType.DataBind();
}
protected void DropDownRoomType_SelectedIndexChanged(object sender, EventArgs e)
@ -37,7 +53,15 @@ namespace Plattform
}
protected void ButtonAddRoom_Click(object sender, EventArgs e)
{
RoomDB roomDB = new RoomDB();
Room room = new Room
{
Hotel = this.Hotels.Single(h => h.HotelID == int.Parse(DropDownHotel.SelectedValue)),
RoomType = this.RoomTypes.Single(t => t.RoomTypeID == int.Parse(DropDownRoomType.SelectedValue)),
FreeFrom = CalendarFrom.SelectedDate,
FreeUntil = CalendarTo.SelectedDate
};
roomDB.CreateRoom(room);
}
}
}
}