/*------------------------------------------------END OF Deleting the City------------------------------------------------*/ //Returning a boolean value to AdminController received from DataAccessLayer based on successful addition of a Hotel public bool AddHotel(CityHotelDetailsFromAdmin hotel) { bool result = adminUpgrades.AddHotel(hotel); if (result) { return(true); } else { return(false); } }
public void Admin_AddHotel_NullValuePassing() { //Arrange AdminController adminController = new AdminController() { Request = new HttpRequestMessage() { Properties = { { HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration() } } } }; CityHotelDetailsFromAdmin hotel = new CityHotelDetailsFromAdmin(); //Act var response = adminController.AddHotel(hotel); //Assert Assert.AreEqual(HttpStatusCode.Conflict, response.StatusCode); }
public HttpResponseMessage AddHotel(CityHotelDetailsFromAdmin hotel) { if (hotel.hotelName == null || hotel.cityName == null || hotel.hotelAddress == null || hotel.hotelRating == 0 || (hotel.numberOfDoubleRooms == 0 && hotel.numberOfSingleRooms == 0) || (hotel.priceOfDoubleRoom == 0 && hotel.priceOfSingleRoom == 0)) { throw new ArgumentNullException("Hotel Details cannot be Null"); } try { bool result = adminManager.AddHotel(hotel); if (result) { return(Request.CreateErrorResponse(HttpStatusCode.Created, "Hotel Added Successfully")); } else { return(Request.CreateErrorResponse(HttpStatusCode.NotAcceptable, "Hotel Cannot be added")); } } catch { throw new DivideByZeroException("Internal Server Error!"); } }
public void Admin_AddHotel_WrongDetails() { //Arrange AdminController adminController = new AdminController() { Request = new HttpRequestMessage() { Properties = { { HttpPropertyKeys.HttpConfigurationKey, new HttpConfiguration() } } } }; CityHotelDetailsFromAdmin hotel = new CityHotelDetailsFromAdmin(); hotel.cityId = 34; hotel.hotelName = "Izzy Cozy Hotel"; hotel.hotelAddress = "143, Patia Road, Near Big Baazar"; hotel.totalRooms = 5; //Act var response = adminController.AddHotel(hotel); //Assert Assert.AreEqual(HttpStatusCode.Conflict, response.StatusCode); }
/*------------------------------------------------END OF Deleting the City------------------------------------------------*/ // CRUD on Hotel Table //Adding Hotel in the hotelDetails Table public bool AddHotel(CityHotelDetailsFromAdmin hotel) { CityDetails cityDetails = new CityDetails(); cityDetails.cityName = hotel.cityName; HotelDetails hotelDetails = new HotelDetails(); hotelDetails.hotelName = hotel.hotelName; hotelDetails.hotelAddress = hotel.hotelAddress; hotelDetails.doubleRooms = hotel.numberOfDoubleRooms; hotelDetails.starRating = hotel.hotelRating; hotelDetails.singleRooms = hotel.numberOfSingleRooms; RoomDetails roomDetails = new RoomDetails(); if (CheckCityIfExists(cityDetails.cityName)) { if (!AddCity(cityDetails)) { return(false); } } int cityId = dbContext.cityDetails.Where(y => y.cityName == cityDetails.cityName).Select(y => y.cityId).FirstOrDefault(); if (CheckHotelIfExists(hotelDetails.hotelName, cityId)) { dbContext.hotelDetails.Add(hotelDetails); dbContext.SaveChanges(); int hotelId = FindTheAppropriateHotelId(hotel.hotelName); //Calling a different function to map Hotel and City Id if (!CityIdHotelIdUpdate(cityId, hotelId)) { return(false); } //Starting to add rooms for (int i = 1; i <= hotel.numberOfSingleRooms; i++) { roomDetails.hotelId = hotelId; roomDetails.roomType = "Single"; roomDetails.price = hotel.priceOfSingleRoom; if (!AddRoom(roomDetails)) { return(false); } } for (int i = 1; i <= hotel.numberOfDoubleRooms; i++) { roomDetails.hotelId = hotelId; roomDetails.roomType = "Double"; roomDetails.price = hotel.priceOfDoubleRoom; if (!AddRoom(roomDetails)) { return(false); } } return(true); } else { return(false); } }