Beispiel #1
0
        public ActionResult <IEnumerable <BandDto> > GetBands([FromQuery] BandsResourceParameters parameters)
        {
            var bands    = _repository.GetBands(parameters);
            var bandsDto = _mapper.Map <IEnumerable <BandDto> >(bands);

            return(Ok(bandsDto));
        }
Beispiel #2
0
        public async Task <ActionResult <IEnumerable <BandDto> > > GetBandsByIds([FromBody] IEnumerable <Guid> bandIds)
        {
            if (bandIds == null)
            {
                throw new ArgumentNullException(nameof(bandIds));
            }

            var bandsFromRepo = await _bandAlbumRepository.GetBands(bandIds);

            return(Ok(_mapper.Map <IEnumerable <BandDto> >(bandsFromRepo)));
        }
Beispiel #3
0
        public IActionResult getBands([FromQuery] BandResourceParameters bandResourceParameters)
        {
            if (!_propertyMappingService.ValidMappingExists <BandDto, Entities.Band>
                    (bandResourceParameters.OrderBy))
            {
                return(BadRequest());
            }

            if (!_propertyValidationService.HasValidParameters <BandDto>(bandResourceParameters.Fields))
            {
                return(BadRequest());
            }

            var bandsFromRepo = _bandAlbumRepository.GetBands(bandResourceParameters);

            var previousPageLink = bandsFromRepo.HasPrevious ? CreateBandsUri(bandResourceParameters, UriType.PreviousPage) : null;
            var nextPageLink     = bandsFromRepo.HasNext ? CreateBandsUri(bandResourceParameters, UriType.NextPage) : null;

            var metaData = new {
                totalCount  = bandsFromRepo.TotalCount,
                pageSize    = bandsFromRepo.PageSize,
                currentPage = bandsFromRepo.CurrentPage,
                totalPages  = bandsFromRepo.TotalPages,
                previousPageLink,
                nextPageLink
            };

            Response.Headers.Add("Pagination", JsonSerializer.Serialize(metaData));

            return(new OkObjectResult(_mapper.Map <IEnumerable <BandDto> >(bandsFromRepo).ShapeData(bandResourceParameters.Fields)));
        }
Beispiel #4
0
        public IActionResult GetBands([FromQuery] BandsResourceParameters parameters)
        {
            if (!_propertyMappingService.ValidMappingExists <BandDto, Band>(parameters.OrderBy))
            {
                return(BadRequest());
            }

            if (!_propertyValidationService.HasValidProperties <BandDto>(parameters.Fields))
            {
                return(BadRequest());
            }

            PagedList <Band> bands = _bandAlbumRepository.GetBands(parameters);

            string previousPageLink = bands.HasPrevious ? CreateBandsUri(parameters, UriType.PreviousPage) : null;
            string nextPageLink     = bands.hasNext ? CreateBandsUri(parameters, UriType.NextPage) : null;

            var metaData = new
            {
                totalCount  = bands.TotalCount,
                pageSize    = bands.PageSize,
                currentPage = bands.CurrentPage,
                totalPages  = bands.TotalPages,
                previousPageLink,
                nextPageLink
            };

            Response.Headers.Add("Pagination", JsonSerializer.Serialize(metaData));

            return(Ok(_mapper.Map <IEnumerable <BandDto> >(bands).ShapeData(parameters.Fields)));
        }
