Example #1
0
        public async Task <long> CriarPatrimonio(long modeloId, string nome, string descricao)
        {
            var modelo = await _modeloRepository.ObterPorIdAsync(modeloId);

            if (modelo == default(Modelo))
            {
                throw new EntityNotFoundException(typeof(Modelo).Name, modeloId);
            }

            var patrimonio = modelo.NovoPatrimonio(_idGenerator.GenerateId(), nome, _timeProvider.UtcNow, descricao);

            await _patrimonioRepository.IncluirAsync(patrimonio);

            return(patrimonio.TomboNumero);
        }
        public async Task <long> CriarMarcaAsync(string nome)
        {
            var marcaRepetida = await _repository.ObterPorNomeAsync(nome);

            if (marcaRepetida != null)
            {
                throw new DuplicatedEntityException(typeof(Marca).Name, nome);
            }

            var marca = new Marca(_idGeneratorService.GenerateId(), nome, _timeProvider.UtcNow);

            await _repository.IncluirAsync(marca);

            return(marca.MarcaId);
        }
        public async Task <long> CriarModeloAsync(long marcaId, string nome)
        {
            var marca = await _marcaRepository.ObterPorIdAsync(marcaId);

            if (marca == null)
            {
                throw new EntityNotFoundException(typeof(Marca).Name, marcaId);
            }

            if (marca.Modelos.Any(r => r.Nome == nome))
            {
                throw new DuplicatedEntityException(typeof(Modelo).Name, nome);
            }

            var modelo = marca.NovoModelo(_idGeneratorService.GenerateId(), nome, _timeProvider.UtcNow);

            await _repository.IncluirAsync(modelo);

            return(modelo.ModeloId);
        }