/// <summary> /// Searches and books for any available room that fit the criteria specified /// </summary> /// <param name="numBeds"></param> /// <param name="numPets"></param> /// <param name="needsAccessibility"></param> /// <returns></returns> public async Task <MotelRoom> BookAvailableRoomAsync(int numBeds, int numPets, bool needsAccessibility) { MotelRoom room = await FindRoomByProperties(numBeds, numPets, needsAccessibility); //if we get null here, the room is not available in the repository if (room == null) { throw new RoomBookingException($"Could not find available room that met the booking criteria"); } if (numPets > 0) { if (room.AllowsPets()) { room.AddPets(numPets); } else { throw new RoomBookingException($"Room {room.RoomNum} does now allow pets"); } } _repo.AddBookedRoom(room); room.TotalCost = CalculateCost(room); return(room); }
private float CalculateCost(MotelRoom room) { float bedCost = GetCostForBeds(room.NumBeds); //calculate cost per bed float petCost = GetCostForPets(room.NumPets); //calculate cost per pet return(bedCost + petCost); }
public async Task <MotelRoom> FindRoomByProperties(int numBeds, int numPets, bool needsAccessibility) { MotelRoom room = null; //if they are not in need of special accomodations, check the second floor first so that we can save //rooms on the first floor for those who need them if (numPets == 0 && !needsAccessibility) { //search for a free room on the second floor with the appropriate number of beds room = (await _repo.GetListOfAvailableRoomsAsync()).FirstOrDefault(r => r.Floor == 2 && r.NumBeds == numBeds ); } //if room is still empty at this point, they either need special accomodations or we coulnd't find a room //on the second floor if (room == null) { //search for a room that has the number of beds requred, allows pets, and is accessible if needed room = (await _repo.GetListOfAvailableRoomsAsync()).FirstOrDefault(r => r.NumBeds == numBeds && (numPets > 0 && r.AllowsPets() || numPets == 0) && (needsAccessibility && r.IsHandicapAccessible() || !needsAccessibility) ); } return(room); }
public async Task <MotelRoom> BookRoomAsync(int roomNum, int numPets, bool needsAccessibility) { MotelRoom room = await FindRoomByNumber(roomNum); //if we get null here, the room is not available in the repository if (room == null) { throw new RoomBookingException($"Room {roomNum} is not available for booking"); } if (needsAccessibility && !room.IsHandicapAccessible()) { throw new RoomBookingException($"Room {roomNum} is not handicap accessible"); } if (numPets > 0) { if (room.AllowsPets()) { room.AddPets(numPets); } else { throw new RoomBookingException($"Room {roomNum} does now allow pets"); } } _repo.AddBookedRoom(room); room.TotalCost = CalculateCost(room); return(room); }
/// <summary> /// Searches, then books a room based on requested beds, pet policy, and accessibility /// </summary> /// <param name="numBeds"></param> /// <param name="numPets"></param> /// <param name="needsAccessibility"></param> /// <returns>Task that represents the async call </returns> public async Task <MotelRoom> BookAvailableRoomAsync(int numBeds, int numPets, bool needsAccessibility) { MotelRoom room = await FindRoomByProperties(numBeds, numPets, needsAccessibility); if (room == null) { throw new Exception($"No available room that matched booking criteria"); } if (numPets > 0) { if (room.AllowsPets()) { room.AddPets(numPets); } else { throw new Exception($"Room {room.RoomNum} does now allow pets"); } } _repo.AddBookedRoom(room); room.TotalCost = CalculateCost(room); return(room); }
public async Task <MotelRoom> FindRoomByNumber(int roomNum) { MotelRoom room = null; room = (await _repo.GetListOfAvailableRoomsAsync()).FirstOrDefault(r => r.RoomNum == roomNum); return(room); }
public async Task Two_Bed_Two_Pets() { IMotelRoomsRepository repo = new MotelRoomsRepository(); BookingProcessor proc = new BookingProcessor(repo); MotelRoom room = await proc.BookAvailableRoomAsync(2, 2, false); Assert.AreEqual(room.TotalCost, 115); }
public static void Seed(this ModelBuilder builder) { var customer = new Customer { Address = "Ho Chi Minh", Birthdate = Convert.ToDateTime("11/12/1998"), Email = "*****@*****.**", FirstName = "Thuy", LastName = "Duong Thi Thu", Identification = "183218131", IDuser = "******", PhoneNumber = "0963902609", }; builder.Entity <Customer>().HasData(customer); var motel = new MotelRoom { Area = 123, BedRoom = 1, idMotel = 12, NameRoom = "Anthony's Room", Payment = 12, Status = true, Toilet = 1, }; builder.Entity <MotelRoom>().HasData(motel); var rent = new Rent { IdRent = "Test2", Start = DateTime.Today, }; builder.Entity <Rent>().HasData(rent); var bill = new InforBill() { ElectricBill = 1, IdInforBill = "test1", IdMotel = 12, MonthRent = 1, ParkingFee = 1, RoomBill = 1, WaterBill = 1, WifiBill = 1, }; builder.Entity <InforBill>().HasData(bill); }
public async Task <IActionResult> BookRoomByProperties(int numBeds, int numPets, bool needsAccessibility) { try { MotelRoom room = await _dataAdapter.BookAvailableRoomAsync(numBeds, numPets, needsAccessibility); return(Created("api/Booking/BookRoom", $"Successfully booked room {room.RoomNum}. Final cost is: {room.TotalCost}")); //return a 201 indicating the room was booked successfully } catch (Exception ex) { //just return 400 indicating there was an issue with the request they sent in return(BadRequest(ex.Message)); } }
// Create Room public async Task <int> Create(RoomRequest request) { var result = new MotelRoom() { Area = request.Area, BedRoom = request.BedRoom, NameRoom = request.NameRoom, Payment = request.Payment, Status = false, Toilet = request.Toilet }; _context.MotelRooms.Add(result); return(await _context.SaveChangesAsync()); }
public ActionResult AddRoom(FormCollection data) { List <Criterion> list = db.Criteria.ToList(); List <Criterion> listCriteria = new List <Criterion>(); foreach (var item in list) { var x = "criteria" + item.CriteriaID; if (data[x] != null) { listCriteria.Add(item); } var t = data[x]; } int? acreage = Convert.ToInt32(data["acreage"]); int? provinceID = Convert.ToInt32(data["province"]); int? districtID = Convert.ToInt32(data["district"]); int? maxPeople = Convert.ToInt32(data["maxPeople"]); int? wardID = Convert.ToInt32(data["ward"]); var motelName = data["motelName"]; MotelRoom house = new MotelRoom(); house.MotelName = motelName; house.Acreage = acreage; house.Price = CurrencyHelper.CurrencyToNumber(data["price"], '.'); house.ProvinceID = provinceID; house.DistrictID = districtID; house.MaxPeople = maxPeople; house.StatusID = 1; house.AccountID = (Session["account"] as Account).AccountID; house.Address = (data["addressRoom"]).ToString(); house.Criteria = listCriteria; house.WardID = wardID; db.MotelRooms.Add(house); db.SaveChanges(); return(RedirectToAction("AddRoom", "User")); }
public static SearchResult CreateSearchResult(int postID) { var acc = new Account(); var post = new Post(); var motel = new MotelRoom(); var info = new Info(); var province = new Province(); var district = new District(); var ward = new Ward(); List <int> listCriteria = new List <int>(); using (var db = new QLTroEntities()) { post = db.Posts.SingleOrDefault(p => p.PostID == postID); motel = db.MotelRooms.SingleOrDefault(p => p.MotelID == post.MotelID); info = db.Infoes.SingleOrDefault(p => p.AccountID.Equals(motel.AccountID)); acc = db.Accounts.SingleOrDefault(p => p.AccountID.Equals(motel.AccountID)); province = db.Provinces.SingleOrDefault(p => p.ProvinceID == motel.ProvinceID); district = db.Districts.SingleOrDefault(p => p.DistrictID == motel.DistrictID); ward = db.Wards.SingleOrDefault(p => p.WardID == motel.WardID); var list = db.MotelRooms.SingleOrDefault(p => p.MotelID == motel.MotelID).Criteria.ToList(); foreach (var item in list) { listCriteria.Add(item.CriteriaID); } } var searchResult = new SearchResult() { AccountID = motel.AccountID, AccountStatus = acc.AccountStatusID, PostID = post.PostID, PostTitle = post.PostTitle, PostDate = post.PostDate, PostView = post.PostView, MotelID = post.MotelID, Description = post.Description, PostStatus = post.PostStatus, Acreage = motel.Acreage, Price = motel.Price, ProvinceID = motel.ProvinceID, DistrictID = motel.DistrictID, WardID = motel.WardID, StatusID = motel.StatusID, Address = motel.Address, MaxPeople = motel.MaxPeople, ListCriteriaID = listCriteria, Name = info.Name, Sex = info.Sex, Birthday = info.Birthday, Phone = info.Phone, Email = info.Email, ProvinceName = province.ProvinceName, DistrictName = district.DistrictName, WardName = ward.WardName, Latitude = ward.Latitude, Longitude = ward.Longitude }; return(searchResult); }