Beispiel #5
0
        public ActionResult <IEnumerable <BandDto> > GetBands([FromQuery] BandsResourceParameters bandsResourceParameters)
        {
            var bandsFromRepo = _bandAlbumRepository.GetBands(bandsResourceParameters);


            var previousPageLink = bandsFromRepo.HasPrevious ?
                                   CreateBandsUri(bandsResourceParameters, UriType.PreviousPage) : null;

            var nextPageLink = bandsFromRepo.HasNext ?
                               CreateBandsUri(bandsResourceParameters, UriType.NextPage) : null;

            var metaData = new
            {
                totalCount       = bandsFromRepo.TotalCount,
                pageSize         = bandsFromRepo.PageSize,
                currentPage      = bandsFromRepo.CurrentPage,
                totalPages       = bandsFromRepo.TotalPages,
                previousPageLink = previousPageLink,
                nextPageLink     = nextPageLink
            };

            Response.Headers.Add("Pagination", JsonSerializer.Serialize(metaData));


            return(Ok(_mapper.Map <IEnumerable <BandDto> >(bandsFromRepo)));
        }
        [HttpHead]                                                                               // return the infomation of the server (infomation in the header) to client
        public IActionResult GetBands([FromQuery] BandResourceParameters bandResourceParameters) // It will automatically map to the query strings?
        {
            if (!_propertyMappingService.ValidMappingExists <BandDto, Band>(bandResourceParameters.OrderBy))
            {
                return(BadRequest());
            }

            if (!_propertyValidationService.HasValidProperties <BandDto>(bandResourceParameters.Fields))
            {
                return(BadRequest());
            }

            var bandsFromRepo = _bandAlbumRepository.GetBands(bandResourceParameters);

            var previousPagePageLink = bandsFromRepo.HasPrevious ? CreateBandsUri(bandResourceParameters, UriType.PreviousPage) : null;

            var nextPageLink = bandsFromRepo.HasNext ? CreateBandsUri(bandResourceParameters, UriType.NextPage) : null;

            var metaData = new
            {
                totalCount  = bandsFromRepo.TotalCount,
                pageSize    = bandsFromRepo.PageSize,
                currentPage = bandsFromRepo.CurrentPage,
                totalPages  = bandsFromRepo.TotalPages,
                previousPagePageLink,
                nextPageLink,
            };

            Response.Headers.Add("Pagination", JsonSerializer.Serialize(metaData));                                   // Adding the Pagination Header to the Response

            return(Ok(_mapper.Map <IEnumerable <BandDto> >(bandsFromRepo).ShapeData(bandResourceParameters.Fields))); // Serialise the Data to JSON
        }
Beispiel #7
0
        public ActionResult <IEnumerable <BandDto> > GetBands([FromQuery] BandsResourceParameters bandsResourceParameters)
        {
            var bandRepo = _bandAlbumRepository.GetBands(bandsResourceParameters);
            var bandsDto = new List <BandDto>();

            return(Ok(_mapper.Map <IEnumerable <BandDto> >(bandRepo)));
        }
Beispiel #8
0
        public IActionResult GetBands(
            [FromQuery] BandsResourceParameters bandsResourceParameters)
        {
            if (!_propertyMappingService.ValidMappingExists <BandDto, Entities.Band>
                    (bandsResourceParameters.OrderBy))
            {
                return(BadRequest());
            }

            if (!_propertyValidationService.HasValidProperties <BandDto>
                    (bandsResourceParameters.Fields))
            {
                return(BadRequest());
            }

            var bandsFromRepo = _bandAlbumRepository.GetBands(bandsResourceParameters);

            var metaData = new
            {
                totalCount  = bandsFromRepo.TotalCount,
                pageSize    = bandsFromRepo.PageSize,
                currentPage = bandsFromRepo.CurrentPage,
                totalPages  = bandsFromRepo.TotalPages
            };

            Response.Headers.Add("Pagination", JsonSerializer.Serialize(metaData));

            var links       = CreateLinksForBands(bandsResourceParameters, bandsFromRepo.HasNext, bandsFromRepo.HasPrevious);
            var shapedBands = _mapper.Map <IEnumerable <BandDto> >(bandsFromRepo)
                              .ShapeData(bandsResourceParameters.Fields);

            var shapedBandsWithLinks = shapedBands.Select(band =>
            {
                var bandAsDictionary = band as IDictionary <string, object>;
                var bandLinks        = CreateLinksForBand((Guid)bandAsDictionary["Id"], null);
                bandAsDictionary.Add("links", bandLinks);
                return(bandAsDictionary);
            });

            var linkedCollectionResource = new
            {
                value = shapedBandsWithLinks,
                links
            };

            return(Ok(linkedCollectionResource));
        }
