public async Task <IOperationResult <Subject> > RemoveSubject(int subjectId)
        {
            Subject subject = await _subjectRepository.Set.FindAsync(subjectId);

            if (subject == null)
            {
                return(BasicOperationResult <Subject> .Fail("Subject not found"));
            }

            var tutorRelations = await _tutorSubjectRepository.FindAll(ts => ts.SubjectId == subjectId);

            _tutorSubjectRepository.Set.RemoveRange(tutorRelations);
            await _tutorSubjectRepository.Save();

            _subjectRepository.Remove(subject);
            await _subjectRepository.Save();

            return(BasicOperationResult <Subject> .Ok(subject));
        }
        public async Task <IOperationResult <bool> > AssignSubjectToTutors(int tutorId, IEnumerable <int> subjectIds)
        {
            var tutor = await _userRepository.Find(u => u.Id == tutorId &&
                                                   u.UserRoles.Any(r => r.RoleId == (int)RoleTypes.Tutor),
                                                   u => u.UserRoles);

            if (tutor == null)
            {
                return(BasicOperationResult <bool> .Fail("El tutor no fue encontrado"));
            }

            bool subjectExists = await CheckIfSubjectIdsExists(subjectIds);

            if (!subjectExists)
            {
                return(BasicOperationResult <bool> .Fail("Revise que todas las materias que esta enviando, están registradas en el sistema"));
            }

            var tutorSubjects = await GetSubjectsForTutor(tutorId);

            var tutorSubjectIds = tutorSubjects.Select(s => s.Id);

            var idOfSubjectsToRemove = GetIdsThatHaveToBeRemoved(tutorSubjectIds, subjectIds);
            var idsOfSubjectsToAdd   = GetIdsThatHaveToBeAdded(tutorSubjectIds, subjectIds);

            var tutorSubjecsToRemove = await _tutorSubjectRepository.FindAll(ts =>
                                                                             idOfSubjectsToRemove.Contains(ts.SubjectId) && ts.TutorId == tutorId);

            _tutorSubjectRepository.Set.RemoveRange(tutorSubjecsToRemove);

            var tutorSubjectsToAdd = idsOfSubjectsToAdd.Select(id => new TutorSubject
            {
                SubjectId = id,
                TutorId   = tutorId
            });

            await _tutorSubjectRepository.Set.AddRangeAsync(tutorSubjectsToAdd);

            await _tutorSubjectRepository.Save();

            return(BasicOperationResult <bool> .Ok(true));
        }