Advertisement
Guest User

Untitled

a guest
Apr 30th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.22 KB | None | 0 0
  1.  public ActionResult AddReview(string ReviewText, int ProdID)
  2.         {
  3.             var review = new Review();
  4.             review.ReviewDesc = ReviewText;
  5.             review.ID = ProdID;
  6.             review.ReviewDate = DateTime.Now.Date;
  7.             //==== Get User ID =====
  8.             review.UserID = User.Identity.GetUserId();
  9.             //======
  10.             db.Reviews.Add(review);
  11.             db.SaveChanges();
  12.             var product = db.products.Find(ProdID);
  13.             var rev = db.Reviews.Where(x => x.ID == ProdID);
  14.             return View("Details", product);
  15.         }
  16.  
  17. /////////////////////////////////////
  18. public class ReviewProducts
  19.     {
  20.         ApplicationDbContext db = new ApplicationDbContext();
  21.         public IEnumerable<Review> GetReviewByID(int prodId)
  22.         {
  23.             var reviews = db.Reviews.Where(x => x.ID == prodId);
  24.             return reviews.AsEnumerable().OrderByDescending(x => x.ID);
  25.  
  26.         }
  27.     }
  28. /////////////////////////
  29.  @using (Html.BeginForm("AddReview", "Home"))
  30.         {
  31.             <input type="text" name="ReviewText" />
  32.             <input type="hidden" name="ProdID" value="@Model.ID">
  33.             <input type="submit" value="Post Review" />
  34.  
  35.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement