// public ActionResult Create(RatingModelViewModel item) public ActionResult Create() { var item = new RatingModelViewModel() { ModelId = 5, RatingId = 4 }; try { if (item == null) return RedirectToAction("Error404", "Home"); if (User.IsInRole("Customer")) { var newItem = _repo.Create(item); if (newItem == null) return RedirectToAction("Error404", "Home"); return View(newItem); } return RedirectToAction("Login", "Account"); } catch (Exception ex) { return new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.ToString()); } }
public RatingModelViewModel Create(RatingModelViewModel item) { if (item == null) return null; db.RatingModels.Add(item); db.SaveChanges(); return item; }
// GET: CustomerRating/Create public ActionResult Create(int id) { try { //if (User.IsInRole("Customer")) //{ //The controller needs a modelId to add the rating //The customer can only a rating that is from one to five int modelId = id; var newItem = new RatingModelViewModel() { ModelId = modelId }; return View(newItem); //} //return RedirectToAction("Login", "Account"); } catch (Exception ex) { return new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.ToString()); } }
public ActionResult Create(ReviewViewModel item, int? rating) { try { if (User.IsInRole("Customer")) { if (item == null) return RedirectToAction("Error404", "Home"); var reviewDetails = Session["Review"] as ReviewViewModel; var newRecord = new ReviewViewModel { Description = item.Description, UserId = reviewDetails.UserId, ModelId = reviewDetails.ModelId, DtCreated = DateTime.UtcNow }; db.Reviews.Add(newRecord); db.SaveChanges(); int ratingNumber = rating ?? 1; int ratingId = (from r in db.Ratings where r.RatingNumber == ratingNumber select r.RatingId).FirstOrDefault(); var newRating = new RatingModelViewModel() { ModelId = reviewDetails.ModelId, RatingId = ratingId }; db.RatingModels.Add(newRating); db.SaveChanges(); Session.Remove("Review"); return RedirectToAction("CustomerRetrieveOrders", "Customer", new { message = ManageMessageId.ReviewSuccess }); } return RedirectToAction("Login", "Account"); } catch (Exception ex) { return new HttpStatusCodeResult(HttpStatusCode.InternalServerError, ex.ToString()); } }