public async Task MakeNewBookingAsync(Booking booking) { using (HotelBookingEntities db = new HotelBookingEntities()) { db.Bookings.Add(booking); await db.SaveChangesAsync(); //return bookingId; }; }
public async Task ResetHotelSizeAsync(int size) { using (HotelBookingEntities db = new HotelBookingEntities()) { //truncate the table string tableName = "Rooms"; //for now, use the "magic string", but the table name should be retrieved in a dynamic way (there is no built-in way for doing this, so some helper method should be implemented)... db.Database.ExecuteSqlCommand($"TRUNCATE TABLE {tableName}"); //add rooms according to the size Room[] rooms = new Room[size]; for (int i = 1; i <= size; i++) { rooms[i - 1] = new Room { Id = i, Name = $"Room {i}" }; } db.Rooms.AddRange(rooms); await db.SaveChangesAsync(); } }