public async Task Handle(V1.BookRoom command) { var period = new StayPeriod(command.CheckIn, command.CheckOut); var roomId = new RoomId(command.RoomId); var exists = await _store.Exists <Booking>(command.BookingId); if (exists) { throw new ApplicationException($"Booking with id {command.BookingId} already exists"); } var booking = new Booking(); await booking.BookRoom(command.BookingId, command.GuestId, roomId, period, _availabilityCheck); await _store.Store(booking); }
public IActionResult BookRoom (IFormCollection formData) { BookingDetails details = new BookingDetails(); if (ModelState.IsValid) { details.Name = Convert.ToString(formData["Name"]); details.EmailAddress = Convert.ToString(formData["EmailAddress"]); details.StartDate = Convert.ToDateTime(formData["StartDate"]); details.EndDate = Convert.ToDateTime(formData["EndDate"]); details.Type = (RoomType)Enum.Parse(typeof(RoomType), formData["Type"].ToString()); var confirmationDetails = _b.BookRoom(details.Type, details.Name, details.EmailAddress, details.StartDate, details.EndDate); TempData.Clear(); return(View(nameof(Confirmation), confirmationDetails)); } return(View()); }
static void Main(string[] args) { var b = new Booking(); //b.PopulateRooms(3, 5); // This is onetime job to populate rooms master data Console.WriteLine("WELCOME TO MY NEW HOTEL"); while (true) { Console.WriteLine("1.SEARCH AVAILABLE ROOMS"); Console.WriteLine("2.BOOK A ROOM"); Console.WriteLine("3.SEARCH BOOKING DETAILS"); Console.WriteLine("4.CHECKIN BY BOOKINGID"); Console.WriteLine("5.CHECKOUT BY ROOMNO"); Console.WriteLine("6.EXIT"); Console.Write("please select an option:"); var option = Console.ReadLine(); switch (option) { case "1": try { PrintRooms(b); } catch (FormatException ex) { Console.WriteLine(ex.Message); } break; case "2": try { Console.Write("Enter your name:"); var name = Console.ReadLine(); Console.Write("Enter emailadress:"); var email = Console.ReadLine(); var avRooms = PrintRooms(b); Console.Write("Enter Room Type : "); var roomType = (RoomType)Enum.Parse(typeof(RoomType), Console.ReadLine()); var roomData = avRooms.Where(x => x.Type == roomType).FirstOrDefault(); if (roomData.AvailableRoomCount > 0) { var bookRoom = b.BookRoom(roomType, name, email, startdate, enddate); Console.WriteLine("Successfully completed your room booking:"); Console.WriteLine("booking confirmation no:{0}", bookRoom.ID); } else { Console.WriteLine("No rooms available for this type " + roomType); } } catch (NullReferenceException) { Console.WriteLine($"Error:selection should be in the above list of numbers"); } catch (ArgumentException ax) { Console.WriteLine($"Error:{ax.Message}"); } catch (FormatException ex) { Console.WriteLine(ex.Message); } catch (BookingException hx) { Console.WriteLine(hx.Message); } catch { Console.WriteLine("something went wrong plese try again"); } break; case "3": try { Console.Write("Enter booking ID:"); var ID = Convert.ToInt32(Console.ReadLine()); var details = b.GetBookingDetails(ID); Console.WriteLine("Name: {0}", details.Name); Console.WriteLine("Email Address: {0}", details.EmailAddress); Console.WriteLine("Startdate: {0}", details.StartDate.ToShortDateString()); Console.WriteLine("Enddate: {0}", details.EndDate.ToShortDateString()); Console.WriteLine("RoomType: {0}", details.Type); } catch (BookingException) { Console.WriteLine("Booking ID does not exists"); } catch (FormatException ex) { Console.WriteLine(ex.Message); } break; case "4": try { Console.Write("Enter booking ID:"); var ID = Convert.ToInt32(Console.ReadLine()); var details = b.CheckIn(ID); Console.WriteLine("RoomNo: {0}", details); } catch (BookingException ex) { Console.WriteLine(ex.Message); } break; case "5": Console.Write("Enter Room No:"); var roomNo = Convert.ToInt32(Console.ReadLine()); b.CheckOut(roomNo); Console.WriteLine("RoomNo: {0} successfully checked out.", roomNo); break; case "6": return; default: break; } } }