public IHttpActionResult PutHotelFacility(int id, HotelFacility hotelFacility) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != hotelFacility.HF_Id) { return(BadRequest()); } db.Entry(hotelFacility).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!HotelFacilityExists(id)) { return(NotFound()); } else { throw; } } return(StatusCode(HttpStatusCode.NoContent)); }
public HotelFacility Create(HotelFacility hotelfacility) { if (hotelfacility.HotelId == 0) { throw new AppException("HotelId is required"); } if (hotelfacility.FacilityId == 0) { throw new AppException("FacilityId is required"); } Hotel hotelChecker = _hotelFacilityRepository.FindHotel(hotelfacility.HotelId); Facility facilityChecker = _hotelFacilityRepository.FindFacility(hotelfacility.FacilityId); if (hotelChecker == null) { throw new AppException("Hotel is not Existing! Add existing HotelId"); } if (facilityChecker == null) { throw new AppException("Facility is not Existing! Add existing FacilityId"); } _hotelFacilityRepository.HotelFacilities.Add(hotelfacility); _hotelFacilityRepository.Save(); return(hotelfacility); }
public void TestGetHotelFacilityGroup_ListOfFacility() { //Arrange int id = 1; var hotelFacility = new HotelFacility() { Id = id, FacilityGroupId = 1, Name = "facility1", IsActive = true, IsDeleted = false }; var baseResult = new BaseResult <List <HotelFacility> >() { Result = new List <HotelFacility>() { hotelFacility } }; var pred = new Func <HotelFacility, bool>(x => x.IsActive && !x.IsDeleted); iHotelFacilityLibrary.Setup(a => a.GetListByPredicate(It.Is <Func <HotelFacility, bool> >(x => x.GetType() == pred.GetType()))).Returns(Task.FromResult(new BaseResult <List <HotelFacility> > { })); //Act var facilityList = facilitiesRepository.GeHotelFacility(); //Assert Assert.IsTrue(facilityList != null); Assert.IsTrue(facilityList.Result is BaseResult <List <HotelFacility> >); //Assert.IsTrue(facilityList.Result.Result.Exists(x => x.Id == id)); }
public ActionResult DeleteConfirmed(int id) { HotelFacility hotelFacility = db.HotelFacilities.Find(id); db.HotelFacilities.Remove(hotelFacility); db.SaveChanges(); return(RedirectToAction("Index")); }
public void Delete(int hotelId, int facilityId) { HotelFacility hotelFacility = _hotelFacilityRepository.FindHotelFacility(hotelId, facilityId); if (hotelFacility != null) { _hotelFacilityRepository.HotelFacilities.Remove(hotelFacility); _hotelFacilityRepository.Save(); } }
public void DeleteHotelFacility(int hotelId, int facilityId) { var hotel = _appDbContext.Hotels.SingleOrDefault(x => x.Id == hotelId); var facility = _appDbContext.Facilities.SingleOrDefault(x => x.Id == facilityId); HotelFacility hotelFacility = new HotelFacility { Facility = facility, Hotel = hotel, FacilityId = facilityId, HotelId = hotelId }; _appDbContext.HotelFacilities.Remove(hotelFacility); _appDbContext.SaveChanges(); }
public IHttpActionResult GetHotelFacility(int id) { HotelFacility hotelFacility = db.HotelFacilities.Find(id); if (hotelFacility == null) { return(NotFound()); } return(Ok(hotelFacility)); }
public ActionResult Edit([Bind(Include = "Id,Facility,HotelId")] HotelFacility hotelFacility) { if (ModelState.IsValid) { db.Entry(hotelFacility).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.HotelId = new SelectList(db.Hotels, "Id", "HotelName", hotelFacility.HotelId); return(View(hotelFacility)); }
public List <String> GetData(HotelFacility entity) { var list = new List <String>(); list.Add(entity.TitleEn.ToString()); list.Add(entity.SubtitleEn?.ToString()); list.Add(entity.TextEn?.ToString()); list.Add(entity.TitleImagePath?.ToString()); list.Add(entity.DateAdded.ToString()); return(list); }
public void Save(HotelFacility entity) { if (entity.Id == default) { context.Entry(entity).State = EntityState.Added; } else { context.Entry(entity).State = EntityState.Modified; } context.SaveChanges(); }
public IHttpActionResult PostHotelFacility(HotelFacility hotelFacility) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.HotelFacilities.Add(hotelFacility); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = hotelFacility.HF_Id }, hotelFacility)); }
public ActionResult Create([Bind(Include = "Id,Facility,HotelId")] HotelFacility hotelFacility) { if (ModelState.IsValid) { db.HotelFacilities.Add(hotelFacility); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.HotelId = new SelectList(db.Hotels, "Id", "HotelName", hotelFacility.HotelId); return(View(hotelFacility)); }
public IHttpActionResult DeleteHotelFacility(int id) { HotelFacility hotelFacility = db.HotelFacilities.Find(id); if (hotelFacility == null) { return(NotFound()); } db.HotelFacilities.Remove(hotelFacility); db.SaveChanges(); return(Ok(hotelFacility)); }
// GET: HotelFacilities/Details/5 public ActionResult Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } HotelFacility hotelFacility = db.HotelFacilities.Find(id); if (hotelFacility == null) { return(HttpNotFound()); } return(View(hotelFacility)); }
private void button2_Click(object sender, EventArgs e) { HotelFacility facility = new HotelFacility() { category = metroComboBox2.Text, item = metroTextBox6.Text, description = metroTextBox4.Text, price = metroTextBox5.Text }; data.HotelFacilities.Add(facility); data.SaveChanges(); MessageBox.Show("Facility Submitted"); data_Load(); }
// GET: HotelFacilities/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } HotelFacility hotelFacility = db.HotelFacilities.Find(id); if (hotelFacility == null) { return(HttpNotFound()); } ViewBag.HotelId = new SelectList(db.Hotels, "Id", "HotelName", hotelFacility.HotelId); return(View(hotelFacility)); }
public async Task <IActionResult> Create([Bind("HotelId,FacilityId")] HotelFacility hotelFacility) { var isHotelAndFacilitiesExists = _context.HotelFacilities .Any(h => h.HotelId == hotelFacility.HotelId && h.FacilityId == hotelFacility.FacilityId); if (ModelState.IsValid && !isHotelAndFacilitiesExists) { _context.Add(hotelFacility); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["FacilityId"] = new SelectList(_context.Facilities, "FacilityId", "Name", hotelFacility.FacilityId); ViewData["HotelId"] = new SelectList(_context.Hotels, "HotelId", "Name", hotelFacility.HotelId); ViewData["Duplicate"] = true; return(View(hotelFacility)); }
public IActionResult Edit(HotelFacility model, IFormFile titleImageFile, string defaultImagePath) { if (ModelState.IsValid) { if (titleImageFile != null) { model.TitleImagePath = "images/hotelFacilities/" + titleImageFile.FileName; using (var stream = new FileStream(Path.Combine(hostEnvironment.WebRootPath, model.TitleImagePath), FileMode.Create)) { titleImageFile.CopyTo(stream); } } else { model.TitleImagePath = defaultImagePath; } dataManager.HotelFacilities.Save(model); return(RedirectToAction("Read", "Home")); } return(View(model)); }
public static async Task Initialize(IServiceProvider serviceProvider) { //dbContext.Database.EnsureDeleted(); using var dbContext = new ApplicationDbContext(serviceProvider.GetRequiredService <DbContextOptions <ApplicationDbContext> >()); await dbContext.Database.EnsureCreatedAsync(); try { if (dbContext.Database.GetPendingMigrations().Count() > 0) { dbContext.Database.Migrate(); } } catch (Exception) { } if (!dbContext.Hotels.Any()) { var hotels = new Hotel[] { new Hotel { Name = "Ritz Hotel Paris", Website = "https://www.ritzparis.com/en-GB", Address = "15 Place Vendôme", ZipCode = "75001", City = "Paris", Country = "France", Description = "Located in Paris, 500 m from Opéra Garnier, Ritz Paris features a selection of bars and restaurants, a garden and a business centre.", Stars = 5, DistanceFromCenter = 6.3, Latitude = "48.868164", Longitude = "2.328888", ImageUrl = "~/pictures/ritz.jpg" }, new Hotel { Name = "Corinthia Hotel London", Website = "https://www.corinthia.com/london/", Address = "Whitehall Place", ZipCode = "SW1A 2BD", City = "London", Country = "United Kingdom", Description = "The luxurious Corinthia Hotel is located in one of London’s most prestigious areas, moments from Trafalgar Square and Whitehall. It features elegant restaurants, 2 bars, a florist and the world's first hotel concession for Harrods.", Stars = 5, DistanceFromCenter = 1.6, Latitude = "51.506753", Longitude = "-0.124422", ImageUrl = "~/pictures/corinthia.jpg" }, new Hotel { Name = "Eden Hotel Amsterdam", Website = "https://www.edenhotelamsterdam.com/en/", Address = "Amstelstraat 17", ZipCode = "1017 DA", City = "Amsterdam", Country = "Netherlands", Description = "Located in the heart of the city center, Eden Hotel Amsterdam offers warm-colored rooms. The famous Rembrandt Square is right around the corner. The central station is 10 minutes away by tram.", Stars = 4, DistanceFromCenter = 0.9, Latitude = "52.366983", Longitude = "4.898774", ImageUrl = "~/pictures/eden.jpg" }, new Hotel { Name = "Paris France Hotel", Website = "https://www.paris-france-hotel.com/", Address = "72 Rue De Turbigo", ZipCode = "75003", City = "Paris", Country = "France", Description = "Built in 1910 during the Belle Epoque period, this hotel is in a great location in central Paris, with easy access to the city’s tourist attractions.", Stars = 3, DistanceFromCenter = 3.1, Latitude = "48.866954", Longitude = "2.360468", ImageUrl = "~/pictures/france.jpg" }, new Hotel { Name = "Athenee Palace Hilton", Website = "https://www.hilton.com/en/hotels/buhhitw-athenee-palace-hilton-bucharest/", Address = "56 Calea Victoriei", ZipCode = "010083", City = "Bucharest", Country = "Romania", Description = "Centrally located on Victoriei Street in the heart of Bucharest, Grand Hotel Continental is steps away from the National Art Museum and close to the Athenaeum, Universitate Metro Station, and business district.", Stars = 5, DistanceFromCenter = 0.2, Latitude = "44.441230", Longitude = "26.095909", ImageUrl = "~/pictures/bucharest.jpg" }, new Hotel { Name = "Saint Ten Hotel", Website = "https://saintten.com/", Address = "Svetog Save 10", ZipCode = "11000", City = "Belgrade", Country = "Serbia", Description = "Set in the Vračar District of Belgrade, about 300 m from the Temple of St. Sava, the luxurious Saint Ten Hotel is housed in a cultural heritage building and offers an on-site restaurant.", Stars = 5, DistanceFromCenter = 1.9, Latitude = "44.801582", Longitude = "20.467130", ImageUrl = "~/pictures/belgrade.jpg" } }; dbContext.Hotels.AddRange(hotels); await dbContext.SaveChangesAsync(); } if (!dbContext.Facilities.Any()) { var facilities = new Facility[] { new Facility { Name = "Wi-fi", Symbol = "wifi" }, new Facility { Name = "Parking", Symbol = "parking" }, new Facility { Name = "Breakfast", Symbol = "utensils" }, new Facility { Name = "Room service", Symbol = "concierge-bell" }, new Facility { Name = "Fitness center", Symbol = "dumbbell" }, new Facility { Name = "Pool", Symbol = "swimming-pool" }, new Facility { Name = "Sauna", Symbol = "hot-tub" } }; dbContext.Facilities.AddRange(facilities); await dbContext.SaveChangesAsync(); } if (!dbContext.Rooms.Any()) { Random random = new Random(); int totalNumberOfRooms = 100; var roomsList = new List <Room>(); var numberOfHotels = dbContext.Hotels.Count(); var roomDescriptionArray = new[] { "A traditionally decorated room with a TV, tea and coffee-making facilities and a private shower.", "This double room is fully fitted with air-conditioning, flat screen TV, direct dial telephone, high-speed WiFi, hairdryer and a safe. The modern bathroom features a powerful shower.", "This room includes a satellite TV, tea and coffee-making facilities, a hairdryer and a private bathroom.", "This triple room has air conditioning, electric kettle, free wi-fi and hairdryer." }; var numberOfBedsArray = new[] { 1, 1, 2, 2 }; var capacityArray = new[] { 1, 2, 2, 3 }; var roomImagesArray = new[] { "~/pictures/single.jpg", "~/pictures/double.jpg", "~/pictures/twin.jpg", "~/pictures/triple.jpg", }; for (int i = 0; i < totalNumberOfRooms; i++) { var index = random.Next(Enum.GetNames(typeof(RoomType)).Length); var randomHotel = random.Next(1, numberOfHotels + 1); roomsList.Add(new Room { RoomType = (RoomType)index, RoomPrice = ((index + 1) * 200) + ((randomHotel + 1) * 50), RoomDescription = roomDescriptionArray[index], NumberOfBeds = numberOfBedsArray[index], Capacity = capacityArray[index], RoomImageUrl = roomImagesArray[index], HotelId = randomHotel }); } dbContext.Rooms.AddRange(roomsList); await dbContext.SaveChangesAsync(); } if (!dbContext.HotelFacilities.Any()) { var hotelFacilities = new HotelFacility[] { new HotelFacility { HotelId = 1, FacilityId = 1 }, new HotelFacility { HotelId = 1, FacilityId = 3 }, new HotelFacility { HotelId = 1, FacilityId = 5 }, new HotelFacility { HotelId = 1, FacilityId = 6 }, new HotelFacility { HotelId = 1, FacilityId = 7 }, new HotelFacility { HotelId = 2, FacilityId = 1 }, new HotelFacility { HotelId = 2, FacilityId = 2 }, new HotelFacility { HotelId = 2, FacilityId = 3 }, new HotelFacility { HotelId = 2, FacilityId = 6 }, new HotelFacility { HotelId = 2, FacilityId = 7 }, new HotelFacility { HotelId = 3, FacilityId = 1 }, new HotelFacility { HotelId = 3, FacilityId = 2 }, new HotelFacility { HotelId = 3, FacilityId = 3 }, new HotelFacility { HotelId = 3, FacilityId = 4 }, new HotelFacility { HotelId = 4, FacilityId = 1 }, new HotelFacility { HotelId = 4, FacilityId = 4 }, new HotelFacility { HotelId = 5, FacilityId = 1 }, new HotelFacility { HotelId = 5, FacilityId = 2 }, new HotelFacility { HotelId = 5, FacilityId = 3 }, new HotelFacility { HotelId = 6, FacilityId = 1 }, new HotelFacility { HotelId = 6, FacilityId = 5 }, new HotelFacility { HotelId = 6, FacilityId = 7 }, }; dbContext.HotelFacilities.AddRange(hotelFacilities); await dbContext.SaveChangesAsync(); } }