Пример #1
0
        public async Task <ResponsesDto <CategoryResponse> > GetTvShowsCategories(int tvShowId)
        {
            var response = new ResponsesDto <CategoryResponse>();

            var tvShowExists = await _tvShowRepository.ExistAsync(x => x.Id == tvShowId);

            if (!tvShowExists)
            {
                response.AddError(Model.TvShow, Error.tvShow_NotFound);
                return(response);
            }

            var assignments       = _tvShowCategoryAssignemtsRepository.GetAllBy(x => x.TvShow.Id == tvShowId, x => x.Category);
            var assignmentsMapped = new List <CategoryResponse>();

            foreach (var assignment in assignments)
            {
                var category = await _categoryRepository.GetByAsync(x => x.Id == assignment.Category.Id);

                var categoryMapped = _mapper.Map <CategoryResponse>(category);
                assignmentsMapped.Add(categoryMapped);
            }

            response.DtoObject = assignmentsMapped;

            return(response);
        }
Пример #2
0
        public async Task <ResponsesDto <GetNotificationsDto> > GetNotifications(string userId)
        {
            var response = new ResponsesDto <GetNotificationsDto>();

            if (userId == null)
            {
                response.AddError(Model.Account, Error.account_Login);
                return(response);
            }

            var notifications       = _notificationRepository.GetAllBy(x => x.UserId == userId, x => x.TvShow).OrderByDescending(x => x.CreateDateTime);
            var notificationsMapped = new List <GetNotificationsDto>();

            if (notifications.Any())
            {
                foreach (var notification in notifications)
                {
                    notificationsMapped.Add(new GetNotificationsDto
                    {
                        Type           = notification.Type,
                        CreateDateTime = notification.CreateDateTime,
                        Id             = notification.Id,
                        FirstPart      = notification.FirstPart,
                        SecondPart     = notification.SecondPart,
                        TvShowName     = notification.TvShow.Name,
                        TvShowId       = notification.TvShowId
                    });
                }

                response.DtoObject = notificationsMapped;
            }

            return(response);
        }
Пример #3
0
        public async Task <ResponsesDto <GetTvSeriesCommentsDto> > GetTvSeriesComments(int tvSeriesId)
        {
            var response = new ResponsesDto <GetTvSeriesCommentsDto>();

            var tvSeriesExists = await _tvSeriesRepository.ExistAsync(x => x.Id == tvSeriesId);

            if (!tvSeriesExists)
            {
                response.AddError(Model.TvShow, Error.tvShow_NotFound);
                return(response);
            }

            var comments = _commentRepository.GetAllBy(x => x.TvSeriesId == tvSeriesId, x => x.User).OrderByDescending(x => x.CreateDateTime);

            if (comments.Any())
            {
                List <GetTvSeriesCommentsDto> tvSeriesComments = new List <GetTvSeriesCommentsDto>();
                foreach (var comment in comments)
                {
                    var user = await _userManager.FindByIdAsync(comment.UserId);

                    var mappedComment = _mapper.Map <GetTvSeriesCommentsDto>(comment);
                    mappedComment.Avatar = user.Avatar;

                    tvSeriesComments.Add(mappedComment);
                }

                response.DtoObject = tvSeriesComments;
            }

            return(response);
        }
        public async Task <ResponsesDto <ActorAssignmentsResponseDto> > GetActorAssignments(int actorId)
        {
            var response = new ResponsesDto <ActorAssignmentsResponseDto>();

            var actorExists = await _actorRepository.ExistAsync(x => x.Id == actorId);

            if (!actorExists)
            {
                response.AddError(Model.Actor, Error.actor_NotExists);
                return(response);
            }

            var assignments       = _actorsAssignmentsRepository.GetAllBy(x => x.Actor.Id == actorId, x => x.TvShow);
            var assignmentsMapped = new List <ActorAssignmentsResponseDto>();

            foreach (var assignment in assignments)
            {
                var tvShow = await _tvShowRepository.GetByAsync(x => x.Id == assignment.TvShow.Id);

                var tvShowMapped = _mapper.Map <TvShowResponse>(tvShow);
                ActorAssignmentsResponseDto tmpAssignment = new ActorAssignmentsResponseDto();
                tmpAssignment.TvShow        = tvShowMapped;
                tmpAssignment.CharacterName = assignment.CharacterName;
                tmpAssignment.Id            = assignment.Id;
                assignmentsMapped.Add(tmpAssignment);
            }

            response.DtoObject = assignmentsMapped;

            return(response);
        }
        public async Task <ResponsesDto <TvSeriesAssignmensResponseDto> > GetTvShowAssignments(int tvShowId)
        {
            var response = new ResponsesDto <TvSeriesAssignmensResponseDto>();

            var tvShowExists = await _tvShowRepository.ExistAsync(x => x.Id == tvShowId);

            if (!tvShowExists)
            {
                response.AddError(Model.TvShow, Error.tvShow_NotFound);
                return(response);
            }

            var assignments       = _actorsAssignmentsRepository.GetAllBy(x => x.TvShow.Id == tvShowId, x => x.Actor);
            var assignmentsMapped = new List <TvSeriesAssignmensResponseDto>();

            foreach (var assignment in assignments)
            {
                var actor = await _actorRepository.GetByAsync(x => x.Id == assignment.Actor.Id);

                var actorMapped = _mapper.Map <ActorDto>(actor);
                TvSeriesAssignmensResponseDto tmpAssignment = new TvSeriesAssignmensResponseDto();
                tmpAssignment.ActorDto      = actorMapped;
                tmpAssignment.CharacterName = assignment.CharacterName;
                tmpAssignment.Id            = assignment.Id;
                assignmentsMapped.Add(tmpAssignment);
            }

            response.DtoObject = assignmentsMapped;

            return(response);
        }