Beispiel #9
0
        public ActionResult <IEnumerable <BandDTO> > GetBandCollection([FromRoute]
                                                                       [ModelBinder(BinderType = typeof(ArrayModelBinder))] IEnumerable <Guid> ids)
        {
            if (ids == null)
            {
                return(BadRequest());
            }
            var bandEntities = _bandAlbumRepository.GetBands(ids);

            if (ids.Count() != bandEntities.Count())
            {
                return(NotFound());
            }
            IEnumerable <BandDTO> bandsForReturn = _mapper.Map <IEnumerable <BandDTO> >(bandEntities);

            return(Ok(bandsForReturn));
        }
Beispiel #10
0
        public ActionResult <IEnumerable <BandDto> > GetBands()
        {
            var bandsFromRepo = _bandAlbumRepository.GetBands();
            var bandsDto      = new List <BandDto>();

            //foreach(var band in bandsFromRepo)
            //{
            //    bandsDto.Add(new BandDto()
            //    {
            //        Id = band.Id,
            //        Name = band.Name,
            //        MainGenre = band.MainGenre,
            //        FoundedYearsAgo = $"{band.Founded.ToString("yyyy")} ({band.Founded.GetYearsAgo()} years ago)"
            //    });
            //}
            return(Ok(_mapper.Map <IEnumerable <BandDto> >(bandsFromRepo)));
        }
        public IActionResult GetBands([FromQuery] BandResourceParameter bandParamter)
        {
            var bandsFromRepo = _repo.GetBands(bandParamter);

            //به جای استفاده از این همه کد و تکرار کد در متدهای دیگر از روش auto mapper استفاده می کنیم
            //var bandDto = new List<BandDto>();
            //foreach (var item in bandsFromRepo)
            //{
            //    bandDto.Add(new BandDto()
            //    {
            //        BandId=item.BandId,
            //        Name=item.Name,
            //        MainGenre=item.MainGenre,
            //        FoundedYearAgo=$"{item.Founded.ToString("yyyy")} ({item.Founded.GetYearAgo()} years ago)"
            //    });
            //}
            return(Ok(_mapper.Map <IEnumerable <BandDto> >(bandsFromRepo)));//create map to banddto
        }
Beispiel #12
0
        public IActionResult GetBands()
        {
            //first need to go to repository and get all the bands. However, we want to return BandDto.
            var bandsFromRepo = _bandAlbumRepository.GetBands();
            var bandsDto      = new List <BandDto>();

            //now we need to constructor the bandsDto

            //foreach (var band in bandsFromRepo)
            //{
            //    bandsDto.Add(new BandDto()
            //    {
            //        Id = band.Id,
            //        Name = band.Name,
            //        MainGenre = band.MainGenre,
            //        FoundedYearsAgo = $"{band.Founded.ToString("yyyy")} ({band.Founded.GetYearsAgo()} years ago)"
            //    });
            // }

            return(Ok());
        }
        public IActionResult GetBands([FromQuery] string mainGenre, [FromQuery] string searchQuery)
        {
            var bands = _bandAlbumRepository.GetBands(mainGenre, searchQuery);

            //var bandsDto = new List<BandDto>();

            //foreach(var band in bands)
            //{
            //    bandsDto.Add(new BandDto
            //    {
            //        Id = band.Id,
            //        Name = band.Name,
            //        MainGenre = band.MainGenre,
            //        FoundedYearsAgo = $"{band.Founded.GetYearsAgo()} years ago."
            //    });
            //}

            //return Ok(bandsDto);

            return(Ok(_mapper.Map <IEnumerable <BandDto> >(bands)));
        }
        public ActionResult <IEnumerable <BandDTO> > GetBands([FromQuery] BandsResourceParameters bandsResourceParameters)
        {
            var bandsFromRepo = _bandAlbumRepository.GetBands(bandsResourceParameters);

            return(Ok(_mapper.Map <IEnumerable <BandDTO> >(bandsFromRepo)));

            //throw new Exception("testing exceptions");

            //var bandsDTO = new List<BandDTO>();

            //foreach(var band in bandsFromRepo)
            //{
            //    bandsDTO.Add(new BandDTO()
            //    {
            //        Id = band.Id,
            //        Name = band.Name,
            //        MainGenre = band.MainGenre,
            //        FoundedYearsAgo = $"{band.Founded.ToString("yyyy")} ({band.Founded.GetYearsAgo()} years ago)"
            //    });
            //}
            //return Ok(BandDTO);
        }
