示例#1
0
        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));
        }