Exemplo n.º 1
0
        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));
        }