Beispiel #15
0
        public IActionResult GetBands([FromQuery] QueryParameters queryParameters)
        {
            var bands = _bandAlbumRepository.GetBands(queryParameters);

            var nextPageLink     = bands.HasNext ? CreateUri(UriType.NextPage, queryParameters) : null;
            var previousPageLink = bands.HasPrevious ? CreateUri(UriType.PreviousPage, queryParameters) : null;

            var metaData = new
            {
                bands.TotalItems,
                bands.PageSize,
                bands.CurrentPage,
                bands.TotalPages,
                previousPageLink,
                nextPageLink
            };

            Response.Headers.Add("Pagination", JsonConvert.SerializeObject(metaData));

            var bandsDto = _mapper.Map <IEnumerable <BandDto> >(bands);

            return(StatusCode(StatusCodes.Status200OK, bandsDto));
        }
Beispiel #16
0
        public ActionResult <IEnumerable <BandDto> > GetCollectionOfBands(
            [FromQuery][ModelBinder(typeof(CustomModelBinder))]
            IEnumerable <Guid> ids)
        {
            if (ids == null)
            {
                ModelState.AddModelError("invalid ids", "ids can not be empty");
                return(BadRequest(ModelState));
            }

            var bandIds = ids.ToArray();

            var bands = _bandAlbumRepository.GetBands(bandIds);

            if (bands.Count() != bandIds.Count())
            {
                return(NotFound());
            }

            var bandsDto = _mapper.Map <IEnumerable <BandDto> >(bands);

            return(Ok(bandsDto));
        }
Beispiel #17
0
        public ActionResult <IEnumerable <Band_Dto> > GetBands([FromQuery] BandsResourceParameters bandsResourceParameters)
        {
            var bandsFromRepo = _bandAlbumRepository.GetBands(bandsResourceParameters);

            //var bandsDto = new List<Band_Dto>();

            //foreach (var b in bandsFromRepo)
            //{
            //    bandsDto.Add(new Band_Dto()
            //    {
            //        Id = b.Id,
            //        Name = b.Name,
            //        MainGenre = b.MainGenre,
            //        FoundedYearsAgo = $"{b.Founded.ToString("yyyy")} ({b.Founded.GetYearsAgo()} years ago)"

            //    });
            //}

            //return new JsonResult(bandsFromRepo);
            //return new JsonResult(bandsDto);

            return(Ok(_mapper.Map <IEnumerable <Band_Dto> >(bandsFromRepo)));
        }
Beispiel #18
0
        public IActionResult GetBands1()
        {
            var bandsFromRepo = _bandAlbumRepository.GetBands();

            return(Ok(bandsFromRepo));
        }
Beispiel #19
0
        public IActionResult GetBands()
        {
            var bandRepo = _bandAlbumRepository.GetBands();

            return(new JsonResult(bandRepo));
        }
        public ActionResult <IEnumerable <BandDto> > GetBands([FromQuery] BandResourceParameter bandResourceParameter)
        {
            var v = _bandAlbumRepository.GetBands(bandResourceParameter);

            return(Ok(_mapper.Map <List <BandDto> >(v)));
        }