Esempio n. 1
0
        public ActionResult RateHikeCalculate(int?id, string rating)
        {
            var   hikeTrips = db.HikerTripDetails.Where(x => x.HikeId == id && x.UserRating > 0).ToList();
            float sumRating = 0;

            for (int i = 0; i < hikeTrips.Count; i++)
            {
                sumRating = sumRating + hikeTrips[i].UserRating;
            }
            sumRating = sumRating + float.Parse(rating);
            var finalRating = sumRating / (hikeTrips.Count + 1);

            Hikes hike = db.Hikes.Find(id);

            hike.HikeRating = finalRating;

            var currentUserId          = User.Identity.GetUserId();
            HikerTripDetails hikerTrip = db.HikerTripDetails.Where(x => x.HikeId == id && x.UserID == currentUserId).ToList()[0];

            hikerTrip.UserRating = float.Parse(rating);

            db.Hikes.Attach(hike);
            db.Entry(hike).Property(x => x.HikeRating).IsModified = true;
            db.HikerTripDetails.Attach(hikerTrip);
            db.Entry(hikerTrip).Property(x => x.UserRating).IsModified = true;
            db.SaveChanges();

            return(RedirectToAction("ShowRatingHikes"));
        }
        public ActionResult DeleteConfirmed(int id)
        {
            HikerTripDetails hikerTripDetails = db.HikerTripDetails.Find(id);

            db.HikerTripDetails.Remove(hikerTripDetails);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public ActionResult Edit([Bind(Include = "Id,UserID,IsHikeCompleted")] HikerTripDetails hikerTripDetails)
 {
     if (ModelState.IsValid)
     {
         db.Entry(hikerTripDetails).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(hikerTripDetails));
 }
        public ActionResult Create([Bind(Include = "Id,UserID,IsHikeCompleted")] HikerTripDetails hikerTripDetails)
        {
            if (ModelState.IsValid)
            {
                db.HikerTripDetails.Add(hikerTripDetails);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(hikerTripDetails));
        }
        // GET: HikerTripDetails/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            HikerTripDetails hikerTripDetails = db.HikerTripDetails.Find(id);

            if (hikerTripDetails == null)
            {
                return(HttpNotFound());
            }
            return(View(hikerTripDetails));
        }
Esempio n. 6
0
        public ActionResult RegisterForHike(int?id)
        {
            ModelState.Clear();
            Hikes hikes = db.Hikes.Find(id);

            TryValidateModel(hikes);
            if (ModelState.IsValid)
            {
                hikes.RegisteredParticipants = hikes.RegisteredParticipants + 1;
                HikerTripDetails hikertrip = new HikerTripDetails();
                hikertrip.HikeId     = hikes.Id;
                hikertrip.UserRating = 0;
                hikertrip.UserID     = User.Identity.GetUserId();
                db.Hikes.Attach(hikes);
                db.Entry(hikes).Property(x => x.RegisteredParticipants).IsModified = true;
                db.HikerTripDetails.Add(hikertrip);
                db.SaveChanges();
                return(RedirectToAction("ShowHikes"));
            }

            return(View(hikes));
        }