Ejemplo n.º 1
0
        public JsonResult GetHotels()
        {
            HotelRating hotelRating = new HotelRating();
            var         hotels      = hotelRating.GetAllHotels();

            return(Json(hotels, JsonRequestBehavior.AllowGet));
        }
Ejemplo n.º 2
0
 public Review(User reviewAuthor, Hotel reviewedHotel, string description, HotelRating hotelRating)
 {
     ReviewAuthor  = reviewAuthor;
     ReviewedHotel = reviewedHotel;
     Description   = description;
     HotelRating   = hotelRating;
 }
Ejemplo n.º 3
0
        public ActionResult DeleteConfirmed(int id)
        {
            HotelRating hotelRating = db.HotelRatings.Find(id);

            db.HotelRatings.Remove(hotelRating);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 4
0
 public ActionResult Edit([Bind(Include = "Id,Rating,HotelName")] HotelRating hotelRating)
 {
     if (ModelState.IsValid)
     {
         db.Entry(hotelRating).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(hotelRating));
 }
Ejemplo n.º 5
0
        // GET: HotelRatings/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            HotelRating hotelRating = db.HotelRatings.Find(id);

            if (hotelRating == null)
            {
                return(HttpNotFound());
            }
            return(View(hotelRating));
        }
        public async Task <bool> CreateHotelRatingAsync(HotelRatingCreate model)
        {
            var entity = new HotelRating
            {
                Comment  = model.Comment,
                HotelId  = model.HotelId,
                Grade    = model.Grade,
                UserId   = _userId,
                StayDate = model.StayDate
            };

            _context.Ratings.Add(entity);
            var changeCount = await _context.SaveChangesAsync();

            return(changeCount == 1);
        }
Ejemplo n.º 7
0
        public ActionResult Create([Bind(Include = "hotelrating_id,hotel_id,rating,review,user_id")] HotelRating hotelRating)
        {
            hotelRating.user_id = User.Identity.GetUserId();
            if (hotelRating.rating <= 0)  // if given is not given
            {
                ViewBag.error = true;
            }
            else if (ModelState.IsValid && hotelRating.rating > 0)
            {
                db.HotelRatings.Add(hotelRating);
                db.SaveChanges();

                var hotel     = db.Hotels.FirstOrDefault(h => h.hotel_id == hotelRating.hotel_id);
                var ratingAvg = hotel.HotelRatings.Average(h => h.rating); // recalculate the rating for the hotel
                hotel.rating = (int)ratingAvg;
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }

            ViewBag.hotel_id = new SelectList(db.Hotels, "hotel_id", "name", hotelRating.hotel_id);
            return(View(hotelRating));
        }
Ejemplo n.º 8
0
        public ActionResult Rate([Bind(Include = "Id,Rating,HotelId")] HotelRating hotelRating)
        {
            hotelRating.UserId = User.Identity.GetUserId();
            var userId = User.Identity.GetUserId();

            ModelState.Clear();
            TryValidateModel(hotelRating);
            if (ModelState.IsValid)
            {
                if (!db.HotelRatings.Where(b => b.UserId == userId).Any(b => b.HotelId == hotelRating.HotelId &&
                                                                        b.HotelId == hotelRating.HotelId))
                {
                    db.HotelRatings.Add(hotelRating);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
                else
                {
                    return(View("Error"));
                }
            }
            ViewBag.HotelId = new SelectList(db.Hotels, "Id", "Name", hotelRating.HotelId);
            return(View(hotelRating));
        }
Ejemplo n.º 9
0
 public ActionResult InsertToHotelRating(HotelRating hotelRating)
 {
     modelobj.HotelRatings.Add(hotelRating);
     return(View(modelobj.SaveChanges()));
 }
Ejemplo n.º 10
0
 public HttpResponseMessage InsertToHotelRating(HotelRating hotelRating)
 {
     modelobj.HotelRatings.Add(hotelRating);
     return(Request.CreateResponse(HttpStatusCode.OK, modelobj.SaveChanges()));
 }