public IActionResult Get() { var movies = Movies.OrderByDescending(a => a.AverageRating).ThenBy(t => t.Title).Take(5); if (movies != null) { var moviesResponse = MoviesResponse.CreateResponse(movies); return(Ok(moviesResponse)); } return(NotFound()); }
public IActionResult Get(int userId) { var user = Users.Where(i => i.ID == userId).SingleOrDefault(); if (user == null) { return(NotFound("No user has been found for this id")); } var movies = Movies.OrderByDescending(a => a.UserRatings.Where(u => u.User.ID == userId).SingleOrDefault().Rating).ThenBy(t => t.Title).Take(5); if (movies != null) { var moviesResponse = MoviesResponse.CreateResponse(movies); return(Ok(moviesResponse)); } return(NotFound("No matching movie ratings were able to be found for this user")); }
public IActionResult Get(string title = null, string yearOfRelease = null, string[] genres = null) { var movies = MathHelpers.RoundRatings(Movies); if (title == null && yearOfRelease == null && genres.Length == 0) { return(BadRequest("You must submit at least 1 search critera")); } IEnumerable <Movie> filteredMovies = null; if (title != null) { filteredMovies = movies.Where(x => x.Title.ToLower().Contains(title.ToLower())); } if (yearOfRelease != null) { filteredMovies = filteredMovies == null? movies.Where(x => x.YearOfRelease == yearOfRelease) : filteredMovies.Where(x => x.YearOfRelease == yearOfRelease); } if (genres.Length > 0) { filteredMovies = filteredMovies == null? movies.Where(x => !genres.Except(x.Genres).Any()) : filteredMovies.Where(x => !genres.Except(x.Genres).Any()); } if (filteredMovies != null) { var moviesResponse = MoviesResponse.CreateResponse(filteredMovies); return(Ok(moviesResponse)); } return(NotFound()); }