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

namespace YGNT.QuestionLibrary.Core.EducationCategories.Domain
{
    public class EducationCategoryManager : IEducationCategoryManager
    {
        private readonly IRepository<EducationCategory> _educationCategoryRepository;

        public EducationCategoryManager(IRepository<EducationCategory> educationCategoryRepository)
        {
            _educationCategoryRepository = educationCategoryRepository;
        }

        /// <summary>
        /// 检查名称是否被占用
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public async Task CheckNameAsync(string name)
        {
            var isExist = await _educationCategoryRepository.AnyAsync(x => x.Name == name);
            if (isExist)
                throw new UserFriendlyException($"教育类别名称:{name}已被占用.");
        }
    }
}