Class BlogRepository
- Namespace
- Builvero.Infrastructure.Repositories
- Assembly
- Builvero.Infrastructure.dll
Repository implementation for blog post data access operations using Entity Framework Core.
public class BlogRepository : IBlogRepository
- Inheritance
-
BlogRepository
- Implements
- Inherited Members
Constructors
BlogRepository(ApplicationDbContext)
Initializes a new instance of the BlogRepository class.
public BlogRepository(ApplicationDbContext context)
Parameters
contextApplicationDbContextThe Entity Framework database context for data access.
Methods
CreateAsync(BlogPost, CancellationToken)
Creates a new blog post entity in the database.
public Task<BlogPost> CreateAsync(BlogPost blogPost, CancellationToken cancellationToken = default)
Parameters
blogPostBlogPostThe blog post entity to create.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
DeleteAsync(BlogPost, CancellationToken)
Deletes a blog post entity from the database.
public Task DeleteAsync(BlogPost blogPost, CancellationToken cancellationToken = default)
Parameters
blogPostBlogPostThe blog post entity to delete.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
- Task
- Repository implementation for blog post data access operations using Entity Framework Core.
GetAllAsync(bool, CancellationToken)
Retrieves all blog posts, optionally filtered by publication status.
public Task<List<BlogPost>> GetAllAsync(bool publishedOnly = false, CancellationToken cancellationToken = default)
Parameters
publishedOnlyboolIf true, returns only published posts; otherwise returns all posts.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
GetByIdAsync(Guid, CancellationToken)
Retrieves a blog post by its unique identifier.
public Task<BlogPost?> GetByIdAsync(Guid id, CancellationToken cancellationToken = default)
Parameters
idGuidThe unique identifier of the blog post to retrieve.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
GetBySlugAsync(string, CancellationToken)
Retrieves a blog post by its slug.
public Task<BlogPost?> GetBySlugAsync(string slug, CancellationToken cancellationToken = default)
Parameters
slugstringThe slug of the blog post to retrieve.
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
SlugExistsAsync(string, Guid?, CancellationToken)
Checks if a slug already exists in the database.
public Task<bool> SlugExistsAsync(string slug, Guid? excludeId = null, CancellationToken cancellationToken = default)
Parameters
slugstringThe slug to check.
excludeIdGuid?Optional blog post ID to exclude from the check (for updates).
cancellationTokenCancellationTokenCancellation token to cancel the operation.
Returns
UpdateAsync(BlogPost, CancellationToken)
Updates an existing blog post entity in the database.
public Task<BlogPost> UpdateAsync(BlogPost blogPost, CancellationToken cancellationToken = default)
Parameters
blogPostBlogPostThe blog post entity with updated values.
cancellationTokenCancellationTokenCancellation token to cancel the operation.