public Task <PagedCollection <Post> > Execute(PagedCollectionParameters parameters)
        {
            var collectionFactory = new PagedCollectionFactory <Post>(PlaceholderLink.ToCollection(_endpoint));

            return(collectionFactory.CreateFrom(
                       _context.Posts.ProjectToType <Post>(),
                       parameters.Offset ?? _defaultPagingParameters.Offset.Value,
                       parameters.Limit ?? _defaultPagingParameters.Limit.Value));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> GetPosts(string id, PagedCollectionParameters parameters)
        {
            var query = new GetPostsByUserQuery(_context, _defaultPagingOptions, Endpoint);
            var posts = await query.Execute(id, parameters);

            return(posts == null
                ? new NotFoundResult() as ActionResult
                : new ObjectResult(posts));
        }
Exemplo n.º 3
0
 public UsersController(
     BeautifulContext context,
     IOptions <PagedCollectionParameters> defaultPagingOptions,
     TypeAdapterConfig typeAdapterConfig)
 {
     _context = context;
     _defaultPagingOptions = defaultPagingOptions.Value;
     _typeAdapterConfig    = typeAdapterConfig;
 }
Exemplo n.º 4
0
        public async Task <IActionResult> Get(PagedCollectionParameters parameters)
        {
            var getAllQuery = new GetAllUsersQuery(_context, _defaultPagingOptions, Endpoint);
            var results     = await getAllQuery.Execute(parameters);

            // Attach form definitions for discoverability
            results.Forms = new[] { Form.FromModel <UserCreateModel>(Endpoint, "POST", "create-form") };

            return(new ObjectResult(results));
        }
 public GetAllPostsQuery(
     BeautifulContext context,
     PagedCollectionParameters defaultPagingParameters,
     TypeAdapterConfig typeAdapterConfig,
     string endpoint)
 {
     _context = context;
     _defaultPagingParameters = defaultPagingParameters;
     _typeAdapterConfig       = typeAdapterConfig;
     _endpoint = endpoint;
 }
        public async Task <PagedCollection <Post> > Execute(string userId, PagedCollectionParameters parameters)
        {
            var meta = PlaceholderLink.ToCollection(_endpoint, values: new { id = userId, link = PostsController.Endpoint });
            var collectionFactory = new PagedCollectionFactory <Post>(meta);

            var user = await _context.Users
                       .Where(x => x.Id == userId)
                       .SingleOrDefaultAsync();

            if (user == null)
            {
                return(null);
            }

            var query = _context.Posts
                        .Where(o => o.UserId == userId)
                        .ProjectToType <Post>(_typeAdapterConfig);

            return(await collectionFactory.CreateFrom(
                       query,
                       parameters.Offset ?? _defaultPagingParameters.Offset.Value,
                       parameters.Limit ?? _defaultPagingParameters.Limit.Value));
        }
 public GetAllUsersQuery(BeautifulContext context, PagedCollectionParameters defaultPagingParameters, string endpoint)
 {
     _context = context;
     _defaultPagingParameters = defaultPagingParameters;
     _endpoint = endpoint;
 }
Exemplo n.º 8
0
 public UsersController(BeautifulContext context, IOptions <PagedCollectionParameters> defaultPagingOptions)
 {
     _context = context;
     _defaultPagingOptions = defaultPagingOptions.Value;
 }