public IActionResult GetHateoasUserList(ResourceParameter resourceParameter)
        {
            var skip      = (resourceParameter.PageNumber > 0) ? resourceParameter.PageNumber - 1 : 0;
            var userList  = Mapper.Map <IEnumerable <UserDto> >(this.usersServices.GetUsersList(skip, resourceParameter.PageSize));
            var pagedList = PagedList <UserDto> .Create(
                userList,
                resourceParameter.PageNumber,
                resourceParameter.PageSize);

            var previousPageLink = pagedList.HasPrevious
                ? this.CreateUserResourceUri(resourceParameter, ResourceUriType.PreviousPage)
                : null;
            var nextPageLink = pagedList.HasNext
                ? this.CreateUserResourceUri(resourceParameter, ResourceUriType.NextPage)
                : null;

            var paginationMetadata = new PaginationMetadata(
                pagedList.TotalCount,
                pagedList.PageSize,
                pagedList.CurrentPage,
                pagedList.TotalPages,
                previousPageLink,
                nextPageLink);

            // add links on each retrieved user
            userList = userList.Select(user => this.CreateLinksForUser(user));

            var wrapper = new LinkedCollectionResourceWrapperDto <UserDto>(userList);

            return(this.Ok(this.CreateLinksForUser(wrapper)));
        }
Example #2
0
        public async Task <LinkedCollectionResourceWrapperDto <CohortGroupDetailDto> > Handle(CohortGroupsDetailQuery message, CancellationToken cancellationToken)
        {
            var pagingInfo = new PagingInfo()
            {
                PageNumber = message.PageNumber,
                PageSize   = message.PageSize
            };

            var orderby = Extensions.GetOrderBy <CohortGroup>(message.OrderBy, "asc");

            var pagedCohortGroupsFromRepo = await _cohortGroupRepository.ListAsync(pagingInfo, null, orderby, new string[] { "Condition", "CohortGroupEnrolments" });

            if (pagedCohortGroupsFromRepo != null)
            {
                // Map EF entity to Dto
                var mappedCohortGroups = PagedCollection <CohortGroupDetailDto> .Create(_mapper.Map <PagedCollection <CohortGroupDetailDto> >(pagedCohortGroupsFromRepo),
                                                                                        pagingInfo.PageNumber,
                                                                                        pagingInfo.PageSize,
                                                                                        pagedCohortGroupsFromRepo.TotalCount);

                // Add HATEOAS links to each individual resource
                mappedCohortGroups.ForEach(dto => CreateLinks(dto));

                var wrapper = new LinkedCollectionResourceWrapperDto <CohortGroupDetailDto>(pagedCohortGroupsFromRepo.TotalCount, mappedCohortGroups, pagedCohortGroupsFromRepo.TotalPages);

                CreateLinksForCohortGroups(wrapper, message.OrderBy, message.PageNumber, message.PageSize,
                                           pagedCohortGroupsFromRepo.HasNext, pagedCohortGroupsFromRepo.HasPrevious);

                return(wrapper);
            }

            return(null);
        }
Example #3
0
        public IActionResult GetBooksForAuthor(Guid authorId,
                                               [FromHeader(Name = "Accept")] string mediaType)
        {
            if (!_libraryRepository.AuthorExists(authorId))
            {
                return(NotFound());
            }

            var booksForAuthorFromRepo = _libraryRepository.GetBooksForAuthor(authorId);

            var booksForAuthor = Mapper.Map <IEnumerable <BookDto> >(booksForAuthorFromRepo);


            if (mediaType == "application/vnd.mauricio.hateoas+json")
            {
                booksForAuthor = booksForAuthor.Select(book =>
                {
                    book = CreateLinksForBook(book);
                    return(book);
                });

                var wrapper = new LinkedCollectionResourceWrapperDto <BookDto>(booksForAuthor);

                return(Ok(CreateLinksForBooks(wrapper)));
            }
            else
            {
                return(Ok(booksForAuthor));
            }
        }
