public ActionResult Rate(AcademyRatingCreate model) { if (ModelState.IsValid) { var service = new RatingService(User.Identity.GetUserId()); if (service.CreateAcademyRating(model)) { return(RedirectToAction(nameof(Index))); } } return(View(model)); }
public ActionResult Rate(int id) { var service = GetAcademyService(); ViewBag.Detail = service.GetAcademyById(id); var model = new AcademyRatingCreate { AcademyId = id }; return(View(model)); }
public bool CreateAcademyRating(AcademyRatingCreate model) { var ctx = new ApplicationDbContext(); var createdBy = ctx.Users.FirstOrDefault(u => u.Id == _userId).UserName; var entity = new AcademyRating { Description = model.Description, AcademyId = model.AcademyId, Score = model.Score, OwnerId = _userId, CreatedBy = createdBy }; _context.Ratings.Add(entity); var changeCount = _context.SaveChanges(); return(changeCount == 1); }