LMS.service/LMS.DAO/PermissionDAO/PermissionTypeDao.cs
2024-10-13 17:04:47 +08:00

56 lines
1.7 KiB
C#

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;
/// <summary>
/// 判断权限类型ID数组中的数据是不是都存在数据库中
/// </summary>
/// <param name="ids"></param>
/// <returns></returns>
public async Task<bool> CheckPermissionTypeIdsExist(List<string> ids)
{
foreach (var id in ids)
{
if (!await _context.PermissionType.AnyAsync(x => x.Id == id))
{
return false;
}
}
return true;
}
/// <summary>
/// 检查权限类型的Code是不是存在
/// </summary>
/// <param name="Code"></param>
/// <param name="Id"></param>
/// <returns></returns>
/// <exception cref="ArgumentNullException"></exception>
public async Task<bool> 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);
}
}
}
}