public IActionResult Add(RatingAddVM ra) { if (!ModelState.IsValid) { return(View(ra)); } ratingService.AddRatingToDB(ra); return(RedirectToAction(nameof(Add))); }
public IActionResult SetRating([FromBody] RatingAddVM product) { if (ratingService.AddUserRatingToDB(product)) { return(Json(new { success = true })); } else { return(Json(new { success = false })); } }
internal void AddRatingToDB(RatingAddVM ra) { Rating x = new Rating(); x.ProductId = ra.SelectedProductValue; x.Rating1 = ra.Rating; x.Comment = ra.Comment; x.UserId = ra.UserId; context.Rating.Add(x); context.SaveChanges(); }
internal RatingAddVM GetAllProductsForDropDownList() { Products[] x = GetAllProductsFromDB_ID_NAME(); var viewModel = new RatingAddVM(); viewModel.ListOfProducts = new SelectListItem[x.Length]; for (int i = 0; i < x.Length; i++) { viewModel.ListOfProducts[i] = new SelectListItem { Value = $"{x[i].Id.ToString()}", Text = $"{x[i].Name}" }; } return(viewModel); }
internal bool AddUserRatingToDB(RatingAddVM producttorate) { try { Rating r = new Rating(); r.UserId = producttorate.UserId; r.ProductId = producttorate.ProductId; r.Rating1 = producttorate.Rating; r.Comment = producttorate.Comment; context.Rating.Add(r); context.SaveChanges(); return(true); } catch (Exception) { return(false); } }