using System.Threading.Tasks;
using Abp.Domain.Repositories;
using Abp.UI;
using YGNT.Infrastructure.Extension;

namespace YGNT.QuestionLibrary.Core.Disciplines.Domain
{
    public class DisciplineManager : IDisciplineManager
    {
        private readonly IRepository<Discipline> _disciplineRepository;

        public DisciplineManager(IRepository<Discipline> disciplineRepository)
        {
            _disciplineRepository = disciplineRepository;
        }

        /// <summary>
        /// 检查学科名称
        /// </summary>
        /// <param name="name"></param>
        /// <param name="educationCategoryId"></param>
        /// <returns></returns>
        public async Task CheckNameAsync(string name, int educationCategoryId)
        {
            var isExist = await _disciplineRepository
                .AnyAsync(x => x.GradeId == educationCategoryId && x.Name == name);
            if (isExist)
                throw new UserFriendlyException($"学科名称:{name}已被占用.");

        }
    }
}