Example #4
0
        public IActionResult GetBooksForAuthor(Guid authorId)
        {
            if (!_libraryRepository.AuthorExists(authorId))
            {
                return(NotFound());
            }

            var booksForAuthorFromRepo = _libraryRepository.GetBooksForAuthor(authorId);

            if (booksForAuthorFromRepo == null)
            {
                return(NotFound());
            }

            var booksForAuthor = Mapper.Map <IEnumerable <BookDto> >(booksForAuthorFromRepo);

            booksForAuthor = booksForAuthor.Select(b => {
                b = CreateLinksForBook(b);
                return(b);
            });

            var wrapper = new LinkedCollectionResourceWrapperDto <BookDto>(booksForAuthor);

            _logger.LogInformation(200, $"Author books with {authorId} are succesfully return.");
            return(Ok(CreateLinksForBooks(wrapper)));
        }
        public IActionResult GetBooksForAuthor(Guid authorId)
        {
            // check if the author exists
            if (!_libraryRepository.AuthorExists(authorId))
            {
                return(NotFound());
            }

            // fetch books for author
            var booksForAuthorFromRepo = _libraryRepository.GetBooksForAuthor(authorId);

            // map to book DTO
            var booksForAuthor = Mapper.Map <IEnumerable <BookDto> >(booksForAuthorFromRepo);

            // create the links for all books
            booksForAuthor = booksForAuthor.Select(book =>
            {
                book = CreateLinksForBook(book);
                return(book);
            });

            var wrapper = new LinkedCollectionResourceWrapperDto <BookDto>(booksForAuthor);

            return(Ok(CreateLinksForBooks(wrapper)));
        }
        public async Task <LinkedCollectionResourceWrapperDto <FacilityIdentifierDto> > Handle(FacilitiesIdentifierQuery message, CancellationToken cancellationToken)
        {
            var pagingInfo = new PagingInfo()
            {
                PageNumber = message.PageNumber,
                PageSize   = message.PageSize
            };

            var orderby = Extensions.GetOrderBy <Facility>(message.OrderBy, "asc");

            var pagedFacilitiesFromRepo = await _facilityRepository.ListAsync(pagingInfo, null, orderby, "");

            if (pagedFacilitiesFromRepo != null)
            {
                // Map EF entity to Dto
                var mappedFacilities = PagedCollection <FacilityIdentifierDto> .Create(_mapper.Map <PagedCollection <FacilityIdentifierDto> >(pagedFacilitiesFromRepo),
                                                                                       pagingInfo.PageNumber,
                                                                                       pagingInfo.PageSize,
                                                                                       pagedFacilitiesFromRepo.TotalCount);

                // Add HATEOAS links to each individual resource
                mappedFacilities.ForEach(dto => CreateLinks(dto));

                var wrapper = new LinkedCollectionResourceWrapperDto <FacilityIdentifierDto>(pagedFacilitiesFromRepo.TotalCount, mappedFacilities, pagedFacilitiesFromRepo.TotalPages);

                CreateLinksForFacilities(wrapper, message.OrderBy, message.PageNumber, message.PageSize,
                                         pagedFacilitiesFromRepo.HasNext, pagedFacilitiesFromRepo.HasPrevious);

                return(wrapper);
            }

            return(null);
        }
