//Post bookroom public string BookRoom(int RoomId, DateTime date, string status) { var checkAvailability = GetAvailability(RoomId, date); if (checkAvailability == true) { Database.Booking booking = new Database.Booking(); booking.RoomId = RoomId; booking.BookingDate = date; switch (status) { case "definitive": booking.BookingStatusId = 2; break; case "cancelled": booking.BookingStatusId = 3; break; case "deleted": booking.BookingStatusId = 4; break; default: booking.BookingStatusId = 1; break; } _dbContext.Bookings.Add(booking); _dbContext.SaveChanges(); return("Booked Room Successfully!"); } else { return("The Room is already booked!"); } }
//Add a hotel public string CreateHotel(Model.Hotel hotel) { try { if (hotel != null) { Database.Hotel hoteldb = new Database.Hotel(); //hoteldb.Id = hotel.Id; hoteldb.Name = hotel.Name; hoteldb.Address = hotel.Address; hoteldb.City = hotel.City; hoteldb.Pincode = hotel.Pincode; hoteldb.ContactNumber = hotel.ContactNumber; hoteldb.ContactPerson = hotel.ContactPerson; hoteldb.IsActive = hotel.IsActive; hoteldb.CreatedDate = hotel.CreatedDate; hoteldb.CreatedBy = hotel.CreatedBy; List <Database.Room> hotelrooms = new List <Database.Room>(); foreach (var room in hotel.Rooms) { Database.Room hotelroom = new Database.Room(); //hotelroom.Id = room.Id; hotelroom.HotelId = room.HotelId; hotelroom.Name = room.Name; hotelroom.Price = room.Price; hotelroom.IsActive = room.IsActive; hotelroom.CreatedBy = room.CreatedBy; hotelroom.CreatedDate = room.CreatedDate; hotelroom.CategoryId = room.CategoryId; //hotelroom.Bookings = new List<Model.Booking>(); List <Database.Booking> hotelroombookings = new List <Database.Booking>(); foreach (var booking in room.Bookings) { Database.Booking hotelroombooking = new Database.Booking(); //hotelroombooking.Id = booking.Id; hotelroombooking.RoomId = booking.RoomId; hotelroombooking.Id = booking.Id; hotelroombooking.BookingDate = booking.BookingDate; hotelroombooking.BookingStatusId = booking.BookingStatusId; hotelroombookings.Add(hotelroombooking); } hotelroom.Bookings = hotelroombookings; hotelrooms.Add(hotelroom); } hoteldb.Rooms = hotelrooms; _dbContext.Hotels.Add(hoteldb); _dbContext.SaveChanges(); return("Successfully added!"); } return("Model is not added!"); } catch (Exception ex) { return(ex.Message); } throw new NotImplementedException(); }