using System.Threading.Tasks;
using GxPress.Repository.Interface.Category;
using GxPress.Repository.Interface.Teacher;
using GxPress.Service.Interface.Teacher;

namespace GxPress.Service.Implement.Teacher
{
    public class TeacherService : ITeacherService
    {
        private readonly ICategoryRepository categoryRepository;
        private readonly ITeacherRepository teacherRepository;

        public TeacherService(ICategoryRepository categoryRepository, ITeacherRepository teacherRepository)
        {
            this.categoryRepository = categoryRepository;
            this.teacherRepository = teacherRepository;
        }

        public async Task<int> InsertAsync(Entity.tede2.Teacher.Teacher note)
        {
            note.CategoryName = await categoryRepository.GetCategoryParentAsync(note.CategoryId, note.CategoryName);
            return await teacherRepository.InsertAsync(note);
        }

        public async Task<bool> UpdateAsync(Entity.tede2.Teacher.Teacher note)
        {
            note.CategoryName = await categoryRepository.GetCategoryParentAsync(note.CategoryId, note.CategoryName);
            return await teacherRepository.UpdateAsync(note);
        }
    }
}