Example #7
0
        public IActionResult GetBooksForAuthor(Guid authorId, [FromHeader(Name = "Accept")] string mediaType)
        {
            if (!_authorAppService.AuthorExists(authorId))
            {
                return(NotFound());
            }

            var booksForAuthor = _bookAppService.GetBooksByAuthorId(authorId);

            if (mediaType == "application/vnd.tmaturano.hateoas+json")
            {
                //HATEOAS we need to create a link for each group
                booksForAuthor = booksForAuthor.Select(book =>
                {
                    book = CreateLinksForBook(book);
                    return(book);
                });

                var wrapper = new LinkedCollectionResourceWrapperDto <BookOutputDto>(booksForAuthor);
                return(Ok(CreateLinksForBooks(wrapper)));
            }
            else
            {
                return(Ok(booksForAuthor));
            }
        }
        public IActionResult GetSpotsInCity(SpotResourceParameters spotResourceParameters)
        {
            try
            {
                _logger.LogTrace($"Getting list of spotfs for city id : {spotResourceParameters.cityId} with search parameter {spotResourceParameters.SearchQuery} and type = {spotResourceParameters.Type}");

                var spotsFromRepo = _cityInfoRepository.GetSpotsForCity(spotResourceParameters);

                if (!spotsFromRepo.Any())
                {
                    _logger.LogInformation($"City Id {spotResourceParameters.cityId} is not exist");
                    return(NotFound());
                }

                var spots = Mapper.Map <IEnumerable <SpotDto> >(spotsFromRepo);

                spots = spots.Select(spot =>
                {
                    spot = CreateLinksForSpot(spot);
                    return(spot);
                });

                var wrapper = new LinkedCollectionResourceWrapperDto <SpotDto>(spots);

                return(Ok(CreateLinksForSpots(wrapper)));
            }
            catch (Exception e)
            {
                _logger.LogError($"Error on getting sports for city : {spotResourceParameters.cityId}");
                _logger.LogError(e.ToString());
                throw;
            }
        }
        [HttpHead]  // Do not transport content/body in response only Returns 200 Status Code & Headers
        public IActionResult GetApplicationCourseCampuses(int applicationId)
        {
            if (!_applicationInfoRepository.ApplicationExists(applicationId))
            {
                return(NotFound());
            }
            var applicationCourseCampuses = _applicationInfoRepository.GetCourseCampusesForApplication(applicationId);

            if (applicationCourseCampuses == null)
            {
                return(NotFound());
            }

            var results = Mapper.Map <IEnumerable <ApplicationCourseCampusDto> >(applicationCourseCampuses);

            #region CreateLinksForApplicationCourseCampuses => Supporting HATEOAS (Base and Wrapper Class Approach)
            results = results.Select(acc =>
            {
                acc = CreateLinksForApplicationCourseCampus(acc);
                return(acc);
            });

            var wrapper = new LinkedCollectionResourceWrapperDto <ApplicationCourseCampusDto>(results);
            #endregion

            //return Ok(results);
            return(Ok(CreateLinksForApplicationCourseCampuses(wrapper)));
        }
        public async Task <IActionResult> GetBooksForAuthor(Guid authorId)
        {
            if (!(await libraryRepository.AuthorExists(authorId)))
            {
                return(NotFound());
            }

            var booksForAuthorFromRepo = await libraryRepository.GetBooksForAuthor(authorId);

            var booksForAuthor = Mapper.Map <IEnumerable <BookDto> >(booksForAuthorFromRepo);

            // Iterate through our books collection and create links for each.
            booksForAuthor = booksForAuthor.Select(book =>
            {
                book = CreateLinksForBook(book);
                return(book);
            });

            // We wrap our books collection so that our author also has a collection
            // of links.
            var booksWrapper = new LinkedCollectionResourceWrapperDto <BookDto>(booksForAuthor);

            // We add our link to api/authors/{authorId}/books
            return(Ok(CreateLinksForBooks(booksWrapper)));
        }
Example #11
0
        public IActionResult GetBooksForAuthor(Guid authorId)
        {
            if (!_libRepository.AuthorExists(authorId))
            {
                return(NotFound());
            }

            var booksForAuthorFromRepo = _libRepository.GetBooksForAuthor(authorId);

            //if (books == null)
            //{
            //    return NotFound();
            //}

            var booksForAuthor = Mapper.Map <IEnumerable <BookDto> >(booksForAuthorFromRepo);

            //foreach (var book in booksForAuthor)
            //{
            //    CreateLinksForBook(book);
            //}

            booksForAuthor = booksForAuthor.Select(book =>
            {
                book = CreateLinksForBook(book);
                return(book);
            });

            var wrapper = new LinkedCollectionResourceWrapperDto <BookDto>(booksForAuthor);

            return(Ok(CreateLinksForBooks(wrapper)));
        }
        public async Task <LinkedCollectionResourceWrapperDto <FacilityTypeIdentifierDto> > Handle(FacilityTypesIdentifierQuery message, CancellationToken cancellationToken)
        {
            var pagingInfo = new PagingInfo()
            {
                PageNumber = message.PageNumber,
                PageSize   = message.PageSize
            };

            var orderby = Extensions.GetOrderBy <FacilityType>(message.OrderBy, "asc");

            var pagedFacilityTypesFromRepo = await _facilityTypeRepository.ListAsync(pagingInfo, null, orderby, "");

            if (pagedFacilityTypesFromRepo != null)
            {
                // Map EF entity to Dto
                var mappedFacilityTypes = PagedCollection <FacilityTypeIdentifierDto> .Create(_mapper.Map <PagedCollection <FacilityTypeIdentifierDto> >(pagedFacilityTypesFromRepo),
                                                                                              pagingInfo.PageNumber,
                                                                                              pagingInfo.PageSize,
                                                                                              pagedFacilityTypesFromRepo.TotalCount);

                var wrapper = new LinkedCollectionResourceWrapperDto <FacilityTypeIdentifierDto>(pagedFacilityTypesFromRepo.TotalCount, mappedFacilityTypes, pagedFacilityTypesFromRepo.TotalPages);

                return(wrapper);
            }

            return(null);
        }