Пример #6
0
        public async Task <ResponsesDto <SeasonResponseDto> > GetAllSeasons(int tvSeriesId)
        {
            var response       = new ResponsesDto <SeasonResponseDto>();
            var tvSeriesExists = await _tvShowRepository.ExistAsync(x => x.Id == tvSeriesId);

            if (!tvSeriesExists)
            {
                response.AddError(Model.TvShow, Error.tvShow_NotFound);
            }

            var seasons       = _seasonRepository.GetAllBy(x => x.TvShowId == tvSeriesId, x => x.Episodes);
            var mappedSeasons = new List <SeasonResponseDto>();

            foreach (var season in seasons)
            {
                mappedSeasons.Add(_mapper.Map <SeasonResponseDto>(season));
            }

            response.DtoObject = mappedSeasons;

            return(response);
        }
Пример #7
0
        public async Task <ResponsesDto <EpisodeDto> > GetEpisodes(int seasonId)
        {
            var response     = new ResponsesDto <EpisodeDto>();
            var seasonExists = await _seasonRepository.ExistAsync(x => x.Id == seasonId);

            if (!seasonExists)
            {
                response.AddError(Model.Season, Error.season_NotFound);
                return(response);
            }

            var episodes       = _episodeRepository.GetAllBy(x => x.SeasonId == seasonId);
            var mappedEpisodes = new List <EpisodeDto>();

            foreach (var episode in episodes)
            {
                mappedEpisodes.Add(_mapper.Map <EpisodeDto>(episode));
            }

            response.DtoObject = mappedEpisodes;

            return(response);
        }
Пример #8
0
        public async Task <ResponsesDto <ReturnEpisodeDto> > GetMonthEpisodes(int monthNumber)
        {
            var response = new ResponsesDto <ReturnEpisodeDto>();

            if (monthNumber > 12 || monthNumber < 1)
            {
                response.AddError(Model.Calendar, Error.calendar_Wrong_Month);
                return(response);
            }

            var episodes = _episodeRepository.GetAllBy(x => x.AiringDate.Month == monthNumber, x => x.Season, x => x.Season.TvShow, x => x.Season.TvShow.TvSeriesRatings);

            var mappedEpisodes = new List <ReturnEpisodeDto>();

            foreach (var episode in episodes)
            {
                mappedEpisodes.Add(_mapper.Map <ReturnEpisodeDto>(episode));
            }

            response.DtoObject = mappedEpisodes;

            return(response);
        }