public ActionResult RateProgram(ProgramRatingCreate model)
 {
     if (ModelState.IsValid)
     {
         var service = new RatingService(User.Identity.GetUserId());
         if (service.CreateProgramRating(model))
         {
             return(RedirectToAction(nameof(Index)));
         }
     }
     return(View(model));
 }
        public ActionResult RateProgram(int id)
        {
            var service = GetBrowsingService();

            ViewBag.Detail = service.GetProgramById(id);

            var model = new ProgramRatingCreate {
                ProgramId = id
            };

            return(View(model));
        }
        public bool CreateProgramRating(ProgramRatingCreate model)
        {
            var ctx       = new ApplicationDbContext();
            var createdBy = ctx.Users.FirstOrDefault(u => u.Id == _userId).UserName;
            var entity    = new ProgramRating
            {
                Description = model.Description,
                ProgramId   = model.ProgramId,
                Score       = model.Score,
                OwnerId     = _userId,
                CreatedBy   = createdBy
            };

            _context.Ratings.Add(entity);
            var changeCount = _context.SaveChanges();

            return(changeCount == 1);
        }