示例#1
0
        public async Task <ActionResult <AbastecimentoDto> > Put(int id, [FromBody] AbastecimentoDto abastecimentoDto)
        {
            try
            {
                var abastecimentoDatabase = await abastecimentoService.GetById(id, GetIdUsuarioLogado());

                if (abastecimentoDatabase == null)
                {
                    return(NotFound());
                }

                var abastecimento = mapper.Map(abastecimentoDto, abastecimentoDatabase);
                await abastecimentoService.Update(id, abastecimento, GetIdUsuarioLogado());

                return(CreatedAtAction(nameof(Put), new { id = abastecimento.Id }, abastecimento));
            }
            catch (ValidationException vex)
            {
                return(BadRequest(new ErrorResponse(vex.Errors.ToListValidationFailureString())));
            }
            catch (Exception ex)
            {
                return(BadRequest(new ErrorResponse(ex.Message)));
            }
        }
示例#2
0
        public int Atualizar(AbastecimentoDto entity)
        {
            Abastecimento abastecimento = new Abastecimento();

            abastecimento.PrepararDadosParaAtualizar(entity.NCodAbastecimento, entity.NKmAbastecimento, entity.NLitroAbastecimento, entity.VVlrPago, entity.DAbastecimento, entity.NCodPosto, entity.NCodUsuarioInc, entity.NCodTipoCombustivel, entity.NCodTipoVeiculo, entity.NCodVeiculo);
            return(_serviceAbastecimento.Atualizar(abastecimento));
        }
示例#3
0
        public async Task <ActionResult <Abastecimento> > Post([FromBody] AbastecimentoDto abastecimentoDto)
        {
            try
            {
                var abastecimento = mapper.Map <AbastecimentoDto, Abastecimento>(abastecimentoDto);
                await abastecimentoService.Create(abastecimento, GetIdUsuarioLogado());

                return(CreatedAtAction(nameof(Post), new { id = abastecimento.Id }, abastecimentoDto));
            }
            catch (ValidationException vex)
            {
                return(BadRequest(new ErrorResponse(vex.Errors.ToListValidationFailureString())));
            }
            catch (Exception ex)
            {
                return(BadRequest(new ErrorResponse(ex.Message)));
            }
        }
 public int Alterar([FromBody] AbastecimentoDto abastecimento)
 {
     return(_appAbastecimento.Atualizar(abastecimento));
 }
 public int Adicionar([FromBody] AbastecimentoDto abastecimento)
 {
     return(_appAbastecimento.Adicionar(abastecimento));
 }