public void createnewrevesationroom(RoomReservationMV resvationroom) { TBLroomReservation roomtemp = new TBLroomReservation(); roomtemp.roomID = resvationroom.roomID; roomtemp.reservationID = resvationroom.reservationID; hotel.TBLroomReservations.Add(roomtemp); hotel.SaveChanges(); }
public Response createnewrevesation(ReservationMV resvation) { Response result = Validatereservation(resvation); if (result.IsValid == true) { TBLreservation roomtemp = new TBLreservation(); roomtemp.fromDate = resvation.fromDate; roomtemp.toDate = resvation.fromDate.Value.AddDays(resvation.numDay); roomtemp.noOFpeople = resvation.noOFpeople; roomtemp.typeReservation = (int)resvation.roomtype; roomtemp.customerId = resvation.customerId; if (resvation.fromDate.Value.Date == DateTime.Now.Date) { StatusType tt = StatusType.Prossing; resvation.statereservation = tt; roomtemp.Status = (int)resvation.statereservation; } else if (resvation.fromDate.Value.Date > DateTime.Now.Date) { StatusType tt = StatusType.Pending; resvation.statereservation = tt; roomtemp.Status = (int)resvation.statereservation; } hotel.TBLreservations.Add(roomtemp); hotel.SaveChanges(); var res = hotel.TBLreservations.OrderByDescending(r => r.id).FirstOrDefault(); if (resvation.selectroom2 != null) { for (int i = 0; i < resvation.selectroom2.Count; i++) { string nameroom = resvation.selectroom2[i]; var room = hotel.TBLrooms.SingleOrDefault(r => r.roomNumber == nameroom); RoomReservationMV room2 = new RoomReservationMV(); room2.reservationID = res.id; room2.roomID = room.id; createnewrevesationroom(room2); } } if (resvation.selectroom3 != null) { for (int i = 0; i < resvation.selectroom3.Count; i++) { string nameroom = resvation.selectroom3[i]; var room = hotel.TBLrooms.SingleOrDefault(r => r.roomNumber == nameroom); RoomReservationMV room2 = new RoomReservationMV(); room2.reservationID = res.id; room2.roomID = room.id; createnewrevesationroom(room2); } } if (resvation.selectsweet != null) { for (int i = 0; i < resvation.selectsweet.Count; i++) { string nameroom = resvation.selectsweet[i]; var room = hotel.TBLrooms.SingleOrDefault(r => r.roomNumber == nameroom); RoomReservationMV room2 = new RoomReservationMV(); room2.reservationID = res.id; room2.roomID = room.id; createnewrevesationroom(room2); } } } return(result); }