Spaces:
Running
Running
Download FlowAPI.Infrastructure/Repositories/GenericRepository.cs from DanilDrotik/FlowAPI: direct link, hf CLI and curl.
- Browser
- Download file 1.43 kB
-
https://huggingface.co/spaces/DanilDrotik/FlowAPI/resolve/ecea7e2cf65ddcb1a751ceab68c14ecad830aa29/FlowAPI.Infrastructure/Repositories/GenericRepository.cs
- Command line
-
hf download hf://spaces/DanilDrotik/FlowAPI@ecea7e2cf65ddcb1a751ceab68c14ecad830aa29/FlowAPI.Infrastructure/Repositories/GenericRepository.cs
-
curl -L -o GenericRepository.cs https://huggingface.co/spaces/DanilDrotik/FlowAPI/resolve/ecea7e2cf65ddcb1a751ceab68c14ecad830aa29/FlowAPI.Infrastructure/Repositories/GenericRepository.cs
1.43 kB
| using FlowAPI.Application.Interfaces; | |
| using FlowAPI.Infrastructure.Data; | |
| using Microsoft.EntityFrameworkCore; | |
| namespace FlowAPI.Infrastructure.Repositories | |
| { | |
| public class GenericRepository<T> : IGenericRepository<T> where T : class | |
| { | |
| protected readonly AppDbContext _context; | |
| protected readonly DbSet<T> _dbSet; | |
| public GenericRepository(AppDbContext context) | |
| { | |
| _context = context; | |
| _dbSet = context.Set<T>(); | |
| } | |
| public virtual async Task<IEnumerable<T>> GetAllAsync() | |
| { | |
| return await _dbSet.AsNoTracking().ToListAsync(); | |
| } | |
| public virtual async Task<T?> GetByIdAsync(Guid id) | |
| { | |
| return await _dbSet.FindAsync(id); | |
| } | |
| public virtual async Task<T> CreateAsync(T entity) | |
| { | |
| _dbSet.Add(entity); | |
| await _context.SaveChangesAsync(); | |
| return entity; | |
| } | |
| public virtual async Task<T> UpdateAsync(T entity) | |
| { | |
| _dbSet.Update(entity); | |
| await _context.SaveChangesAsync(); | |
| return entity; | |
| } | |
| public virtual async Task<bool> DeleteAsync(Guid id) | |
| { | |
| var entity = await _dbSet.FindAsync(id); | |
| if (entity is null) return false; | |
| _dbSet.Remove(entity); | |
| await _context.SaveChangesAsync(); | |
| return true; | |
| } | |
| } | |
| } | |