public ActionResult DeleteConfirmed(int id) { Hotel_Data hotel_Data = db.Hotel_Data.Find(id); db.Hotel_Data.Remove(hotel_Data); db.SaveChanges(); return(RedirectToAction("Index")); }
public void JsonOneTests() { SerializeJsonProvider1 serjson = new SerializeJsonProvider1(); Hotel_Data rootObject = serjson.ReadJson(); Assert.IsNotNull(rootObject); }
public ActionResult Edit([Bind(Include = "hotel_id,hotel_name,hotel_description,hotel_email,hotel_latitude,hotel_longitude,hotel_price,hotel_address")] Hotel_Data hotel_Data) { if (ModelState.IsValid) { db.Entry(hotel_Data).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(hotel_Data)); }
public ActionResult Create([Bind(Include = "hotel_id,hotel_name,hotel_description,hotel_email,hotel_latitude,hotel_longitude,hotel_price,hotel_address")] Hotel_Data hotel_Data) { if (ModelState.IsValid) { db.Hotel_Data.Add(hotel_Data); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(hotel_Data)); }
public ActionResult Create([Bind(Include = "booking_id,booking_start_date,booking_end_date,user_id,hotel_id,booking_places")] BookingViewModel booking) { if (ModelState.IsValid) { try { Booking bk = new Booking(); bk.hotel_id = booking.hotel_id; bk.booking_places = (int)booking.booking_places; bk.booking_start_date = (System.DateTime)booking.booking_start_date; bk.booking_end_date = (System.DateTime)booking.booking_end_date; bk.user_id = User.Identity.GetUserId(); //booking.user_id; //Getting the hotel Hotel_Data hotel = dm.Hotel_Data.Find(booking.hotel_id); var newHotelCapacity = hotel.hotel_capacity - booking.booking_places; if (newHotelCapacity >= 0) { hotel.hotel_capacity = (int)newHotelCapacity; dm.SaveChanges(); db.Bookings.Add(bk); db.SaveChanges(); return(RedirectToAction("Index")); } else { var model = new BookingViewModel { hotelList = dm.Hotel_Data.Select(p => new SelectListItem { Text = p.hotel_name, Value = p.hotel_id.ToString() }).ToList() }; ViewBag.Failure = "Booking capacity reached for that hotel. please choose a different hotel."; return(View(model)); } } catch (Exception ex) { var model = new BookingViewModel { hotelList = dm.Hotel_Data.Select(p => new SelectListItem { Text = p.hotel_name, Value = p.hotel_id.ToString() }).ToList() }; ViewBag.Failure = "You already have a booking for that date. Please choose a different date."; return(View(model)); } } return(View()); }
// GET: Hotel_Data_/Edit/5 public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Hotel_Data hotel_Data = db.Hotel_Data.Find(id); if (hotel_Data == null) { return(HttpNotFound()); } return(View(hotel_Data)); }
//GET: Bookins/Rate public ActionResult Rate(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Hotel_Data hotel = dm.Hotel_Data.Find(id); /*Booking booking = db.Bookings.Find(id); * if (booking == null) * { * return HttpNotFound(); * }*/ return(View(hotel)); }
public ActionResult Rate(int?id, Hotel_Data hotel) { if (ModelState.IsValid) { if (hotel.hotel_rating != null) { //hotel.hotel_rating = 2; Hotel_Data hotel2 = dm.Hotel_Data.Find(id); var oldRating = hotel2.hotel_rating; var noOfRatings = hotel2.hotel_no_of_ratings; noOfRatings = noOfRatings + 1; // calculating the new rating var newRating = oldRating + ((hotel.hotel_rating - oldRating) / noOfRatings); hotel2.hotel_no_of_ratings = hotel2.hotel_no_of_ratings + 1; hotel2.hotel_rating = newRating; //f.Name = NewName; //myEntities.SaveChanges(); dm.SaveChanges(); db.SaveChanges(); /*db.Entry(booking).State = EntityState.Modified; * db.SaveChanges(); * return RedirectToAction("Index");*/ //ViewBag.Result = "Thank you for rating " + hotel.hotel_name; TempData["shortMessage"] = "Thank you for rating " + hotel2.hotel_name; } else { ViewBag.Result = "Please select a rating"; return(View(hotel)); } } return(RedirectToAction("Index")); }
public Hotel_Data ReadJson() { var randomiser = new Random(); var randomNumber = randomiser.Next(30000); Thread.Sleep(randomNumber); JavaScriptSerializer oJS = new JavaScriptSerializer(); StreamReader sr = new StreamReader(Property.DataProviderJsonTwo); string jsonString = sr.ReadToEnd(); var oRootObject = JsonConvert.DeserializeObject <Rootobject>(jsonString); Hotel_Data hotelData = new Hotel_Data(); hotelData.hotel_0 = oRootObject.getHotelRatesLiveNet.results.hotel_data.hotel_0; hotelData.hotel_1 = oRootObject.getHotelRatesLiveNet.results.hotel_data.hotel_1; hotelData.hotel_2 = oRootObject.getHotelRatesLiveNet.results.hotel_data.hotel_2; //string str = oRootObject.GetType().ToString(); //StreamReader sr = new StreamReader(@"D:\\training\\WCF\\XMLHotelAPI\\Data\\RS_f370dfb6-e226-4c9a-92f2-35b79e90c6b7.txt"); //string jsonString = sr.ReadToEnd(); //DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(Rootobject)); //MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(jsonString)); //Rootobject obj = (Rootobject)ser.ReadObject(ms); //return obj; //StreamReader sr = new StreamReader(@"D:\\training\\WCF\\XMLHotelAPI\\Data\\RS_f370dfb6-e226-4c9a-92f2-35b79e90c6b7.JSON"); //string jsonString = sr.ReadToEnd(); //object obj = JsonConvert.DeserializeObject<Hotel_Data>(jsonString); return(hotelData); }