Example #13
0
        private LinkedCollectionResourceWrapperDto <BookDto> CreateLinksForBooks(
            LinkedCollectionResourceWrapperDto <BookDto> booksWrapper)
        {
            booksWrapper.Links.Add(new LinkDto(_urlHelper.Link("GetBooksForAuthor", new { }), "self", "GET"));

            return(booksWrapper);
        }
        public async Task <LinkedCollectionResourceWrapperDto <PatientIdentifierDto> > Handle(PatientsIdentifierQuery message, CancellationToken cancellationToken)
        {
            var pagingInfo = new PagingInfo()
            {
                PageNumber = message.PageNumber,
                PageSize   = message.PageSize
            };

            var facilityId = await GetFacilityIdAsync(message.FacilityName);

            var custom = await GetCustomAsync(message.CustomAttributeId);

            var facilityIdParm         = new SqlParameter("@FacilityID", facilityId.ToString());
            var patientIdParm          = new SqlParameter("@PatientID", message.PatientId.ToString());
            var firstNameParm          = new SqlParameter("@FirstName", !String.IsNullOrWhiteSpace(message.FirstName) ? (Object)message.FirstName : DBNull.Value);
            var lastNameParm           = new SqlParameter("@LastName", !String.IsNullOrWhiteSpace(message.LastName) ? (Object)message.LastName : DBNull.Value);
            var dateOfBirthParm        = new SqlParameter("@DateOfBirth", message.DateOfBirth > DateTime.MinValue ? (Object)message.DateOfBirth : DBNull.Value);
            var customAttributeKeyParm = new SqlParameter("@CustomAttributeKey", !String.IsNullOrWhiteSpace(message.CustomAttributeValue) ? (Object)custom.attributeKey : DBNull.Value);
            var customPathParm         = new SqlParameter("@CustomPath", !String.IsNullOrWhiteSpace(message.CustomAttributeValue) ? (Object)custom.path : DBNull.Value);
            var customValueParm        = new SqlParameter("@CustomValue", !String.IsNullOrWhiteSpace(message.CustomAttributeValue) ? (Object)message.CustomAttributeValue : DBNull.Value);

            var patientsFromRepo = _context.PatientLists
                                   .FromSqlRaw <PatientList>($"EXECUTE spSearchPatients @FacilityID, @PatientId, @FirstName, @LastName, @DateOfBirth, @CustomAttributeKey, @CustomPath, @CustomValue"
                                                             , facilityIdParm
                                                             , patientIdParm
                                                             , firstNameParm
                                                             , lastNameParm
                                                             , dateOfBirthParm
                                                             , customAttributeKeyParm
                                                             , customPathParm
                                                             , customValueParm)
                                   .AsEnumerable();

            var pagedPatientsFromRepo = PagedCollection <PatientList> .Create(patientsFromRepo, pagingInfo.PageNumber, pagingInfo.PageSize);

            if (pagedPatientsFromRepo != null)
            {
                var mappedPatientsWithLinks = new List <PatientIdentifierDto>();

                foreach (var pagedPatient in pagedPatientsFromRepo)
                {
                    var mappedPatient = _mapper.Map <PatientIdentifierDto>(pagedPatient);
                    CreateLinks(mappedPatient);

                    mappedPatientsWithLinks.Add(mappedPatient);
                }

                var wrapper = new LinkedCollectionResourceWrapperDto <PatientIdentifierDto>(pagedPatientsFromRepo.TotalCount, mappedPatientsWithLinks, pagedPatientsFromRepo.TotalPages);

                CreateLinksForPatients(wrapper, message.OrderBy, message.FacilityName, message.PageNumber, message.PageSize,
                                       pagedPatientsFromRepo.HasNext, pagedPatientsFromRepo.HasPrevious);

                return(wrapper);
            }

            return(null);
        }
        private LinkedCollectionResourceWrapperDto <GameDto> CreateLinksForGames(LinkedCollectionResourceWrapperDto <GameDto> gameWrapper)
        {
            gameWrapper.Links.Add(
                new LinkDto(_urlHelper.Link("GetReviewdGames", new { }),
                            "self",
                            "GET"));

            return(gameWrapper);
        }
