Пример #1
0
        public async Task <IActionResult> GetMyMovies(GetMyMoviesFilter model)
        {
            try
            {
                var result = await movieLib.GetMyMoviesAsync(model, CurrentUserId);

                return(CustomResult(result));
            }
            catch (System.Exception exp)
            {
                return(CustomError(exp));
            }
        }
Пример #2
0
        public async Task <List <MovieModel> > GetMyMoviesAsync(GetMyMoviesFilter filter, long currentUserId)
        {
            var result =
                from m in movieRepo.GetQuery()
                join mcd in movieCollectionDetailRepo.GetQuery() on m.Id equals mcd.MovieId into mmcd
                from mcd in mmcd.DefaultIfEmpty()
                join mc in movieCollectionRepo.GetQuery() on mcd.MovieCollectionId equals mc.Id into mcdmc
                from mc in mcdmc.DefaultIfEmpty()
                where
                m.UserId == currentUserId &&
                (m.Title.Contains(filter.Title) || (mc != null && mc.Name.Contains(filter.Title))) &&
                (filter.MinRate == 0 || Convert.ToDouble(m.ImdbRating) >= filter.MinRate) &&
                (filter.MaxRate == 0 || Convert.ToDouble(m.ImdbRating) <= filter.MaxRate) &&
                (filter.MinYear == 0 || Convert.ToInt32(m.Year) >= filter.MinYear) &&
                (filter.MaxYear == 0 || Convert.ToInt32(m.Year) <= filter.MaxYear) &&
                (filter.Rated == null || filter.Rated.Contains(m.Rated)) &&
                (string.IsNullOrWhiteSpace(filter.Genre) || m.MovieGenres.Any(r => r.Genre.Title.Contains(filter.Genre))) &&
                (string.IsNullOrWhiteSpace(filter.Director) || m.MovieCasts.Any(r => r.CastType == CastTypeKind.Director && r.Cast.FullName.Contains(filter.Director))) &&
                (string.IsNullOrWhiteSpace(filter.Writer) || m.MovieCasts.Any(r => r.CastType == CastTypeKind.Writer && r.Cast.FullName.Contains(filter.Writer))) &&
                (string.IsNullOrWhiteSpace(filter.Star) || m.MovieCasts.Any(r => r.CastType == CastTypeKind.Actor && r.Cast.FullName.Contains(filter.Star))) &&
                (filter.Seen == null || m.Seen == filter.Seen)
                orderby mc.Name, mcd.Number, m.Title
                select new MovieModel
            {
                Id         = m.Id,
                Title      = (mc == null ? "" : "(" + mc.Name + " - " + mcd.Number.ToString() + ") ") + m.Title,
                ImdbRating = m.ImdbRating,
                Year       = m.Year,
                Rated      = m.Rated,
                Genre      = (filter.Genre == string.Empty && !filter.ShowAllInfo) ? string.Empty : string.Join(',', m.MovieGenres.Select(r => r.Genre.Title)),
                Director   = (filter.Director == string.Empty && !filter.ShowAllInfo) ? string.Empty : string.Join(',', m.MovieCasts.Where(r => r.CastType == CastTypeKind.Director).Select(r => r.Cast.FullName)),
                Writer     = (filter.Writer == string.Empty && !filter.ShowAllInfo) ? string.Empty : string.Join(',', m.MovieCasts.Where(r => r.CastType == CastTypeKind.Writer).Select(r => r.Cast.FullName)),
                Actors     = (filter.Star == string.Empty && !filter.ShowAllInfo) ? string.Empty : string.Join(',', m.MovieCasts.Where(r => r.CastType == CastTypeKind.Actor).Select(r => r.Cast.FullName)),
                LocalPath  = m.LocalPath,
                Poster     = m.Poster,
                Seen       = m.Seen
            };

            return(await result.ToAsyncEnumerable().ToList());
        }