Example #1
0
        public async Task <IActionResult> GetShapedArtists([FromQuery] RequestParameters requestParameters)
        {
            if (string.IsNullOrWhiteSpace(requestParameters.OrderBy))
            {
                requestParameters.OrderBy = "StageName";
            }

            if (!_typeHelperService.TypeHasProperties <ArtistDto>(requestParameters.Fields))
            {
                return(BadRequest());
            }

            var artistPagedList = await GetPagedListOfArtists(requestParameters);

            var paginationMetaData = _controllerHelper.CreatePaginationMetadataObject(artistPagedList, requestParameters, "Getartists");

            Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(paginationMetaData));

            var artists = Mapper.Map <IEnumerable <ArtistDto> >(artistPagedList);

            if (requestParameters.IncludeMetadata)
            {
                var shapedArtists       = artists.ShapeData(requestParameters.Fields);
                var artistsWithMetadata = new EntityWithPaginationMetadataDto <ExpandoObject>(paginationMetaData, shapedArtists);
                return(Ok(artistsWithMetadata));
            }

            return(Ok(artists.ShapeData(requestParameters.Fields)));
        }
Example #2
0
        public async Task <IActionResult> GetAllShowtimesAsync([FromRoute] Guid movieId, [FromQuery] RequestParameters requestParameters, [FromHeader(Name = "Accept")] string mediaType)
        {
            if (!await _showtimeRepository.MovieExists(movieId))
            {
                return(NotFound());
            }

            if (string.IsNullOrWhiteSpace(requestParameters.OrderBy))
            {
                //  TODO: change to order by when playing
                requestParameters.OrderBy = "Id";
            }

            if (!_propertyMappingService.ValidMappingExistsFor <ShowtimeDto, Showtime>(requestParameters.Fields))
            {
                return(BadRequest());
            }

            if (!_typeHelperService.TypeHasProperties <ShowtimeDto>(requestParameters.Fields))
            {
                return(BadRequest());
            }

            var showtimesPagedList = await _showtimeRepository.GetAllShowtimesAsync(movieId, requestParameters.OrderBy, requestParameters.PageNumber, requestParameters.PageSize);

            var showtimes = Mapper.Map <IEnumerable <ShowtimeDto> >(showtimesPagedList);

            if (mediaType == "application/vnd.biob.json+hateoas")
            {
                return(Ok(CreateHateoasResponse(showtimesPagedList, requestParameters)));
            }
            else
            {
                var previousPageLink   = showtimesPagedList.HasPrevious ? CreateUrlForResource(requestParameters, PageType.PreviousPage) : null;
                var nextPageLink       = showtimesPagedList.HasNext ? CreateUrlForResource(requestParameters, PageType.NextPage) : null;
                var paginationMetadata = new PaginationMetadata()
                {
                    TotalCount       = showtimesPagedList.TotalCount,
                    PageSize         = showtimesPagedList.PageSize,
                    CurrentPage      = showtimesPagedList.CurrentPage,
                    TotalPages       = showtimesPagedList.TotalPages,
                    PreviousPageLink = previousPageLink,
                    NextPageLink     = nextPageLink
                };

                Response.Headers.Add("X-Pagination", Newtonsoft.Json.JsonConvert.SerializeObject(paginationMetadata));

                if (requestParameters.IncludeMetadata)
                {
                    var showtimesWithMetadata = new EntityWithPaginationMetadataDto <ShowtimeDto>(paginationMetadata, showtimes);
                    return(Ok(showtimesWithMetadata));
                }

                return(Ok(showtimes));
            }
        }
Example #3
0
        public async Task <IActionResult> GetAllMoviesAsync(
            [FromQuery] RequestParameters requestParameters,
            [FromHeader(Name = "Accept")] string mediaType)
        {
            if (string.IsNullOrWhiteSpace(requestParameters.OrderBy))
            {
                requestParameters.OrderBy = "Title";
            }

            if (!_propertyMappingService.ValidMappingExistsFor <MovieDto, Movie>(requestParameters.Fields))
            {
                return(BadRequest());
            }

            if (!_typeHelperService.TypeHasProperties <MovieDto>(requestParameters.Fields))
            {
                return(BadRequest());
            }

            var moviesPagedList = await _movieRepository.GetAllMoviesAsync(requestParameters.OrderBy,
                                                                           requestParameters.SearchQuery,
                                                                           requestParameters.PageNumber, requestParameters.PageSize);

            var movies = Mapper.Map <IEnumerable <MovieDto> >(moviesPagedList);

            if (mediaType == "application/vnd.biob.json+hateoas")
            {
                return(Ok(CreateHateoasResponse(moviesPagedList, requestParameters)));
            }
            else
            {
                var previousPageLink   = moviesPagedList.HasPrevious ? CreateUrlForResource(requestParameters, PageType.PreviousPage) : null;
                var nextPageLink       = moviesPagedList.HasNext ? CreateUrlForResource(requestParameters, PageType.NextPage) : null;
                var paginationMetadata = new PaginationMetadata()
                {
                    TotalCount       = moviesPagedList.TotalCount,
                    PageSize         = moviesPagedList.PageSize,
                    CurrentPage      = moviesPagedList.CurrentPage,
                    TotalPages       = moviesPagedList.TotalPages,
                    PreviousPageLink = previousPageLink,
                    NextPageLink     = nextPageLink
                };

                Response.Headers.Add("X-Pagination", Newtonsoft.Json.JsonConvert.SerializeObject(paginationMetadata));

                if (requestParameters.IncludeMetadata)
                {
                    var shapedMovies       = movies.ShapeData(requestParameters.Fields);
                    var moviesWithMetadata = new EntityWithPaginationMetadataDto <ExpandoObject>(paginationMetadata, shapedMovies);
                    return(Ok(moviesWithMetadata));
                }

                return(Ok(movies.ShapeData(requestParameters.Fields)));
            }
        }