Example #16
0
 private LinkedCollectionResourceWrapperDto <AddressDto> CreateLinksForAddresses(
     LinkedCollectionResourceWrapperDto <AddressDto> addressesWrapper)
 {
     addressesWrapper.Links.Add(
         new LinkDto(_urlHelper.Link("GetAddressesForOrganization", new { })
                     , "self",
                     "GET"));
     return(addressesWrapper);
 }
        private LinkedCollectionResourceWrapperDto <ScoreDto> CreateLinksForScores(
            LinkedCollectionResourceWrapperDto <ScoreDto> scoresWrapper)
        {
            scoresWrapper.Links.Add(
                new LinkDto(_urlHelper.Link("GetScores", new { }),
                            "self",
                            "GET"));

            return(scoresWrapper);
        }
Example #18
0
        private LinkedCollectionResourceWrapperDto <BookDto> CreateLinksForBook(
            LinkedCollectionResourceWrapperDto <BookDto> booksWrapper)
        {
            booksWrapper.Links.Add(new LinkDto(
                                       href: _linkGenerator.GetUriByRouteValues(HttpContext, "GetBooksForAuthor", new { }),
                                       rel: "self",
                                       method: "GET"));

            return(booksWrapper);
        }
        private LinkedCollectionResourceWrapperDto <UserDto> CreateLinksForUser(
            LinkedCollectionResourceWrapperDto <UserDto> usersWrapper)
        {
            usersWrapper.Links.Add(
                new LinkDto(this.urlHelper.Link(nameof(this.GetHateoasUserList), new { }),
                            "self",
                            "GET"));

            return(usersWrapper);
        }
        private LinkedCollectionResourceWrapperDto <ApplicationCourseCampusDto> CreateLinksForApplicationCourseCampuses(
            LinkedCollectionResourceWrapperDto <ApplicationCourseCampusDto> applicationCourseCampusWrapper)
        {
            // link to self
            applicationCourseCampusWrapper.Links.Add(
                new LinkDto(_urlHelper.Link("GetApplicationCourseCampuses", new { }),
                            "self",
                            "GET"));

            return(applicationCourseCampusWrapper);
        }
        private LinkedCollectionResourceWrapperDto <SpotDto> CreateLinksForSpots(
            LinkedCollectionResourceWrapperDto <SpotDto> spotsWrapper)
        {
            //link to self
            spotsWrapper.Links.Add(
                new LinkDto(_urlHelper.Link("GetSpotsForCity", new { }),
                            "self",
                            "GET"));

            return(spotsWrapper);
        }
Example #22
0
        private LinkedCollectionResourceWrapperDto <AreaPostalCodeDto> CreateLinksForPostalCodes(
            LinkedCollectionResourceWrapperDto <AreaPostalCodeDto> postalCodesWrapper)
        {
            // link to self
            postalCodesWrapper.Links.Add(
                new LinkDto(_urlHelper.Link("GetPostalCodesForCountry", new { }),
                            "self",
                            "GET"));

            return(postalCodesWrapper);
        }
