Exemplo n.º 1
0
        public IActionResult Rating(int id, HomeRatingViewModel model)
        {
            string userId = User.FindFirstValue(ClaimTypes.NameIdentifier);

            if (!TryValidateModel(model))
            {
                return(View(model));
            }

            var rating = new Rating()
            {
                RatingPoints = model.Rating.RatingPoints,
                FilmId       = id,
                UserId       = userId,
                Review       = model.Rating.Review
            };

            try
            {
                _appContext.Ratings.Add(rating);
                _appContext.SaveChanges();
            }
            catch (Exception)
            {
                _appContext.Ratings.Update(rating);
                _appContext.SaveChanges();
            }
            return(RedirectToAction("Index"));
        }
Exemplo n.º 2
0
        public IActionResult Rating(int id)
        {
            Rating[] ratingsFromDb        = _appContext.Ratings.ToArray();
            List <SelectListItem> ratings = new List <SelectListItem>();
            Film filmFromDb = _appContext.Films.FirstOrDefault(x => x.Id == id);


            for (int i = 1; i < 11; ++i)
            {
                ratings.Add(new SelectListItem()
                {
                    Value = i.ToString(),
                    Text  = i.ToString(),
                });
            }
            HomeRatingViewModel model = new HomeRatingViewModel()
            {
                Titel        = filmFromDb.Titel,
                Beschrijving = filmFromDb.Beschrijving,
                Foto         = filmFromDb.Foto,
                Ratings      = ratings,
            };

            return(View(model));
        }