| | | 1 | | using Microsoft.EntityFrameworkCore; |
| | | 2 | | using OzonDomains.Models.AccessControl; |
| | | 3 | | using OzonRepositories.Context; |
| | | 4 | | |
| | | 5 | | namespace OzonRepositories.Data; |
| | | 6 | | |
| | | 7 | | public class AccessProfileRepository : MainRepository |
| | | 8 | | { |
| | 1 | 9 | | public AccessProfileRepository(ApplicationDbContext context) : base(context) |
| | | 10 | | { |
| | 1 | 11 | | } |
| | | 12 | | |
| | | 13 | | public async Task<List<AccessProfile>> GetAllAsync() |
| | | 14 | | { |
| | 0 | 15 | | return await _context.AccessProfiles |
| | 0 | 16 | | .Include(ap => ap.DataScopeSets) |
| | 0 | 17 | | .ToListAsync(); |
| | 0 | 18 | | } |
| | | 19 | | |
| | | 20 | | public async Task<AccessProfile?> GetByIdAsync(int id) |
| | | 21 | | { |
| | 1 | 22 | | return await _context.AccessProfiles |
| | 1 | 23 | | .Include(ap => ap.DataScopeSets) |
| | 1 | 24 | | .ThenInclude(s => s.Items) |
| | 1 | 25 | | .AsSplitQuery() |
| | 1 | 26 | | .FirstOrDefaultAsync(ap => ap.Id == id); |
| | 1 | 27 | | } |
| | | 28 | | |
| | | 29 | | public async Task<int> AddAsync(AccessProfile profile) |
| | | 30 | | { |
| | 0 | 31 | | _context.AccessProfiles.Add(profile); |
| | 0 | 32 | | return await _context.SaveChangesAsync(); |
| | 0 | 33 | | } |
| | | 34 | | |
| | | 35 | | public async Task<int> UpdateAsync(AccessProfile profile) |
| | | 36 | | { |
| | 0 | 37 | | _context.AccessProfiles.Update(profile); |
| | 0 | 38 | | return await _context.SaveChangesAsync(); |
| | 0 | 39 | | } |
| | | 40 | | |
| | | 41 | | public async Task<int> DeleteAsync(AccessProfile profile) |
| | | 42 | | { |
| | 0 | 43 | | _context.AccessProfiles.Remove(profile); |
| | 0 | 44 | | return await _context.SaveChangesAsync(); |
| | 0 | 45 | | } |
| | | 46 | | } |