main
|
Last change
on this file since 99c1e45 was 99c1e45, checked in by kikisrbinoska <srbinoskakristina07@…>, 11 days ago |
|
Fixed writer section and admin management
|
-
Property mode
set to
100644
|
|
File size:
1.3 KB
|
| Line | |
|---|
| 1 | using ChapterX.Domain.Entities;
|
|---|
| 2 | using ChapterX.Domain.Repositories;
|
|---|
| 3 | using ChapterX.Infrastructure.Data.DataContext;
|
|---|
| 4 | using System;
|
|---|
| 5 | using System.Collections.Generic;
|
|---|
| 6 | using System.Linq;
|
|---|
| 7 | using System.Text;
|
|---|
| 8 | using System.Threading.Tasks;
|
|---|
| 9 |
|
|---|
| 10 | using Microsoft.EntityFrameworkCore;
|
|---|
| 11 |
|
|---|
| 12 | namespace ChapterX.Infrastructure.Repositories
|
|---|
| 13 | {
|
|---|
| 14 | public class ChapterRepository : GenericRepository<Chapter>, IChapterRepository
|
|---|
| 15 | {
|
|---|
| 16 | public ChapterRepository(ApplicationDbContext context) : base(context)
|
|---|
| 17 | {
|
|---|
| 18 | }
|
|---|
| 19 |
|
|---|
| 20 | public async Task<IEnumerable<Chapter>> GetByStoryIdAsync(int storyId, CancellationToken cancellationToken = default)
|
|---|
| 21 | {
|
|---|
| 22 | return await _dbSet
|
|---|
| 23 | .Where(c => c.StoryId == storyId)
|
|---|
| 24 | .ToListAsync(cancellationToken);
|
|---|
| 25 | }
|
|---|
| 26 |
|
|---|
| 27 | public async Task<Chapter?> GetByIdWithStoryAsync(int id, CancellationToken cancellationToken = default)
|
|---|
| 28 | {
|
|---|
| 29 | return await _dbSet
|
|---|
| 30 | .Include(c => c.Story)
|
|---|
| 31 | .FirstOrDefaultAsync(c => c.Id == id, cancellationToken);
|
|---|
| 32 | }
|
|---|
| 33 |
|
|---|
| 34 | public async Task IncrementViewCountAsync(int id, CancellationToken cancellationToken = default)
|
|---|
| 35 | {
|
|---|
| 36 | await _dbSet
|
|---|
| 37 | .Where(c => c.Id == id)
|
|---|
| 38 | .ExecuteUpdateAsync(s => s.SetProperty(c => c.ViewCount, c => c.ViewCount + 1), cancellationToken);
|
|---|
| 39 | }
|
|---|
| 40 | }
|
|---|
| 41 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.