Example #4
0
        public async Task <IActionResult> GetAllSeatsAsync(
            [FromRoute] Guid hallId,
            [FromQuery] RequestParameters requestParameters,
            [FromHeader(Name = "Accept")] string mediaType)
        {
            if (!await _seatRepository.HallExists(hallId))
            {
                return(NotFound());
            }

            if (!string.IsNullOrWhiteSpace(requestParameters.Fields))
            {
                return(BadRequest());
            }

            var seatsPagedList = await _seatRepository.GetAllSeatsByHallIdAsync(hallId, requestParameters.PageNumber, requestParameters.PageSize);

            var seats = Mapper.Map <IEnumerable <SeatDto> >(seatsPagedList);

            if (mediaType == "application/vnd.biob.json+hateoas")
            {
                return(Ok(CreateHateoasResponse(seatsPagedList, requestParameters)));
            }
            else
            {
                var previousPageLink   = seatsPagedList.HasPrevious ? CreateUrlForResource(requestParameters, PageType.PreviousPage) : null;
                var nextPageLink       = seatsPagedList.HasNext ? CreateUrlForResource(requestParameters, PageType.NextPage) : null;
                var paginationMetadata = new PaginationMetadata()
                {
                    TotalCount       = seatsPagedList.TotalCount,
                    PageSize         = seatsPagedList.PageSize,
                    CurrentPage      = seatsPagedList.CurrentPage,
                    TotalPages       = seatsPagedList.TotalPages,
                    PreviousPageLink = previousPageLink,
                    NextPageLink     = nextPageLink
                };

                Response.Headers.Add("X-Pagination", Newtonsoft.Json.JsonConvert.SerializeObject(paginationMetadata));

                if (requestParameters.IncludeMetadata)
                {
                    var seatsWithMetadata = new EntityWithPaginationMetadataDto <SeatDto>(paginationMetadata, seats);
                    return(Ok(seatsWithMetadata));
                }

                return(Ok(seats));
            }
        }
        public async Task <IActionResult> GetReviewsForAlbum([FromRoute] Guid albumId, RequestParameters reviewRequestParameters)
        {
            if (string.IsNullOrWhiteSpace(reviewRequestParameters.OrderBy))
            {
                reviewRequestParameters.OrderBy = "Submitted";
            }
            if (!_propertyMappingService.ValidMappingExistsFor <ReviewDto, Review>(reviewRequestParameters.Fields))
            {
                return(BadRequest());
            }

            if (!_typeHelperService.TypeHasProperties <ReviewDto>(reviewRequestParameters.Fields))
            {
                return(BadRequest());
            }
            var reviewsForAlbumPagedList = await _reviewRepository.GetReviewsForAlbumAsync(
                albumId, reviewRequestParameters.OrderBy,
                reviewRequestParameters.PageNumber, reviewRequestParameters.PageSize,
                _propertyMappingService.GetPropertyMapping <ReviewDto, Review>());

            var previousPageLink = reviewsForAlbumPagedList.HasPrevious ? CreateUrlForReviewResource(reviewRequestParameters, PageType.PreviousPage) : null;
            var nextPageLink     = reviewsForAlbumPagedList.HasNext ? CreateUrlForReviewResource(reviewRequestParameters, PageType.NextPage) : null;

            var paginationMetaData = new PaginationMetadata()
            {
                TotalCount       = reviewsForAlbumPagedList.TotalCount,
                PageSize         = reviewsForAlbumPagedList.PageSize,
                CurrentPage      = reviewsForAlbumPagedList.CurrentPage,
                TotalPages       = reviewsForAlbumPagedList.TotalPages,
                PreviousPageLink = previousPageLink,
                NextPageLink     = nextPageLink
            };


            Response.Headers.Add("X-Pagination", Newtonsoft.Json.JsonConvert.SerializeObject(paginationMetaData));

            var reviews = Mapper.Map <IEnumerable <ReviewDto> >(reviewsForAlbumPagedList);

            if (reviewRequestParameters.IncludeMetadata)
            {
                var records = reviews.ShapeData(reviewRequestParameters.Fields);

                var artistsWithMetadata = new EntityWithPaginationMetadataDto <ExpandoObject>(paginationMetaData, records);
                return(Ok(artistsWithMetadata));
            }

            return(Ok(reviews.ShapeData(reviewRequestParameters.Fields)));
        }
