public Domain.Entities.Professor Add(Domain.Entities.Professor entity) { if (entity == null) { throw new ArgumentNullException("Nenhuma informação de professor enviada"); } if (!_person.CheckIfExists(entity.Person)) { try { _person.Add(entity.Person); entity.PersonId = entity.Person.Id.Value; } catch (Exception ex) { entity.AddError(ex.Message); return(entity); } } if (entity.RelatedSubjects.Any()) { var validationResult = VerifyIfProfessorIsACurrentStudentFromClass(entity); if (validationResult.Errors.Any()) { entity.AddError(validationResult.Errors.ToArray()); return(entity); } } _professorRepository.Add(entity); return(entity); }
public ValidationResult Update(Domain.Entities.Professor entity) { if (entity.RelatedSubjects.Any()) { var validationResult = VerifyIfProfessorIsACurrentStudentFromClass(entity); if (validationResult.Errors.Any()) { entity.AddError(validationResult.Errors.ToArray()); return(entity); } } _professorRepository.Update(entity); return(new ValidationResult()); }