예제 #1
0
        public async Task <bool> RegisterRate(MovieRate rate)
        {
            _iMDbContext.MovieRates.Add(rate);
            await _iMDbContext.SaveChangesAsync();

            return(true);
        }
        public IActionResult Index(int selectedRate, long MovieId)
        {
            QueryOptions options = new QueryOptions();

            MovieRate movie = new MovieRate();

            movie.MovieId = MovieId;
            movie.Rate    = selectedRate;
            User user = JsonConvert.DeserializeObject <User>(HttpContext.Session.GetString("SessionUser"));

            movie.UserId = user.UserId;
            if (movieRateRepository.MovieRates.Count(u => u.MovieId == MovieId && u.UserId == user.UserId) == 0)
            {
                movieRateRepository.AddMovieRate(movie);
            }
            else
            {
                var obj = movieRateRepository.MovieRates.First(u => u.UserId == user.UserId && u.MovieId == MovieId);
                obj.MovieId = MovieId;
                obj.UserId  = user.UserId;
                obj.Rate    = selectedRate;
                movieRateRepository.UpdateMovieRate(obj);
            }

            return(RedirectToAction("Index", movieRepository.GetMovies(options)));
        }
예제 #3
0
        public static void generate()
        {
            var dbContext = new WebContext();

            for (int i = 4; i < 52; i++)
            {
                MovieRate mr = new MovieRate();
                mr.Rate      = i % 5 + 1;
                mr.MovieId   = 47;
                mr.Id        = i;
                mr.Comment   = "my rate is the only true rate";
                mr.UserLogin = "******" + i.ToString();
                dbContext.MovieRate.Add(mr);
            }
            dbContext.SaveChanges();
        }