public ActionResult Book(SearchRoomViewModel srm) { Session["start"] = DateTime.Now.ToString(); ReservationDetailViewModel rvm = new ReservationDetailViewModel(); rvm.checkIn = srm.checkIn; rvm.checkOut = srm.checkOut; rvm.nights = BizLogic.Utilities.calculateNight(srm.checkIn, srm.checkOut); rvm.roomId = srm.roomId; rvm.listPrice = srm.listPrice; using (var roomcontext = new DataModel.HotelDatabaseContainer()) { var room = roomcontext.RoomTypes.Find(rvm.roomId); rvm.roomType = room.type; rvm.roomGuest = room.maxGuests; } // Check if user is login Person p = getPersonByEmail(); if (p != null) { rvm.firstName = p.firstName; rvm.lastName = p.lastName; rvm.email = p.email; rvm.phone = p.phone; rvm.address = p.address; rvm.city = p.city; rvm.state = p.state; rvm.zip = p.zip; } return(View(rvm)); }
public IActionResult Index() { var model = new SearchRoomViewModel(_context) { // Filter values isUsingTodaysRooms = false, StartDate = DateTime.Today.AddDays(1).AddHours(16), EndDate = DateTime.Today.AddDays(2).AddHours(12), Capacity = null, NumberOfRooms = null, PriceOfRooms = null, // Values for the dropdown lists. ChainSelected = null, CategorySelected = null, StateSelected = null }; return(View(model)); }
public SearchRoomView() { InitializeComponent(); BindingContext = new SearchRoomViewModel(); }
public ActionResult Search(DateTime?Arrival, DateTime?Departure) { if (!Arrival.HasValue) { Arrival = DateTime.Now; } if (!Departure.HasValue) { Departure = DateTime.Now.AddDays(1); } SearchRoomViewModel srm = new SearchRoomViewModel(); srm.checkIn = Arrival.Value; srm.checkOut = Departure.Value; srm.nights = BizLogic.Utilities.calculateNight(Arrival.Value, Departure.Value); srm.roomTypes = new List <RoomType>(); srm.listPrices = new List <List <double> >(); // Find User Preference Room if (User.Identity.IsAuthenticated) { using (var context = new DataModel.HotelDatabaseContainer()) { srm.prefRoom = context.RoomTypes.First().Id; if (!User.IsInRole("Staff")) //Is Customer { Customer c = context.Customers.Find(getPersonByEmail().Id); //If Customer has Room Preference if (c.RoomPref != null) { srm.prefRoom = c.RoomPref.Id; } } } } // Find available rooms List <RoomType> roomTypes = new List <RoomType>(); using (var roomtypecontext = new DataModel.HotelDatabaseContainer()) { roomTypes = roomtypecontext.RoomTypes.ToList(); } for (int i = 0; i < roomTypes.Count; i++) { Boolean available = true; List <double> listPrice = new List <double>(); int roomId = roomTypes[i].Id; int roomNum = roomTypes[i].numberOfRooms; double baseprice = roomTypes[i].basePrice; for (int j = 0; j < srm.nights.Count; j++) { DateTime date = srm.nights[j].AddDays(1); double price = 0; using (var availableContext = new DataModel.HotelDatabaseContainer()) { var sqlstring = "SELECT COUNT(*) FROM dbo.Reservations WHERE dbo.Reservations.RoomTypeId = " + roomId + " AND dbo.Reservations.checkIn < '" + date + "' AND dbo.Reservations.checkOut >= '" + date + "'"; int reserved = availableContext.Database.SqlQuery <int>(sqlstring).First(); if (reserved == roomNum) { // if not available, exit check loop available = false; break; } else { // if available, calculate price for each day double percentage = (double)reserved / roomNum; if (percentage >= 0.75) { price = baseprice * 2; } else if (0.75 > percentage && percentage >= 0.5) { price = baseprice * 1.5; } else { price = baseprice * 1; } listPrice.Add(price); } } } if (available) { srm.roomTypes.Add(roomTypes[i]); srm.listPrices.Add(listPrice); } } return(View(srm)); }
public IActionResult Index(SearchRoomViewModel model) { DBManipulation db = new DBManipulation(_context); List <int> RoomsToExclude = new List <int>(); string qry = ""; DateTime s = model.StartDate.Date.AddHours(16); DateTime e = model.EndDate.Date.AddHours(12); model.Rooms = new List <Room>(); model.initModel(_context); if (!ModelState.IsValid) { return(View(model)); } if (!(DateTime.Compare(s, DateTime.Now) > 0)) { ModelState.AddModelError("StartDate", "The start date must be greater than today."); return(View(model)); } if (!(DateTime.Compare(e, DateTime.Now) > 0)) { ModelState.AddModelError("EndDate", "The end date must be greater than today."); return(View(model)); } else if (!(DateTime.Compare(e, model.StartDate) > 0)) { ModelState.AddModelError("EndDate", "The end date must be greater (by at least 1 day) than the start date."); return(View(model)); } if (!model.isUsingTodaysRooms) { qry += "SELECT rid, room_num, room.hid, price, capacity, isExtandable, landscape FROM eHotel.room INNER JOIN eHotel.hotel ON room.hid = hotel.hid WHERE 0=0"; List <Booking> Bookings = db.getBookingsByDates(s, e); if (Bookings.Count > 0) { foreach (Booking b in Bookings) { RoomsToExclude.Add(b.Rid); } } List <Renting> Rentings = db.getRentingsByDates(s, e); if (Rentings.Count > 0) { foreach (Renting r in Rentings) { RoomsToExclude.Add(r.Rid); } } if (model.ChainSelected != null) { qry += " AND hotel.hcid = " + model.ChainSelected; } if (model.Capacity != null) { qry += " AND capacity >= " + model.Capacity; } if (model.CategorySelected != null) { qry += " AND category = " + model.CategorySelected; } if (model.StateSelected != null) { qry += " AND h_state = '" + model.StateSelected + "'"; } if (model.NumberOfRooms != null) { qry += " AND num_rooms >= " + model.NumberOfRooms; } if (model.PriceOfRooms != null) { qry += " AND price <= " + model.PriceOfRooms; } if (RoomsToExclude.Count > 0) { bool first = true; qry += " AND rid NOT IN ("; foreach (int r in RoomsToExclude) { if (first) { qry += r; first = false; } else { qry += ", " + r; } } qry += ")"; } model.Rooms = db.getRoomForSearch(qry); return(View(model)); } TempData["StatusMessage"] = "Exactly " + model.Rooms.Count.ToString() + " have been loaded."; return(View(model)); }