Example #23
0
        private LinkedCollectionResourceWrapperDto <BookDto> CreateLinksForBooks(LinkedCollectionResourceWrapperDto <BookDto> booksWrapper)
        {
            //Same concept, add links to itself, plus anything else you do to collection
            //link to itself
            booksWrapper.Links.Add(new LinkDto(
                                       _urlHelper.Link("GetBooks", new { }), //href
                                       "self",                               //rel
                                       "GET"));                              //method

            return(booksWrapper);
        }
Example #24
0
        private LinkedCollectionResourceWrapperDto <ProductDto> CreateLinks(
            LinkedCollectionResourceWrapperDto <ProductDto> productsWrapper)
        {
            productsWrapper.Links.Add(
                new LinkDto(
                    href: _urlHelper.Link("GetProductsForCompany", new { }),
                    rel: "self",
                    method: "GET"));

            return(productsWrapper);
        }
 /*
  * We add our link for api/author/{authorId}/books
  */
 private LinkedCollectionResourceWrapperDto <BookDto> CreateLinksForBooks(
     LinkedCollectionResourceWrapperDto <BookDto> booksWrapper)
 {
     // link to self
     // Don't need authorId since our urlHelper already knows about it,
     // but I added it for clarity. Could have just been new { }.
     booksWrapper.Links.Add(
         new LinkDto(urlHelper.Link("GetBooksForAuthor", new { authorId = booksWrapper.Value.First().AuthorId }),
                     "self",
                     "GET"));
     return(booksWrapper);
 }
        public async Task <LinkedCollectionResourceWrapperDto <CustomAttributeDetailDto> > Handle(CustomAttributesDetailQuery message, CancellationToken cancellationToken)
        {
            var pagingInfo = new PagingInfo()
            {
                PageNumber = message.PageNumber,
                PageSize   = message.PageSize
            };

            var orderby = Extensions.GetOrderBy <CustomAttributeConfiguration>(message.OrderBy, "asc");

            var predicate = PredicateBuilder.New <CustomAttributeConfiguration>(true);

            if (message.ExtendableTypeName != ExtendableTypeNames.All)
            {
                predicate = predicate.And(f => f.ExtendableTypeName == message.ExtendableTypeName.ToString());
            }
            if (message.CustomAttributeType != CustomAttributeTypes.All)
            {
                predicate = predicate.And(f => f.CustomAttributeType.ToString() == message.CustomAttributeType.ToString());
            }
            if (message.IsSearchable.HasValue)
            {
                predicate = predicate.And(f => f.IsSearchable == message.IsSearchable);
            }

            var pagedCustomAttributesFromRepo = await _CustomAttributeRepository.ListAsync(pagingInfo, predicate, orderby, "");

            if (pagedCustomAttributesFromRepo != null)
            {
                // Map EF entity to Dto
                var mappedCustomAttributes = PagedCollection <CustomAttributeDetailDto> .Create(_mapper.Map <PagedCollection <CustomAttributeDetailDto> >(pagedCustomAttributesFromRepo),
                                                                                                pagingInfo.PageNumber,
                                                                                                pagingInfo.PageSize,
                                                                                                pagedCustomAttributesFromRepo.TotalCount);

                // Add HATEOAS links to each individual resource
                foreach (var mappedCustomAttribute in mappedCustomAttributes)
                {
                    CreateSelectionValues(mappedCustomAttribute);
                    CreateLinks(mappedCustomAttribute);
                }

                var wrapper = new LinkedCollectionResourceWrapperDto <CustomAttributeDetailDto>(pagedCustomAttributesFromRepo.TotalCount, mappedCustomAttributes, pagedCustomAttributesFromRepo.TotalPages);

                CreateLinksForCustomAttributes(wrapper, message.OrderBy, message.PageNumber, message.PageSize,
                                               pagedCustomAttributesFromRepo.HasNext, pagedCustomAttributesFromRepo.HasPrevious);

                return(wrapper);
            }

            return(null);
        }
