Пример #1
0
        public ActionResult UpdateReview(Review updatedReview)
        {
            DetroitEntities ORM       = new DetroitEntities();
            Review          OldReview = ORM.Reviews.Find(updatedReview.ReviewNumber);

            if (OldReview != null)
            {
                //3. Update the existing customer

                OldReview.Recommended = updatedReview.Recommended;
                OldReview.Review1     = updatedReview.Review1;
                if (updatedReview.Rating != OldReview.Rating)
                {
                    int difference = updatedReview.Rating - OldReview.Rating;
                    ORM.Landmarks.Find(updatedReview.SiteName).Rating += difference;
                    OldReview.Rating = updatedReview.Rating;
                }

                ORM.Entry(OldReview).State = EntityState.Modified;
                ORM.Entry(ORM.Landmarks.Find(OldReview.SiteName)).State = EntityState.Modified;
                //4. save back to the DB
                ORM.SaveChanges();

                return(RedirectToAction("About"));
            }
            else
            {
                ViewBag.ErrorMessage = "Oops! Something went wrong!";
                return(View("Error"));
            }
        }
Пример #2
0
        public ActionResult DeleteReview(int ReviewNumber)
        {
            //1 ORM
            DetroitEntities ORM = new DetroitEntities();

            DbContextTransaction DeleteTransaction = ORM.Database.BeginTransaction();

            //2 Locate review to delete
            Review Found = ORM.Reviews.Find(ReviewNumber);

            //3 Remove review
            if (Found != null)
            {
                try
                {
                    //4 Save to database
                    ORM.Landmarks.Find(Found.SiteName).Rating          -= Found.Rating;
                    ORM.Entry(ORM.Landmarks.Find(Found.SiteName)).State = EntityState.Modified;
                    ORM.Reviews.Remove(Found);
                    ORM.SaveChanges();
                    DeleteTransaction.Commit();
                    return(RedirectToAction("ListReviews"));
                }
                catch (Exception ex)
                {
                    DeleteTransaction.Rollback();
                    return(View("Error"));
                }
            }
            else
            {
                ViewBag.ErrorMessage = "Customer Not Found";
                return(View("Error"));
            }
        }
Пример #3
0
        public ActionResult AddNewRating(Review userReview, HttpPostedFileBase upload)
        {
            DetroitEntities ORM = new DetroitEntities();

            userReview.UserID   = User.Identity.GetUserId();
            userReview.imageURL = UploadImage(upload);
            ORM.Reviews.Add(userReview);
            Landmark reviewed = ORM.Landmarks.Find(userReview.SiteName);

            reviewed.Rating += userReview.Rating;


            ORM.Entry(reviewed).State = EntityState.Modified;
            ORM.SaveChanges();
            return(RedirectToAction("ListOfLandmarks"));
        }