public async Task <Review> addReview(ReviewProduction review) { HttpConnection http = new HttpConnection(); String url = Constant.POST_REVIEW_URL; return(await http.postReviewAsync(url, review)); }
//public ActionResult AddNew([Bind(Include = "OverallRating,Title,Content")] ReviewProduction1 model) public async Task <ActionResult> AddNewReview(ReviewProduction model) { if (UserManager.User != null) { if (ModelState.IsValid) { // save to DB DBModelContainer db = new DBModelContainer(); Review review = new Review(); review.UserId = UserManager.User.Id; review.ProductId = model.ProductId; review.ReviewDate = DateTime.Now; review.Title = model.Title; review.Content = model.Content; review.OverallRating = model.OverallRating; db.Reviews.Add(review); await db.SaveChangesAsync(); // Info. /* * return this.Json(new * { * EnableSuccess = true, * SuccessTitle = "Success", * SuccessMsg = "Add new review sucessfully" * });*/ List <ReviewProduction> reviewList = (from r in db.Reviews join u in db.Users on r.UserId equals u.UserId where r.ProductId == model.ProductId select new ReviewProduction { ReviewId = r.ReviewId, Title = r.Title, Content = r.Content, OverallRating = r.OverallRating, UserName = u.UserName, ReviewDate = r.ReviewDate, }).ToList(); return(PartialView("_PartialPage_ReviewList", reviewList)); } return(this.Json(new { ResponseType = Config.SOMETHING_WRONG_WITH_POST_REQUEST, Msg = "Something goes wrong, please try again later" })); } return(this.Json(new { ResponseType = Config.NEED_LOGIN, Msg = "Please login first" })); }
public async Task <Review> postReviewAsync(string path, ReviewProduction _review) { HttpResponseMessage response = await client.PostAsJsonAsync(path, _review); response.EnsureSuccessStatusCode(); // Deserialize the updated product from the response body. Review review = await response.Content.ReadAsAsync <Review>(); return(review); }
//public ActionResult AddNew([Bind(Include = "OverallRating,Title,Content")] ReviewProduction1 model) public async Task <ActionResult> AddNewReview(ReviewProduction model) { if (UserManager.User != null) { if (ModelState.IsValid) { ProductionService service = new ProductionService(); // add new review of a product model.UserId = UserManager.User.Id; await service.addReview(model); /*{ * ReviewId, * Title, * Content, * OverallRating, * UserName, * ReviewDate, * }*/ // get all reviews of a product List <ReviewProduction> reviewList = await service.getReviewsByProductId(model.ProductId); return(PartialView("_PartialPage_ReviewList", reviewList)); } return(this.Json(new { ResponseType = Config.SOMETHING_WRONG_WITH_POST_REQUEST, Msg = "Something goes wrong, please try again later" })); } return(this.Json(new { ResponseType = Config.NEED_LOGIN, Msg = "Please login first" })); }