/
Airat
/
ASP.NET
Обзор
Документация
Войти
/
Airat
/
ASP.NET
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
EF/src/PromoCodeFactory.DataAccess/Repositories/EfRepository.cs
53 строки
1 KB
Айрат Измаилов
modified: EF/src/PromoCodeFactory.Core/Abstractions/Repositories/IRepository.cs
06 ноя 2024, 19:39
06 ноя 2024, 19:39
c4e3369
Код
Авторство
О чём код?
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Sqlite; using PromoCodeFactory.Core.Abstractions.Repositories; using PromoCodeFactory.Core.Domain; using PromoCodeFactory.DataAccess.Data; namespace PromoCodeFactory.DataAccess.Repositories { public class EfRepository<T> : IRepository<T> where T : BaseEntity { private AppDbContext _context; public EfRepository(AppDbContext context) { _context = context; } public async Task<IEnumerable<T>> GetAllAsync() { return await _context.Set<T>().ToListAsync(); } public async Task<T> GetByIdAsync(Guid id) { return await _context.Set<T>().FirstOrDefaultAsync(x => x.Id == id); } public async Task AddAsync(T entity) { await _context.Set<T>().AddAsync(entity); await _context.SaveChangesAsync(); } public async Task UpdateAsync(T entity) { await _context.SaveChangesAsync(); } public async Task DeleteAsync(T entity) { _context.Set<T>().Remove(entity); await _context.SaveChangesAsync(); } } }