/
renix
/
TravelGuide
Обзор
Документация
Войти
/
renix
/
TravelGuide
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
back/Repositories/RoleRepository.cs
53 строки
1 KB
artem777764
Role Clean Architecture
02 апр 2025, 22:10
02 апр 2025, 22:10
80cdd38
Код
Авторство
О чём код?
using back.Interfaces; using back.Models; using back.Models.Entities; using Microsoft.EntityFrameworkCore; namespace back.Repositories; public class RoleRepository : IRepository<RoleEntity> { private readonly Context _dbContext; public RoleRepository(Context context) { _dbContext = context; } public async Task<int> AddAsync(RoleEntity entity) { await _dbContext.Roles.AddAsync(entity); await _dbContext.SaveChangesAsync(); return entity.Id; } public async Task<bool> DeleteAsync(int id) { RoleEntity? role = await _dbContext.Roles.FindAsync(id); if (role == null) return false; _dbContext.Roles.Remove(role); await _dbContext.SaveChangesAsync(); return true; } public async Task<List<RoleEntity>> GetAllAsync() { return await _dbContext.Roles.AsNoTracking().ToListAsync(); } public async Task<RoleEntity?> GetByIdAsync(int id) { return await _dbContext.Roles.FindAsync(id); } public async Task<bool> UpdateAsync(RoleEntity entity) { RoleEntity? currentRole = await _dbContext.Roles.FindAsync(entity.Id); if (currentRole == null) return false; _dbContext.Entry(currentRole).CurrentValues.SetValues(entity); await _dbContext.SaveChangesAsync(); return true; } }