Example #27
0
        private LinkedCollectionResourceWrapperDto <BookDto> CreateLinksForBooks(LinkedCollectionResourceWrapperDto <BookDto> booksWrapper)
        {
            // link to self
            string getBooksForAuthorUrl = c_urHhelper.Link(
                "GetBooksForAuthor",
                new
            {
            });

            booksWrapper.Links.Add(new LinkDto(getBooksForAuthorUrl, "self", "GET"));

            return(booksWrapper);
        }
        public async Task <LinkedCollectionResourceWrapperDto <AdverseEventFrequencyReportDto> > Handle(AdverseEventFrequencyReportQuery message, CancellationToken cancellationToken)
        {
            var pagingInfo = new PagingInfo()
            {
                PageNumber = message.PageNumber,
                PageSize   = message.PageSize
            };

            if (message.FrequencyCriteria == FrequencyCriteria.Annual)
            {
                var results = await _patientQueries.GetAdverseEventsByAnnualAsync(message.SearchFrom, message.SearchTo);

                var pagedResults = PagedCollection <AdverseEventFrequencyReportDto> .Create(results, pagingInfo.PageNumber, pagingInfo.PageSize);

                var wrapper = new LinkedCollectionResourceWrapperDto <AdverseEventFrequencyReportDto>(pagedResults.TotalCount, pagedResults);
                CreateLinksForAdverseEventFrequencyReport(wrapper, message.PageNumber, message.PageSize,
                                                          pagedResults.HasNext, pagedResults.HasPrevious);

                return(wrapper);
            }

            if (message.FrequencyCriteria == FrequencyCriteria.Quarterly)
            {
                var results = await _patientQueries.GetAdverseEventsByQuarterAsync(message.SearchFrom, message.SearchTo);

                var pagedResults = PagedCollection <AdverseEventFrequencyReportDto> .Create(results, pagingInfo.PageNumber, pagingInfo.PageSize);

                var wrapper = new LinkedCollectionResourceWrapperDto <AdverseEventFrequencyReportDto>(pagedResults.TotalCount, pagedResults);
                CreateLinksForAdverseEventFrequencyReport(wrapper, message.PageNumber, message.PageSize,
                                                          pagedResults.HasNext, pagedResults.HasPrevious);

                return(wrapper);
            }

            if (message.FrequencyCriteria == FrequencyCriteria.Monthly)
            {
                var results = await _patientQueries.GetAdverseEventsByMonthAsync(message.SearchFrom, message.SearchTo);

                var pagedResults = PagedCollection <AdverseEventFrequencyReportDto> .Create(results, pagingInfo.PageNumber, pagingInfo.PageSize);

                var wrapper = new LinkedCollectionResourceWrapperDto <AdverseEventFrequencyReportDto>(pagedResults.TotalCount, pagedResults);
                CreateLinksForAdverseEventFrequencyReport(wrapper, message.PageNumber, message.PageSize,
                                                          pagedResults.HasNext, pagedResults.HasPrevious);

                return(wrapper);
            }

            return(null);
        }
Example #29
0
        private LinkedCollectionResourceWrapperDto <BookDto> CreateLinksForBooks(
            IEnumerable <BookDto> booksForAuthor)
        {
            var booksWrapper = new LinkedCollectionResourceWrapperDto <BookDto>(booksForAuthor);

            booksWrapper.Links.Add(
                new LinkDto
                (
                    new Uri(_urlHelper.Link(ApiNames.GetBooksForAuthor, new { })),
                    LinksMetadata.Self,
                    LinksMetadata.HttpGet)
                );

            return(booksWrapper);
        }
Example #30
0
        public ActionResult <LinkedCollectionResourceWrapperDto <MetaPageDetailDto> > GetMetaPagesByDetail(
            [FromQuery] IdResourceParameters metaResourceParameters)
        {
            if (!_typeHelperService.TypeHasProperties <MetaPageDetailDto>
                    (metaResourceParameters.OrderBy))
            {
                return(BadRequest());
            }

            var mappedMetaPagesWithLinks = GetMetaPages <MetaPageDetailDto>(metaResourceParameters);

            var wrapper = new LinkedCollectionResourceWrapperDto <MetaPageDetailDto>(mappedMetaPagesWithLinks.TotalCount, mappedMetaPagesWithLinks);

            return(Ok(wrapper));
        }