Beispiel #1
0
        public async Task UpdateUserRatingAsync(UserRatingDTO userRatingDTO)
        {
            var finalQuery = movieDbContext.Movies.Where(m => m.Title.Contains(userRatingDTO.Movie.Title) &&
                                                         m.YearOfRelease == userRatingDTO.Movie.YearOfRelease &&
                                                         m.RunningTimeInMinutes == userRatingDTO.Movie.RunningTimeInMinutes);
            Movie movie = await finalQuery.FirstAsync();

            if (movie != null)
            {
                var user = await movieDbContext.Users.Where(p => p.Name == userRatingDTO.User.Name).FirstAsync();

                if (user != null)
                {
                    var rating = await movieDbContext.Ratings.Where(p => p.MovieId == movie.Id &&
                                                                    p.UserId == user.Id).FirstOrDefaultAsync();

                    if (rating != null)
                    {
                        rating.Value = userRatingDTO.Rating;
                    }
                    else
                    {
                        movieDbContext.Ratings.Add(new Rating {
                            Id      = Guid.NewGuid(),
                            MovieId = movie.Id,
                            UserId  = user.Id,
                            Value   = userRatingDTO.Rating
                        });
                    }
                    await movieDbContext.SaveChangesAsync();
                }
            }
        }
Beispiel #2
0
        //Method that gets all Ratings for specific user
        public IList<UserRatingDTO> GetAllUserRatings(Guid userID)
        {
            IList<UserRatingDTO> ListOfRatings = new List<UserRatingDTO>();

            using (var context = new CinemaEntities())
            {
                var results = (from rt in context.Ratings.Include("Movie")
                               where rt.UserID == userID
                               select rt);

                if (results != null)
                {
                    foreach (var item in results)
                    {
                        UserRatingDTO row = new UserRatingDTO();
                        row.ratingID = item.RatingID;
                        row.userID = userID.ToString();
                        row.movieID = item.MovieID;
                        row.MovieTitle = item.Movie.Title;
                        row.rate = item.Rate;
                        ListOfRatings.Add(row);
                    }
                }
            }

            return ListOfRatings;
        }
Beispiel #3
0
        //Method that gets all Ratings for specific user
        public IList <UserRatingDTO> GetAllUserRatings(Guid userID)
        {
            IList <UserRatingDTO> ListOfRatings = new List <UserRatingDTO>();

            using (var context = new CinemaEntities())
            {
                var results = (from rt in context.Ratings.Include("Movie")
                               where rt.UserID == userID
                               select rt);

                if (results != null)
                {
                    foreach (var item in results)
                    {
                        UserRatingDTO row = new UserRatingDTO();
                        row.ratingID   = item.RatingID;
                        row.userID     = userID.ToString();
                        row.movieID    = item.MovieID;
                        row.MovieTitle = item.Movie.Title;
                        row.rate       = item.Rate;
                        ListOfRatings.Add(row);
                    }
                }
            }


            return(ListOfRatings);
        }
Beispiel #4
0
        public async Task <UserRatingDTO> EditUserRatingAsync(UserRatingDTO userRating)
        {
            if (userRating == null)
            {
                throw new ArgumentNullException(nameof(userRating));
            }

            var createdUserRating = await _userRatingRepository
                                    .UpdateAsync(_mapper.Map <UserRatingDTO, UserRating>(userRating));

            if (createdUserRating == null)
            {
                throw new NullReferenceException("User rating was not updated");
            }
            return(_mapper.Map <UserRating, UserRatingDTO>(createdUserRating));
        }
Beispiel #5
0
        public async Task <ActionResult> UpdateUserRatingAsync([FromBody] UserRatingDTO userRatingDTO)
        {
            await movieRepository.UpdateUserRatingAsync(userRatingDTO);

            return(Ok());
        }