Exemplo n.º 1
0
        public ActionResult CreateComment(string CommentText, int Rating, int TripId)
        {
            string      userId    = User.Identity.GetUserId();
            Users_Trips user_trip = db.Users_Trips.Where(ut => ut.UserId == userId && ut.TripId == TripId).FirstOrDefault();

            user_trip.CommentText = CommentText;
            user_trip.Rating      = Rating;

            List <Users_Trips> uts = db.Users_Trips.Where(ut => ut.TripId == TripId && ut.CommentText != null).ToList();

            Trip trip = db.Trips.Find(TripId);

            if (trip == null)
            {
                return(HttpNotFound());
            }
            else
            {
                double divider = uts.Count + 1;
                if (trip.Rating == null)
                {
                    trip.Rating = 0;
                }
                trip.Rating = (trip.Rating * uts.Count + Rating) / divider;

                if (ModelState.IsValid)
                {
                    db.Entry(trip).State = EntityState.Modified;
                    db.SaveChanges();
                }
            }

            if (ModelState.IsValid)
            {
                db.Entry(user_trip).State = EntityState.Modified;
                db.SaveChanges();
            }

            return(RedirectToAction("Details", "Route", new { id = TripId }));
        }
Exemplo n.º 2
0
 public void Update(Trip c)
 {
     db.Entry(c).State = EntityState.Modified;
 }