public void Can_Paginate() { Mock <IHotelRepository> mock = new Mock <IHotelRepository>(); mock.Setup(m => m.Hotels).Returns(new Hotel[] { new Hotel { HotelID = 1, NameHotel = "P1" }, new Hotel { HotelID = 2, NameHotel = "P2" }, new Hotel { HotelID = 3, NameHotel = "P3" }, new Hotel { HotelID = 4, NameHotel = "P4" }, new Hotel { HotelID = 5, NameHotel = "P5" }, }); HotelController controller = new HotelController(mock.Object); controller.PageSize = 3; HotelListViewModel result = (HotelListViewModel)controller.List(null, 2).Model; Hotel[] prodArray = result.Hotels.ToArray(); Assert.IsTrue(prodArray.Length == 2); Assert.AreEqual(prodArray[0].NameHotel, "P4"); Assert.AreEqual(prodArray[1].NameHotel, "P5"); }
public IActionResult Index() { var OnlineUser = _userManager.GetUserAsync(HttpContext.User).Result; if (OnlineUser != null && _userManager.IsInRoleAsync(OnlineUser, "Manager").Result) { var hotel = _repository.GetHotelByManagerId(OnlineUser.Id, true); var facilities = _context.HotelFacilities.FirstOrDefault(p => p.Hotel.HotelId == hotel.HotelId); if (hotel != null) { var model = new HotelListViewModel() { HotelId = hotel.HotelId, HotelName = hotel.HotelName, HotelCity = hotel.HotelCity, NoOfFloors = hotel.NoOfFloors, NoOfRooms = hotel.NoOfRooms, Address = hotel.Address, Description = hotel.Description, FreeWifi = facilities.FreeWifi, Dinner = facilities.Dinner, Laundry = facilities.Laundry, Lunch = facilities.Lunch, AttachedWashrooms = facilities.AttachedWashrooms, Receptionservices = facilities.Receptionservices, CarParking = facilities.CarParking }; return(PartialView(model)); } } return(PartialView()); }
public async Task <IViewComponentResult> InvokeAsync() { HotelListViewModel model = null; List <HotelListViewModel> list = new List <HotelListViewModel>(); var hotels = _context.hotels.Where(p => p.HotelCity == "Lahore" || p.HotelCity == "Karachi" || p.HotelCity == "Peshawer" || p.HotelCity == "Mardan" || p.HotelCity == "Hyderabad" || p.HotelCity == "Sialkot" || p.HotelCity == "FaisalAbad" || p.HotelCity == "Rawalpindi" || p.HotelCity == "Nawshehra" || p.HotelCity == "Islamabad") .ToList(); if (hotels == null) { } foreach (var hotel in hotels) { model = new HotelListViewModel() { HotelName = hotel.HotelName, HotelCity = hotel.HotelCity, NoOfRooms = hotel.NoOfRooms, HotelImage = hotel.HotelImage }; list.Add(model); } return(View(list)); }
public ActionResult Index(HotelSearchViewModel model = null, string username = null) { var Now = DateTime.Now; Session["CheckInDate"] = Now.AddDays(1); Session["CheckOutDate"] = Now.AddDays(2); if (model != null && model.BeginDate >= DateTime.Now) { Session["CheckInDate"] = model.BeginDate; Session["CheckOutDate"] = model.EndDate; } var result = new HotelListViewModel().GetHotels(model); ViewBag.HotelList = result; // var a = new FacilityModel().SelectListItems; ViewBag.Facility = new FacilityModel().SelectListItems; ViewBag.Scenic = new ScenicModel().SelectListItems; var City = new Caches().TWCity; SelectList selectList = new SelectList(City, "ID", "Name", 0); ViewBag.City = selectList; return(View()); }
public ActionResult List(string urlparam) { if (GuidChecker.IsGuid(urlparam)) { return(RedirectPermanent("/")); } List <Hotel> hotels = ReturnHotelList(urlparam); HotelListViewModel tourListViewModel = new HotelListViewModel(); tourListViewModel.Menu = menu.ReturnMenuTours(); tourListViewModel.Hotels = hotels; tourListViewModel.MenuBlogGroups = menu.ReturnBlogGroups(); tourListViewModel.HotelCategory = db.HotelCategories.Include(current => current.Parent) .FirstOrDefault(current => current.UrlParam == urlparam); tourListViewModel.Footer = menu.ReturnFooter(); ViewBag.Canonical = "https://www.bektashtravel.com/hotel/" + urlparam; tourListViewModel.SidebarVisaList = GetSideBarVisaList(); tourListViewModel.SidebarTourCategories = GetSideBarTourCategory(); if (hotels == null) { return(RedirectPermanent("/hotel")); } return(View(tourListViewModel)); }
public IActionResult HotelDetailList(int id) { var model = new HotelListViewModel(); var hotel = _repository.GetHotelById(id, true); if (hotel == null) { } model.HotelId = hotel.HotelId; model.HotelName = hotel.HotelName; model.NoOfFloors = hotel.NoOfFloors; model.NoOfRooms = hotel.NoOfRooms; model.HotelCity = hotel.HotelCity; model.Address = hotel.Address; model.Description = hotel.Description; //model.Manager = hotel.AppUser.FirstName + hotel.AppUser.LastName; return(View(model)); }
public async Task <IActionResult> All(int id = 1) { if (id <= 0) { return(this.NotFound()); } const int itemPerPage = 6; var user = await this.userManager.GetUserAsync(this.User); var viewModel = new HotelListViewModel { Hotels = this.hotelService.GetAll(id, user.Id, itemPerPage), ItemPerPage = itemPerPage, PageNumber = id, ItemsCount = this.hotelService.GetCount(), }; return(this.View(viewModel)); }
public ViewResult List(string city, int page = 1) { HotelListViewModel model = new HotelListViewModel() { Hotel = repository.Hotel .Where(h => city == null || h.City == city) .OrderBy(hotel => hotel.HotelID) .Skip((page - 1) * pageSize) .Take(pageSize), PagingInfo = new PagingInfo { CurrentPage = page, ItemsPerPage = pageSize, TotalItems = city == null? repository.Hotel.Count() : repository.Hotel.Where(hotel => hotel.City == city).Count() }, CurrentType = city }; return(View(model)); }
public ViewResult List(string category, int page = 1) { HotelListViewModel viewModel = new HotelListViewModel { Hotels = repository.Hotels .Where(p => category == null || p.City == category) .OrderBy(p => p.HotelID) .Skip((page - 1) * PageSize) .Take(PageSize), PagingInfo = new PagingInfo { CurrentPage = page, ItemsPerPage = PageSize, TotalItems = category == null? repository.Hotels.Count() : repository.Hotels.Where(e => e.City == category).Count() }, CurrentCategory = category }; return(View(viewModel)); }
public IActionResult Index() { var model = new HotelListViewModel(); var OnlineUser = _userManager.GetUserAsync(HttpContext.User).Result; if (OnlineUser != null && _userManager.IsInRoleAsync(OnlineUser, "Manager").Result) { var hotel = _repository.GetHotelByManagerId(OnlineUser.Id, true); var facilities = _context.HotelFacilities.Include(p => p.Hotel) .FirstOrDefault(p => p.Hotel.HotelId == hotel.HotelId); if (hotel != null) { model.HotelId = hotel.HotelId; model.HotelName = hotel.HotelName; model.NoOfFloors = hotel.NoOfFloors; model.NoOfRooms = hotel.NoOfRooms; model.HotelCity = hotel.HotelCity; model.Address = hotel.Address; model.HotelImage = hotel.HotelImage; model.Description = hotel.Description; if (facilities != null) { model.FreeWifi = facilities.FreeWifi; model.Dinner = facilities.Dinner; model.Lunch = facilities.Lunch; model.BreckFast = facilities.BreckFast; model.Receptionservices = facilities.Receptionservices; model.AttachedWashrooms = facilities.AttachedWashrooms; model.CarParking = facilities.CarParking; model.Laundry = facilities.Laundry; } model.Manager = hotel.AppUser.FirstName + hotel.AppUser.LastName; } } return(View(model)); }
public void Can_Send_Pagination_View_Model() { Mock <IHotelRepository> mock = new Mock <IHotelRepository>(); mock.Setup(m => m.Hotels).Returns(new Hotel[] { new Hotel { HotelID = 1, NameHotel = "P1" }, new Hotel { HotelID = 2, NameHotel = "P2" }, new Hotel { HotelID = 3, NameHotel = "P3" }, new Hotel { HotelID = 4, NameHotel = "P4" }, new Hotel { HotelID = 5, NameHotel = "P5" }, }); HotelController controller = new HotelController(mock.Object); controller.PageSize = 3; HotelListViewModel result = (HotelListViewModel)controller.List(null, 2).Model; PagingInfo pageInfo = result.PagingInfo; Assert.AreEqual(pageInfo.CurrentPage, 2); Assert.AreEqual(pageInfo.ItemsPerPage, 3); Assert.AreEqual(pageInfo.TotalItems, 5); Assert.AreEqual(pageInfo.TotalPages, 2); }
public IActionResult Index(HotelListViewModel model) { bool Status = false; string Message = string.Empty; var hotel = _repository.HotelById(model.HotelId); var facilities = _context.HotelFacilities.FirstOrDefault(p => p.Hotel.HotelId == hotel.HotelId); if (ModelState.IsValid) { hotel.HotelName = model.HotelName; hotel.HotelId = model.HotelId; hotel.HotelCity = model.HotelCity; hotel.NoOfFloors = model.NoOfFloors; hotel.NoOfRooms = model.NoOfRooms; hotel.Address = model.Address; hotel.Description = model.Description; _repository.Update(hotel); if (_repository.SaveChange()) { if (facilities == null) { var hotelfacility = new HotelFacilities() { FreeWifi = model.FreeWifi, Dinner = model.Dinner, CarParking = model.CarParking, AttachedWashrooms = model.AttachedWashrooms, Receptionservices = model.Receptionservices, Laundry = model.Laundry, Lunch = model.Lunch, BreckFast = model.BreckFast, }; _context.Add(hotelfacility); _context.SaveChanges(); } else { facilities.FreeWifi = model.FreeWifi; facilities.Dinner = model.Dinner; facilities.CarParking = model.CarParking; facilities.AttachedWashrooms = model.AttachedWashrooms; facilities.Receptionservices = model.Receptionservices; facilities.Laundry = model.Laundry; facilities.Lunch = model.Lunch; facilities.BreckFast = model.BreckFast; _context.Update(facilities); _context.SaveChanges(); } return(RedirectToAction("Index", new { area = "Manager", controller = "HotelProfile" })); } else { Status = false; Message = "Error inserting /Creating Course"; } } else { ModelState.AddModelError("", "invalid / incomplete data"); } return(Json(new { status = Status, message = Message })); }
public IActionResult Search(HotelSerachViewModel model) { DateTime TempchkIn = new DateTime(); DateTime TempchkOut = new DateTime(); var hotelList = new List <HotelListViewModel>(); HotelListViewModel hotelModel = null; List <Hotel> SearchHotels = new List <Hotel>(); HotelRoomType RoomType = new HotelRoomType(); int RoomCount = 0; // filtered Hotel by Hotel City And RoomType if (model.City != null && model.RoomTypeId > 0 && model.checkOut == null && model.checkIn == null) { SearchHotels = _filterHotelByCityAndRoomType. GetHotelByCityAndRoomType(model.City, model.checkIn, model.checkOut); RoomType = RoomTypeById(model.RoomTypeId); } // Filtered Hotel by Price and StarRating else if (model.Price > 0 && model.StarRatingid > 0) { SearchHotels = _filterHotelByPriceAndHotelRatings. GetHotelByPriceAndHotelRatings(model.City, model.Price, model.StarRatingid, model.checkIn, model.checkOut); RoomType = RoomTypeById(model.hotelRoomTypeId); } // Filtered Hotel By HotelPrice else if (model.Price > 0 && model.StarRatingid == 0) { SearchHotels = _filterHotelByPrice. GetHotelByPrice(model.City, model.Price, model.checkIn, model.checkOut); RoomType = RoomTypeById(model.hotelRoomTypeId); } //Filtered Hotel By StarRating else if (model.Price == 0 && model.StarRatingid > 0) { SearchHotels = _filterHotelByHotelRatings. GetHotelByHotelRatings(model.City, model.StarRatingid , model.checkIn, model.checkOut); RoomType = RoomTypeById(model.hotelRoomTypeId); } //Filtered Hotel By Main Search Engine else if (model.City != null && model.checkIn != null && model.checkOut != null && model.RoomTypeId > 0) { SearchHotels = _hotelNetworkMainSearchEngine. GetHotelBySearchEngine(model.City, model.checkIn, model.checkOut); RoomType = RoomTypeById(model.RoomTypeId); TempchkIn = model.checkIn; TempchkOut = model.checkOut; } foreach (var hotel in SearchHotels) { var Rooms = _context.hotelRooms .Where(p => p.Hotel.HotelId == hotel.HotelId) .Where(p => p.HotelRoomType.HotelRoomTypeId == RoomType.HotelRoomTypeId).ToList(); if (Rooms != null) { foreach (var room in Rooms) { if (room.IsBooked == false) { RoomCount++; } else if (room.IsBooked == true) { if (_checkOutCheckInImplmentation. Check(room.HotelRoomId, model.checkIn, model.checkOut) == true) { RoomCount++; } } } } var Averagereview = _context.hotelReviews. Include(p => p.hotel).Where(p => p.hotel.HotelId == hotel.HotelId).ToList(); if (Averagereview != null) { for (int review = 0; review < Averagereview.Count; review++) { TotalStar = TotalStar + Averagereview[review].ReviewStar; } AverageStar = TotalStar / Averagereview.Count; } var RoomPrice = _context.hotelRooms. Include(p => p.Hotel).Where(p => p.Hotel.HotelId == hotel.HotelId).ToList(); if (RoomPrice != null) { for (int price = 0; price < RoomPrice.Count; price++) { TotalPrice = TotalPrice + RoomPrice[price].RsPernight; } Averageprice = TotalPrice / (RoomPrice.Count); } if (RoomCount > 0) { hotelModel = new HotelListViewModel() { HotelName = hotel.HotelName, HotelCity = model.City, NoOfRoomsFree = RoomCount, HotelImage = hotel.HotelImage, HotelId = hotel.HotelId, ReviewStar = AverageStar, AveragePrice = Averageprice, TotalReview = Averagereview.Count, hotelRoomtype = RoomType.RoomType, HotelRoomTypeId = RoomType.HotelRoomTypeId, }; if (TempchkIn != null && TempchkOut != null) { hotelModel.CheckIn = TempchkIn; hotelModel.CheckOut = TempchkOut; } hotelList.Add(hotelModel); AverageStar = 0; Averageprice = 0; TotalPrice = 0; TotalStar = 0; RoomCount = 0; } } return(View(hotelList)); }