Example #6
0
        public async Task <IActionResult> GetArtists([FromQuery] RequestParameters requestParameter)
        {
            if (string.IsNullOrWhiteSpace(requestParameter.OrderBy))
            {
                requestParameter.OrderBy = "StageName";
            }

            var artistPagedList = await GetPagedListOfArtists(requestParameter);

            var paginationMetaData = _controllerHelper.CreatePaginationMetadataObject(artistPagedList, requestParameter, "GetArtists");


            Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(paginationMetaData));

            var artists = Mapper.Map <IEnumerable <ArtistDto> >(artistPagedList);

            if (requestParameter.IncludeMetadata)
            {
                var artistsWithMetadata = new EntityWithPaginationMetadataDto <ArtistDto>(paginationMetaData, artists);
                return(Ok(artistsWithMetadata));
            }

            return(Ok(artists));
        }
Example #7
0
        public async Task <IActionResult> GetAllTickets([FromRoute, SwaggerParameter(Description = "Id of the related movie", Required = true)] Guid movieId,
                                                        [FromRoute, SwaggerParameter(Description = "Id of the related showtime", Required = true)] Guid showtimeId,
                                                        [FromQuery, SwaggerParameter(Description = "Parameters for the request: PageNumber, OrderBy, Fields, SearchQuery, IncludeMetadata")] RequestParameters requestParameters,
                                                        [FromHeader(Name = "Accept"), SwaggerParameter(Description = "Media type to return eg. json or json+hateoas")] string mediaType)
        {
            if (!await _ticketRepository.MovieExists(movieId))
            {
                return(NotFound());
            }

            if (!await _ticketRepository.ShowtimeExists(showtimeId))
            {
                return(NotFound());
            }

            //Note: In TicketRepository, ApplySort is temprarily outcommented as it caused an error somehow. TODO: Could be fixed at some point
            //EDIT: This was becuase it didn't like to sort on a date? now sorting on price to make it work.
            //TODO: Change back to CreatedOn
            if (string.IsNullOrWhiteSpace(requestParameters.OrderBy))
            {
                requestParameters.OrderBy = "Price";
            }

            if (!_propertyMappingService.ValidMappingExistsFor <TicketDto, Ticket>(requestParameters.Fields))
            {
                return(BadRequest());
            }

            if (!_typeHelperService.TypeHasProperties <TicketDto>(requestParameters.Fields))
            {
                return(BadRequest());
            }

            PagedList <Ticket> ticketsPagedList = await _ticketRepository.GetAllTicketsByShowtimeIdAsync(showtimeId, requestParameters.OrderBy, requestParameters.SearchQuery,
                                                                                                         requestParameters.PageNumber, requestParameters.PageSize);

            var tickets = Mapper.Map <IEnumerable <TicketDto> >(ticketsPagedList);

            if (mediaType == "application/vnd.biob.json+hateoas")
            {
                return(Ok(CreateHateoasResponse(ticketsPagedList, requestParameters)));
            }
            else
            {
                var previousPageLink   = ticketsPagedList.HasPrevious ? CreateUrlForResource(requestParameters, PageType.PreviousPage) : null;
                var nextPageLink       = ticketsPagedList.HasNext ? CreateUrlForResource(requestParameters, PageType.NextPage) : null;
                var paginationMetadata = new PaginationMetadata()
                {
                    TotalCount       = ticketsPagedList.TotalCount,
                    PageSize         = ticketsPagedList.PageSize,
                    CurrentPage      = ticketsPagedList.CurrentPage,
                    TotalPages       = ticketsPagedList.TotalPages,
                    PreviousPageLink = previousPageLink,
                    NextPageLink     = nextPageLink
                };

                Response.Headers.Add("X-Pagination", Newtonsoft.Json.JsonConvert.SerializeObject(paginationMetadata));

                if (requestParameters.IncludeMetadata)
                {
                    var shapedTickets       = tickets.ShapeData(requestParameters.Fields);
                    var ticketsWithMetadata = new EntityWithPaginationMetadataDto <ExpandoObject>(paginationMetadata, shapedTickets);
                    return(Ok(ticketsWithMetadata));
                }

                return(Ok(tickets.ShapeData(requestParameters.Fields)));
            }
        }