Beispiel #1
0
 public ActionResult Create(RestaurantReviewModel review)
 {
     if (ModelState.IsValid)
     {
         _db.Reviews.Add(review);
         _db.SaveChanges();
         return(RedirectToAction("Index", new { id = review.RestaurantId }));
     }
     return(View(review));
 }
Beispiel #2
0
 //Exclude -> Prevent erroneous POST requests from editing the model (Mass assignment/Overposting)
 public ActionResult Edit(RestaurantReviewModel review)
 {
     if (ModelState.IsValid)
     {
         //Do not insert new record into DB. Update existing record.
         _db.Entry(review).State = System.Data.Entity.EntityState.Modified;
         _db.SaveChanges();
         return(RedirectToAction("Index", new { id = review.RestaurantId }));
     }
     return(View(review));
 }
        public JsonResult PostRestaurantReview(RestaurantReviewModel model)
        {
            var restaurantReview = new RestaurantReview
            {
                AspNetUserId       = User.Identity.GetUserId(),
                RestaurantBranchId = model.RestaurantBranchId,
                ReviewTitle        = model.ReviewTitle,
                ReviewText         = model.ReviewText,
                CreatedOn          = DateTime.Now,
                CreatedBy          = User.Identity.GetUserId()
            };

            try
            {
                _restaurantReviewTask.AddRestaurantReview(restaurantReview);
                return(Json(new { status = ActionStatus.Successful }));
            }
            catch (Exception exception)
            {
                return(Json(new { status = ActionStatus.Failed, data = exception.Message }));
            }
        }