using Microsoft.EntityFrameworkCore; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using static LMS.Common.Enums.ResponseCodeEnum; namespace LMS.DAO.PermissionDAO { public class PermissionTypeDao(ApplicationDbContext context) { private readonly ApplicationDbContext _context = context; /// /// 判断权限类型ID数组中的数据是不是都存在数据库中 /// /// /// public async Task CheckPermissionTypeIdsExist(List ids) { foreach (var id in ids) { if (!await _context.PermissionType.AnyAsync(x => x.Id == id)) { return false; } } return true; } /// /// 检查权限类型的Code是不是存在 /// /// /// /// /// public async Task CheckPermissionTypeCodeExist(string Code, string Id = null) { if (string.IsNullOrWhiteSpace(Code)) { throw new ArgumentNullException(nameof(Code)); } if (string.IsNullOrWhiteSpace(Id)) { return await _context.PermissionType.AnyAsync(x => x.Code == Code); } else { return await _context.PermissionType.AnyAsync(x => x.Code == Code && x.Id != Id); } } } }