public IComandResult Handle(CreateCollaboratorComand comand) { if (_collaboratorRepository.CheckDocument(comand.Document)) { AddNotification("Document", "Esse documento já está cadastrado"); } if (_collaboratorRepository.CheckEmail(comand.Email)) { AddNotification("Email", "Esse email já está cadastrado"); } var name = new Name(comand.FirstName, comand.LastName); var document = new Document(comand.Document); var email = new Email(comand.Email); var address = new Address(comand.Street, comand.Number, comand.District, comand.City, comand.Country, comand.ZipCode); var phone = new Phone(comand.Phone); var collaborator = new Collaborator(name, document, email, phone, address, comand.Salary, comand.ProjectName, comand.BirthDate, comand.JobTitle); AddNotifications(collaborator); AddNotifications(name); AddNotifications(document); AddNotifications(email); AddNotifications(address); AddNotifications(phone); if (IsInvalid()) { return(null); } _collaboratorRepository.Save(collaborator); return(new CreateCollaboratorCommandResult(collaborator.Id, name.ToString(), email.Address)); }
public void Create(Collaborator collaborator) { if (collaborator == null) { throw new DomainException($@"Não foi informado um colaborador!"); } if (string.IsNullOrWhiteSpace(collaborator.Name)) { throw new DomainException($@"Não foi informado o nome do colaborador!"); } ICollection <Collaborator> collaborators = collaboratorRepository.Find(x => x.Name.ToUpper().Equals(collaborator.Name.ToUpper())); if (collaborators.Any(x => x.Actived)) { throw new DomainException($@"Já existe o colaborador {collaborator.Name}"); } collaborator.Enable(); collaboratorRepository.Save(collaborator); }