Table of Contents

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

context ApplicationDbContext

The 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

blogPost BlogPost

The blog post entity to create.

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

Task<BlogPost>

The created blog post entity with generated ID and timestamps.

DeleteAsync(BlogPost, CancellationToken)

Deletes a blog post entity from the database.

public Task DeleteAsync(BlogPost blogPost, CancellationToken cancellationToken = default)

Parameters

blogPost BlogPost

The blog post entity to delete.

cancellationToken CancellationToken

Cancellation 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

publishedOnly bool

If true, returns only published posts; otherwise returns all posts.

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

Task<List<BlogPost>>

A list of blog posts ordered by creation date (newest first).

GetByIdAsync(Guid, CancellationToken)

Retrieves a blog post by its unique identifier.

public Task<BlogPost?> GetByIdAsync(Guid id, CancellationToken cancellationToken = default)

Parameters

id Guid

The unique identifier of the blog post to retrieve.

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

Task<BlogPost>

The blog post entity if found; otherwise, null.

GetBySlugAsync(string, CancellationToken)

Retrieves a blog post by its slug.

public Task<BlogPost?> GetBySlugAsync(string slug, CancellationToken cancellationToken = default)

Parameters

slug string

The slug of the blog post to retrieve.

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

Task<BlogPost>

The blog post entity if found; otherwise, null.

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

slug string

The slug to check.

excludeId Guid?

Optional blog post ID to exclude from the check (for updates).

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

Task<bool>

True if the slug exists; otherwise, false.

UpdateAsync(BlogPost, CancellationToken)

Updates an existing blog post entity in the database.

public Task<BlogPost> UpdateAsync(BlogPost blogPost, CancellationToken cancellationToken = default)

Parameters

blogPost BlogPost

The blog post entity with updated values.

cancellationToken CancellationToken

Cancellation token to cancel the operation.

Returns

Task<BlogPost>

The updated blog post entity.