public async Task <ICommandResult> Handler(CreateHospitalCommand command) { var isDocument = await _hospitalRepository.DocumentExists(command.CNPJ); if (isDocument) { return(new GenericCommandResult(false, "Ops, já temos um Hospital cadastrado com esse CNPJ", command.Notifications)); } command.Validate(); if (command.Invalid) { return(new GenericCommandResult(false, "Ops, CNPJ inválido!", command.Notifications)); } var address = new Address(command.Street, command.Number, command.State, command.City, command.Country, command.ZipCode); var document = new Document(command.CNPJ, EDocumentType.CNPJ); var hospital = new Hospital(command.Name, document, address); await _addressRepositoty.Create(address); await _hospitalRepository.Create(hospital); return(new GenericCommandResult(true, "Hospital cadastrado", hospital)); }
public async Task <ICommandExit> Handler(CreateHospitalCommand command) { Hospital hospital = new Hospital(command.Name, command.CNPJ, command.State, command.City, command.Number, command.Complement, command.Neighborhood); if (Invalid) { return(new CommandExit(false, "Não foi possivel realizar o cadastro", hospital)); } await Task.Factory.StartNew(() => { _hospitalRepository.Create(hospital); }); return(new CommandExit(true, "Cadastro Realizado Com Sucesso", null)); }