public async Task <ActionResult <ServicoOutput> > PostServico(PostServico servico)
        {
            var retorno = await _servicos.Create(servico.MapTo <Servico>());

            await _servicos.Commit();

            return(CreatedAtAction("GetServico", new { id = retorno.Id }, retorno.MapTo <ServicoOutput>()));
        }
Beispiel #2
0
        public Servico Create(Servico servico)
        {
            var servicoExiste = _repoServico.FindByName(servico.Nome);

            if (servicoExiste != null)
            {
                return(null);
            }

            return(_repoServico.Create(servico));
        }
        public ICommandResult Handle(CreateServicoCommand command)
        {
            // fail-first principle
            if (!command.Validate())
            {
                return(new CommandResult("error", "Falha ao criar um serviço.", command));
            }

            var servico = new Servico(command.Usuario, command.Titulo, command.Descricao);

            _repository.Create(servico);

            return(new CommandResult("success", "Serviço criado com sucesso.", servico));
        }
Beispiel #4
0
        public async Task <ResultDto <ServicoDto> > Create(ServicoDto servicoDto)
        {
            var servicoDtoValidate = new ServicoDtoValidate(servicoDto);

            if (!servicoDtoValidate.Validate())
            {
                return(await Task.FromResult(ResultDto <ServicoDto> .Validation(servicoDtoValidate.Mensagens)));
            }

            var servico = _mapper.Map <Servico>(servicoDto);

            servico.SituacaoId   = (int)ESituacao.ATIVO;
            servico.DataCadastro = DateTime.Now;
            await _servicoRepository.Create(servico);

            return(await Task.FromResult(ResultDto <ServicoDto> .Success(_mapper.Map <ServicoDto>(servico))));
        }